SA-MP Forums Archive
Global variable i think - 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: Global variable i think (/showthread.php?tid=440745)



Global variable i think - bleedis - 31.05.2013

Hello, how to change global variable for all players if i use command?
I have this
pawn Код:
new spikes[MAX_PLAYERS];
and after command i need it to bee like
pawn Код:
spikes[playerid] = 0;
but the thing is i cant figure out how to make it for all players not just for one who used the command. And yea, i hope its the right word for it Thanks


Re: Global variable i think - dubyabeast - 31.05.2013

alright. can be done using a loop:
pawn Код:
// zcmd:
CMD:spikesoffall(playerid) {
    for(new i = 0; i < MAX_PLAYERS; i++) spikes[i] = 0;
    return 1;
}



Re: Global variable i think - bleedis - 31.05.2013

Thanks, i will try that.


Re: Global variable i think - bleedis - 31.05.2013

Sorry for double post, didnt work. It was the same, removed all spikes but that thing staid. Maybe i have to better explain. If someone uses spike command it makes this to go to 1
pawn Код:
spikes[playerid] = 1;
if someone already placed spikes then this happens -
pawn Код:
if (spikes[playerid] == 1) return SendClientMessage(playerid, 0xE01B4CFF, "{ff0000}** {C8D1CC}You already placed spikes!");
So if admin uses command to remove all players spikes on server, then how to get that spikes[playerid] = 1; goes to spikes[playerid] = 0; for everyone?


Re: Global variable i think - Rillo - 31.05.2013

Quote:
Originally Posted by bleedis
Посмотреть сообщение
Sorry for double post, didnt work. It was the same, removed all spikes but that thing staid. Maybe i have to better explain. If someone uses spike command it makes this to go to 1
pawn Код:
spikes[playerid] = 1;
if someone already placed spikes then this happens -
pawn Код:
if (spikes[playerid] == 1) return SendClientMessage(playerid, 0xE01B4CFF, "{ff0000}** {C8D1CC}You already placed spikes!");
So if admin uses command to remove all players spikes on server, then how to get that spikes[playerid] = 1; goes to spikes[playerid] = 0; for everyone?
Well instead of setting spikes[playerid] = 0 you would need to do what the guy above said.

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
So when you use the command to set the spikes to 0 for all players. Instead of doing spikes[playerid] = 0 you would need to do spikes[i] = 0 . Then instead of just setting that variable to 0 for the player who used the command [playerid], it would go threw all the online players [i] and set that variable to 0 for them.

So when the player uses the command to set the spikes, you would do spikes[playerid] = 1 and the admin command to remove ALL spikes would have spikes[i] = 0 in the command with the for (new.. code before you use the [i].

Did that make any sense?


Re: Global variable i think - bleedis - 31.05.2013

Yup. Thanks.