Loop Problem - 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: Loop Problem (
/showthread.php?tid=197576)
Loop Problem -
Infamous - 09.12.2010
Hi,
I have several loops in my script and have never had a problem with any of them before. I have since added a new loop which is exactly the same as the others besides the name. This loop just doesn't seem to be getting called at all.
Код:
//The cmd:
if (strcmp("/test", cmdtext, true, 5) == 0) {
SetPlayerWantedLevel(playerid, 5);
return 1;
}
//The forward:
forward WantedLevel();
//The timer:
SetTimer("WantedLevel", 500, 1);
//The loop:
public WantedLevel()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && IsPlayerSpawned[i] == 1)
{
new wantedlevel = GetPlayerWantedLevel(i);
if(wantedlevel == 0) SetPlayerToTeamColour(i);
if(wantedlevel >= 1) SetPlayerColor(i, COLOR_WANTED);
}
}
}
I can't see a problem with that at all yet the loop never gets called for some reason. If anyone has any ideas it would be appreciated.
Thanks, Infamous.
Re: Loop Problem -
Ash. - 09.12.2010
pawn Код:
//The cmd:
if (strcmp("/test", cmdtext, true, 5) == 0) {
SetPlayerWantedLevel(playerid, 5);
return 1;
}
//The forward:
forward WantedLevel();
//The timer:
SetTimer("WantedLevel", 500, 1);
//The loop:
public WantedLevel()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && IsPlayerSpawned[i] == 1)
{
new wantedlevel = GetPlayerWantedLevel(i);
if(wantedlevel == 0) SetPlayerToTeamColour(i);
if(wantedlevel >= 1) SetPlayerColor(i, COLOR_WANTED);
}
}
}
Where is the timer?
Re: Loop Problem -
Infamous - 09.12.2010
Quote:
Originally Posted by funky1234
pawn Код:
//The cmd: if (strcmp("/test", cmdtext, true, 5) == 0) { SetPlayerWantedLevel(playerid, 5); return 1; }
//The forward: forward WantedLevel();
//The timer: SetTimer("WantedLevel", 500, 1); <--------------------- Here
//The loop: public WantedLevel() { for(new i=0; i<MAX_PLAYERS; i++) { if(IsPlayerConnected(i) && IsPlayerSpawned[i] == 1) { new wantedlevel = GetPlayerWantedLevel(i);
if(wantedlevel == 0) SetPlayerToTeamColour(i);
if(wantedlevel >= 1) SetPlayerColor(i, COLOR_WANTED);
} } }
Where is the timer?
|
This is really bugging me now lol
EDIT: The problem is related to my registration system. (Please close)
Re: Loop Problem - rjjj - 09.12.2010
Put:
pawn Код:
//In The OnGameModeInit
SetTimer("WantedLevel", 500, 1);
//In The OnPlayerCommandText:
if(strcmp("/test", cmdtext, true, 4) == 0)
{
SetPlayerWantedLevel(playerid, 5);
return 1;
}
//In the end of the gamemode:
forward WantedLevel();
public WantedLevel()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && IsPlayerSpawned[i] == 1)
{
new wantedlevel = GetPlayerWantedLevel(i);
if(wantedlevel == 0){SetPlayerToTeamColour(i);}
if(wantedlevel >= 1){SetPlayerColor(i, COLOR_WANTED);}
}
}
}
I hope that i have helped