timer for multiple players -
tommzy09 - 12.08.2014
how am i able to make 1 timer that works for multiple players
for example, i got an arrest command that sends a player to jail for 30 seconds and then unjails them once the 30 seconds is over but theres a bug, if i arrest another player 15 seconds after, they both get released from jail at the same time.
i've been trying to fix this for a while and yet, i can't. here is the bits of code:
up top
the timer itself
Код:
SetTimerEx("UnJail", 60000, false, "i", playerid);
public
Код:
public UnJail()
{
for(new i; i < MAX_PLAYERS; i++)
{
if(jailed[i] == 1)
{
new pname[MAX_PLAYER_NAME];
new string[60];
GetPlayerName(i, pname, sizeof(pname));
SetPlayerPos(i, 255.2078,86.6854,1002.4453);
SetPlayerInterior(i, 6);
SetPlayerFacingAngle(i, 90);
format(string, sizeof(string), "%s (%d) has been Released from Jail.", pname, i);
SendClientMessageToAll(0xFFFFFFFF, string);
jailed[i] = 0;
}
}
}
how can i make the timer run individually for all players in jail
Re: timer for multiple players -
Vince - 12.08.2014
Remove the loop and replace
i with
playerid. Also add
playerid to the function header.
Re: timer for multiple players -
GGW - 12.08.2014
Quote:
Originally Posted by tommzy09
for(new i; i < MAX_PLAYERS; i++)
|
there is a problem in your loop
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++)
Re: timer for multiple players -
tommzy09 - 12.08.2014
Quote:
Originally Posted by Vince
Remove the loop and replace i with playerid. Also add playerid to the function header.
|
like this?
Код:
public UnJail(playerid)
{
if(jailed[playerid] == 1)
{
new pname[MAX_PLAYER_NAME];
new string[60];
GetPlayerName(playerid, pname, sizeof(pname));
SetPlayerPos(playerid, 255.2078,86.6854,1002.4453);
SetPlayerInterior(playerid, 6);
SetPlayerFacingAngle(playerid, 90);
format(string, sizeof(string), "%s (%d) has been Released from Jail.", pname, playerid);
SendClientMessageToAll(0xFFFFFFFF, string);
jailed[playerid] = 0;
}
}
Quote:
Originally Posted by GGW
there is a problem in your loop
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++)
|
so, like this?
Код:
public UnJail()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(jailed[i] == 1)
{
new pname[MAX_PLAYER_NAME];
new string[60];
GetPlayerName(i, pname, sizeof(pname));
SetPlayerPos(i, 255.2078,86.6854,1002.4453);
SetPlayerInterior(i, 6);
SetPlayerFacingAngle(i, 90);
format(string, sizeof(string), "%s (%d) has been Released from Jail.", pname, i);
SendClientMessageToAll(0xFFFFFFFF, string);
jailed[i] = 0;
}
}
}
also, which one will work? or do both methods work?
Re: timer for multiple players -
GGW - 12.08.2014
PHP код:
public UnJail(playerid)
{
if(jailed[playerid] == 1)
{
new pname[MAX_PLAYER_NAME];
new string[60];
GetPlayerName(playerid, pname, sizeof(pname));
SetPlayerPos(playerid, 255.2078,86.6854,1002.4453);
SetPlayerInterior(playerid, 6);
SetPlayerFacingAngle(playerid, 90);
format(string, sizeof(string), "%s (%d) has been Released from Jail.", pname, playerid);
SendClientMessageToAll(0xFFFFFFFF, string);
jailed[playerid] = 0;
}
}
is better than the loop if you want my opinion
loop is for all players but " playerid " is only for 1 player ^^
Re: timer for multiple players -
Stinged - 12.08.2014
Quote:
Originally Posted by GGW
is better than the loop if you want my opinion
|
He's using SetTimerEx, he doesn't need a loop at all.
Re: timer for multiple players -
GGW - 12.08.2014
i didn't understand him from the first time , sorry my bad .
Re: timer for multiple players -
tommzy09 - 12.08.2014
im sort of confused on which method to use for my situation :/
i want the same timer running separately for each player who is jailed so that they dont get released at the same time. which method is the best one to use?
sorry for my confusion
Re: timer for multiple players -
Stinged - 12.08.2014
You use a loop when you don't have a playerid.
You use playerid when you do (obviously)
You do have playerid, so use it.
Re: timer for multiple players -
ikkentim - 13.08.2014
Quote:
Originally Posted by GGW
Quote:
Originally Posted by tommzy09
pawn Код:
for(new i; i < MAX_PLAYERS; i++)
|
there is a problem in your loop
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
|
The default value of a cell is 0, therefore there is no problem in the loop. Though this way it is more
obvious what the initial value is, this is code style related and has nothing to do with the logic.