loops - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: loops (
/showthread.php?tid=250699)
loops -
fissekarl - 24.04.2011
Could anyone show me a code when a player types a cmd like /tp and then get tp...(i can do that)
but like how can you make a loop where you get all the players who typed /tp
Re: loops -
Seven_of_Nine - 24.04.2011
pawn Code:
for(new i = 0; i < MAX_PLAYERS; ++i) {
//code here
}
"//code here" will be done with all players.
pawn Code:
for(new i = 0; i < MAX_PLAYERS; ++i) {
if(!IsPlayerAdmin(i)) {
//code here
}
}
Now, "//code here" will be applied only non-rcon admins
Re: loops -
fissekarl - 24.04.2011
ok but its not like that i want
example a player types /tp
an someone types /tplist it will show who type /tp
Re: loops -
Seven_of_Nine - 24.04.2011
I think it's better to put in a file.
And read it line-by-line with fread til line 5.
Maybe I will write it later..
Re: loops -
Babul - 24.04.2011
to get a /tplist of all players (who typed /tp), i suggest you to set a PVar for each player and loop through them..
Code:
CMD:tp(playerid,params[]){
new string[128];
new Name[MAX_PLAYER_NAME];
switch(GetPVarInt(playerid,"TeleportMe"))
{
case 0:
{
SetPVarInt(playerid,"TeleportMe",1);
GetPlayerName(playerid,Name,sizeof(Name));
format(string,sizeof(string),"(%d)%s joined.",playerid,Name);
SendClientMessageToAll(0x33ccccff,string);
SendClientMessage(playerid,0x33cc33ff,"You are on the List now.");
}
case 1:
{
SendClientMessage(playerid,0xcc7f33ff,"You are already on the List.");
}
}
return 1;
}
CMD:tplist(playerid,params[]){
new string[128];
new Name[MAX_PLAYER_NAME];
new MaxPlayers=GetMaxPlayers();
for(new i=0;i<MaxPlayers;i++)
{
if(GetPVarInt(i,"TeleportMe")==1))
{
if(!IsPlayerAdmin(i))//i would leave that out. maybe even an rcon admin wants to get teleported to en event?
{
GetPlayerName(i,Name,sizeof(Name));
format(string,sizeof(string),"(%d)%s",i,Name);
SendClientMessage(playerid,0xcccc33ff,string);
}
SetPVarInt(i,"TeleportMe",0);
}
}
return 1;
}
not tested, not optimized, just a suggestion - anyways, a PVar wont blow up your .amx size, and it gets deleted (set to 0 when GetPVar-ing it) automatically at OnPlayerDisconnect(), it will return 0 then. so a not connected player cant get .. listed/teleported/exploded.... have fun debugging it