Setting A Timer On Player Disconnect - 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)
+--- Thread: Setting A Timer On Player Disconnect (
/showthread.php?tid=358899)
Setting A Timer On Player Disconnect -
WinterAce - 12.07.2012
Hello, I have a timer set for the trucker job so when a player picks up packages it sets a 30 minute timer until they're allowed to do it again, all working good, except one issue. How would I go about keeping the timer set even when the player disconnects? But for the timer to pause until the player reconnects. Say the timer shows 18 minutes left, player leaves, goes back on the server two hours later and it starts counting down from 18 minutes when the player reconnects again.
Re: Setting A Timer On Player Disconnect -
ReneG - 12.07.2012
pawn Код:
new
TruckMinutes[MAX_PLAYERS];
forward OneMinute();
public OneMinute()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(i != INVALID_PLAYER_ID && TruckMinutes[i] > 0)
{
TruckMinutes[playerid]--;
}
}
return 1;
}
public OnGameModeInit()
{
SetTimer("OneMinute", 60000, true);
return 1;
}
public OnPlayerConnect(playerid)
{
TruckMinutes[playerid] = 0;
return 1;
}
In the command, you would set TruckMinutes to however big the reload time is in minutes.
Every minute, for every player that is connected, their variable will reduce by one.
You would have to save the variable, and load it on connect.
Re: Setting A Timer On Player Disconnect -
WinterAce - 12.07.2012
Quote:
Originally Posted by VincentDunn
pawn Код:
new TruckMinutes[MAX_PLAYERS];
forward OneMinute(); public OneMinute() { for(new i=0; i<MAX_PLAYERS; i++) { if(i != INVALID_PLAYER_ID && TruckMinutes[i] > 0) { TruckMinutes[playerid]--; } } return 1; }
public OnGameModeInit() { SetTimer("OneMinute", 60000, true); return 1; }
public OnPlayerConnect(playerid) { TruckMinutes[playerid] = 0; return 1; }
In the command, you would set TruckMinutes to however big the reload time is in minutes.
Every minute, for every player that is connected, their variable will reduce by one.
You would have to save the variable, and load it on connect.
|
Thanks man, I'll use this for my command if I can't get the time function to work instead. Rep for you.
Re: Setting A Timer On Player Disconnect -
WinterAce - 12.07.2012
Quote:
Originally Posted by ******
Why do you need a timer? Just use time functions to test when they can or can't do things.
|
I have the paycheck set as a time function but can't seem to get my /loadpackages command to work with it, PM.