[Help] Turn on and off with the same command - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] Turn on and off with the same command (
/showthread.php?tid=584359)
[Help] Turn on and off with the same command -
Dragonic - 04.08.2015
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:
if (strcmp("/R", cmdtext, true, 5) == 0)
{
g_Ramp[playerid] = 1;
}
|
Thanks in advance!
Re: [Help] Turn on and off with the same command -
MarvinPWN - 04.08.2015
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;
}
Re: [Help] Turn on and off with the same command -
Dragonic - 04.08.2015
Thanks it works

!
Re: [Help] Turn on and off with the same command -
Dragonic - 04.08.2015
Mind explaining the code if possible? Thanks.
Re: [Help] Turn on and off with the same command -
Krokett - 04.08.2015
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.