AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Enable/Disable (https://forums.alliedmods.net/showthread.php?t=183986)

Artifact 04-29-2012 10:30

Enable/Disable
 
What code can I put in this plugin to player enable / disable hud with chat command, I tried with bool but I cant

<VeCo> 04-29-2012 10:36

Re: Enable/Disable
 
Show your code.

Bilal Pro 04-29-2012 10:40

Re: Enable/Disable
 
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>

#define PLUGIN "Block hudmessage"
#define VERSION "1.0"
#define AUTHOR "Bilal"

new boolEnabled

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /enable""CmdEnable")
    
register_clcmd("say /disable""CmdDisable")
}

public 
CmdEnable(id)
{
    if (
is_user_connected(id))
    {
        
Enabled true
        show_hudmessage
(0"Hudmessages are now ON!")
        
client_print(idprint_chat"You succesfully enabled the hudmessage!")
    }
    else if (
Enabled == true)
    {
        
client_print(idprint_chat"You already have this enabled!")
    }
}

public 
CmdDisable(id)
{
    if (
is_user_connected(id))
    {
        
Enabled false
        show_hudmessage
(0"Hudmessages are now OFF!")
        
client_print(idprint_chat"You succesfully disabled the hudmessage!")
    }
    else if (
Enabled == false)
    {
        
client_print(idprint_chat"You already have this disabled!")
    }


Example with a bool.

Artifact 04-29-2012 10:48

Re: Enable/Disable
 
My code with bool:
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "hud"
#define VERSION "1.0"
#define AUTHOR "good."

new bool:hud

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
set_task(1.0"ShowHud",_,_,_,"b")
    
register_clcmd("say /hide_hud""HideHud")
    
register_clcmd("say /show_hud""Show_Hud")
}

public 
HideHud()
{
    
hud false
    
return PLUGIN_HANDLED
}

public 
Show_Hud()
{
    
hud true
    
return PLUGIN_HANDLED
}

public 
ShowHud(id)
{
    if(
hud == true) {
        new 
currmap[31], NextMap[32];
        
get_mapname(currmap30)
        
get_cvar_string"amx_nextmap" NextMap 31 );
        
set_hudmessage(025500.010.2506.01.0)
        new 
iTimeLeft get_timeleft();
        if(
get_cvar_num("mp_timelimit") == 0)
        {
            
show_hudmessage(0"Server: %s^nTrenutna mapa: %s^nSledeca mapa: %s^nMapa se menja nakon ove runde!",get_cvar_pointer("hostname"), currmapNextMap)
        }
        else
        {
            
show_hudmessage(0"Server: %s^nTrenutna mapa: %s^nSledeca mapa: %s^nVreme do sledece mape: %d:%d",get_cvar_pointer("hostname"), currmapNextMapiTimeLeft 60iTimeLeft 60)
        }
    }
    else
        return 
PLUGIN_HANDLED
    
return PLUGIN_HANDLED


And without bool and without enable/disable plugin..
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "hud"
#define VERSION "1.0"
#define AUTHOR "good."


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
set_task(1.0"ShowHud",_,_,_,"b")
}

public 
ShowHud(id)
{
    new 
currmap[31], NextMap[32];
    
get_mapname(currmap30)
    
get_cvar_string"amx_nextmap" NextMap 31 );
    
set_hudmessage(025500.010.2506.01.0)
    new 
iTimeLeft get_timeleft();
    if(
get_cvar_num("mp_timelimit") == 0)
    {
        
show_hudmessage(0"Server: %s^nTrenutna mapa: %s^nSledeca mapa: %s^nMapa se menja nakon ove runde!",get_cvar_pointer("hostname"), currmapNextMap)
    }
    else
    {
        
show_hudmessage(0"Server: %s^nTrenutna mapa: %s^nSledeca mapa: %s^nVreme do sledece mape: %d:%d",get_cvar_pointer("hostname"), currmapNextMapiTimeLeft 60iTimeLeft 60)
    }


Here is error with bool http://i47.tinypic.com/20pv8dd.png

<VeCo> 04-29-2012 10:59

Re: Enable/Disable
 
Something like this... You don't even need a variable.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#define PLUGIN "hud"
#define VERSION "1.0"
#define AUTHOR "good."
public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /show_hud","cmd_showhud")
    
register_clcmd("say /hide_hud","cmd_hidehud")
    
    
set_task(1.0"ShowHud",123,.flags "b")
}
public 
cmd_showhud(id)
{
    if(
task_exists(123)) return
    
set_task(1.0"ShowHud",123,.flags "b")
}
public 
cmd_hidehud(id)
{
    if(!
task_exists(123)) return
    
remove_task(123)
}
public 
ShowHud()
{
    new 
currmap[31], NextMap[32];
    
get_mapname(currmap30)
    
get_cvar_string"amx_nextmap" NextMap 31 );
    
set_hudmessage(025500.010.2506.01.0)
    new 
iTimeLeft get_timeleft();
    if(
get_cvar_num("mp_timelimit") == 0)
    {
        
show_hudmessage(0"Server: %s^nTrenutna mapa: %s^nSledeca mapa: %s^nMapa se menja nakon ove runde!",get_cvar_pointer("hostname"), currmapNextMap)
    }
    else
    {
        
show_hudmessage(0"Server: %s^nTrenutna mapa: %s^nSledeca mapa: %s^nVreme do sledece mape: %d:%d",get_cvar_pointer("hostname"), currmapNextMapiTimeLeft 60iTimeLeft 60)
    }



Artifact 04-29-2012 11:02

Re: Enable/Disable
 
PHP Code:

    set_task(1.0"ShowHud",123,.flags "b")
}
public 
cmd_showhud(id)
{
    if(
task_exists(123)) return
    
set_task(1.0"ShowHud",123,.flags "b")


??? O.o description

<VeCo> 04-29-2012 11:07

Re: Enable/Disable
 
Yeah, it's a little bit sucky, but I couldn't think of another good way (i would do it with entity)...
Anyway - I'm setting an index to the task (in this case it's 123) and checking if it exists and then remove it or set it again. I used the ".flags" to set the flags directly without these "_" ...

Artifact 04-29-2012 12:33

Re: Enable/Disable
 
Now when I type /hide_hud, hud message was hide for whole server :D
Can you fix that?
(sorry for bump, I need it realy, sorry)

<VeCo> 04-29-2012 12:52

Re: Enable/Disable
 
You want it to hide the message only for the player that typed the command?

Artifact 04-29-2012 12:53

Re: Enable/Disable
 
Yes :)


All times are GMT -4. The time now is 07:46.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.