Setting A Timer On Player Disconnect
#1

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)