[Help] Turn on and off with the same command
#1

Hi! In my server I have a ramp spawning system and I made it so for them to spawn by pressing "Caps" only if you type /R, theres a way to make if the player types /R again the ramp spawning turns off?

Here's the code:

Quote:

new g_Ramp[MAX_PLAYERS];

Quote:

if (strcmp("/R", cmdtext, true, 5) == 0)
{
g_Ramp[playerid] = 1;
}

Thanks in advance!
Reply
#2

PHP код:
if(!strcmp("/R",cmdtext,true))
{
    if(
g_Ramp[playerid] == 1)g_Ramp[playerid] = 0;
    else if(
g_Ramp[playerid] == 0)g_Ramp[playerid] = 1;
    return 
1;
}
//or another solution:
if(!strcmp("/R",cmdtext,true))
{
    
g_Ramp[playerid] = !g_Ramp[playerid];
    return 
1;

Reply
#3

Thanks it works !
Reply
#4

Mind explaining the code if possible? Thanks.
Reply
#5

I think the first snippet of code is understandable enough (just say the code in English)

PHP код:
//or another solution: 
if(!strcmp("/R",cmdtext,true)) 

    
g_Ramp[playerid] = !g_Ramp[playerid]; 
    return 
1

What is says here is g_Ramp[player] = whatever g_Ramp[playerid] is NOT. ! = inverse operator.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)