timer for multiple players
#1

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
Код:
forward UnJail();
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
Reply
#2

Remove the loop and replace i with playerid. Also add playerid to the function header.
Reply
#3

Quote:
Originally Posted by tommzy09
Посмотреть сообщение
for(new i; i < MAX_PLAYERS; i++)
there is a problem in your loop

PHP код:
for(new 0MAX_PLAYERSi++) 
Reply
#4

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 0MAX_PLAYERSi++) 
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?
Reply
#5

PHP код:
public UnJail(playerid)
{
    if(
jailed[playerid] == 1)
        {
        new 
pname[MAX_PLAYER_NAME];
        new 
string[60];
        
GetPlayerName(playeridpnamesizeof(pname));
        
SetPlayerPos(playerid255.2078,86.6854,1002.4453);
        
SetPlayerInterior(playerid6);
        
SetPlayerFacingAngle(playerid90);
        
format(stringsizeof(string), "%s (%d) has been Released from Jail."pnameplayerid);
        
SendClientMessageToAll(0xFFFFFFFFstring);
        
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 ^^
Reply
#6

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.
Reply
#7

i didn't understand him from the first time , sorry my bad .
Reply
#8

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
Reply
#9

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)