AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Command Toggle(ON/OFF) (https://forums.alliedmods.net/showthread.php?t=244146)

suundz 07-14-2014 09:31

Command Toggle(ON/OFF)
 
Hello, I wan't to make a plugin with a command that toggle on/off

Code:

#include <amxmodx>

new bool:ReadyUsed[33];

public plugin_init() {
    register_clcmd("ready", "ready");
}

So I'm using this and I wan't to toggle the boolean ReadyUsed on or off, by using it first time it's on and by second time it's off

Please give me some help, if you don't understand try reading it again :S

Thanks in advance! =D

Phant 07-14-2014 10:16

Re: Command Toggle(ON/OFF)
 
ClanWar plugin @_@?
PHP Code:

new bool:g_user_ready[33]

register_clcmd("say /ready""clcmdReady"0)

public 
clcmdReady(id)
{    
    if(
g_user_ready[id])
    {
        
g_user_ready[id] = false
    
} else {
        
g_user_ready[id] = true
    
}



Flick3rR 07-14-2014 10:22

Re: Command Toggle(ON/OFF)
 
Ahh I hate this:
PHP Code:

public clcmdReady(id)
{    
    if(
g_user_ready[id])
    {
        
g_user_ready[id] = false
    
} else {
        
g_user_ready[id] = true
    
}


It's just:
PHP Code:

public clcmdReady(id)
{    
    
g_user_ready[id] = !g_user_ready[id]



Phant 07-14-2014 10:52

Re: Command Toggle(ON/OFF)
 
If/Else condition in this case for further coding. For example, adding client_print() messages, like:
Quote:

"%s" Ready.
"%s" Not Ready.

Backstabnoob 07-14-2014 11:06

Re: Command Toggle(ON/OFF)
 
PHP Code:

g_user_ready[id] = !g_user_ready[id]
client_print(0print_chat"Name %sReady", !g_user_ready[id] ? "Not " ""


mottzi 07-14-2014 13:38

Re: Command Toggle(ON/OFF)
 
And if you have more to do after the value toggle then things get pretty silly. I guess Phants point is valid there.

suundz 07-14-2014 13:53

Re: Command Toggle(ON/OFF)
 
Thank you all for replying very kind of you all since I'm new :)
Appreciate a lot!


All times are GMT -4. The time now is 21:05.

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