need fast help!! loop issue!! - 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: need fast help!! loop issue!! (
/showthread.php?tid=246097)
need fast help!! loop issue!! -
BlackWolf120 - 03.04.2011
hi,
i need a solution fast pls!
everytime this loop is used everything in this loop is executed that often how many players are currently on the server.
So e.g. if there are 4 players on the server and the loop would include a SendClientMessageToAll, this message would be send 4 times!
But i only want this to be executed once, pls help!!
pawn Код:
forward pAliveChecker();//this is a timer checking how many players are still alive...
public pAliveChecker()
{
new Float:survivorhealth[MAX_PLAYERS];
for(new i=0;i < MAX_PLAYERS; i++)
{
GetPlayerHealth(i,survivorhealth[i]);
if((survivorhealth[i] > 0) && (IsPlayerConnected(i) == 1))//if only one single player is alive the round ends...
{
ChainsawEnder();//this is a stock and its executed like i wrote on top... But it shall be executed only once
}
}
return 1;
}
regards, Black.
I really need a fast solution pls
Re: need fast help!! loop issue!! -
Miguel - 03.04.2011
pawn Код:
forward pAliveChecker();//this is a timer checking how many players are still alive...
public pAliveChecker()
{
new
Float:survivorhealth[MAX_PLAYERS];
for(new i=0;i < MAX_PLAYERS; i++)
{
GetPlayerHealth(i,survivorhealth[i]);
if((survivorhealth[i] > 0) && (IsPlayerConnected(i) == 1))//if only one single player is alive the round ends...
{
ChainsawEnder();//this is a stock and its executed like i wrote on top... But it shall be executed only once
break; // Use break to exit a loop.
}
}
return 1;
}
Please, indent your code next time. By the way, you can find more information here:
https://sampwiki.blast.hk/wiki/Keywords:Statements
Re: need fast help!! loop issue!! -
bigcomfycouch - 03.04.2011
A few things could be improved upon as well
pawn Код:
forward pAliveChecker( );
public pAliveChecker( )
{
new
Float:health;
for( new i; i < MAX_PLAYERS; ++i )
{
// samp has internal checks to see if players are connected
// no reason to have an array of health values if they are never compared
if ( GetPlayerHealth( i, health ) && health > 0 )
{
ChainsawEnder( );
break;
}
}
return 1;
}
Re: need fast help!! loop issue!! -
BlackWolf120 - 03.04.2011
thx but...
This does not check if theres only one single player alive right?
Cause there could be also more than one player online having bigger health than 0.
Or am i wrong?