Help with PayDay
#7

pawn Код:
// Top of script

new
    CurrentSession[ MAX_PLAYERS ] // Create an array which keeps track of how many seconds the player has been on the server.
;

forward PayDay( ); // Forwarding the payday function.
forward ThreeSecondTimer( ); // Forwarding the session increment function.

// OnGameModeInit

SetTimer( "PayDay", 1800000, true ); // Setting the payday timer for 30 minutes.
SetTimer( "ThreeSecondTimer", 3000, true ); // Setting the session timer for 3 seconds.

// OnPlayerConnect

CurrentSession[ playerid ] = 0; // When a new player connects, their session time should be 0.

// Outside callbacks

public ThreeSecondTimer( )
{
    for( new i; i < MAX_PLAYERS; i++ ) // Can be substituted with foreach (Recommended)
    {
        if( IsPlayerConnected( i ) ) // If the player is connected
        {
            CurrentSession[ i ] += 3; // Add 3 to their seconds connected.
        }
    }
    return 1;
}

public PayDay( )
{
    for( new i; i < MAX_PLAYERS; i++ ) // Can be substituted with foreach (Recommended)
    {
        if( IsPlayerConnected( i ) ) // If the player is connected
        {
            if( CurrentSession[ i ] >= 900 ) // If the player has been connected for at least 15 minutes.
            {
                GivePlayerMoney( i, 5000 ); // Give the player money
            }
            else
            {
                SendClientMessage( i, 0xFFFFFFFF, "Server: You haven't played long enough!" ); // The player has not been connected for at least 15 minutes.
            }
           
            CurrentSession[ i ] = 0; // Reset the session.
        }
    }
    return 1;
}
Untested, I'm sure there are more efficient ways of doing this but I feel this is the easiest way to explain how it works.
Reply


Messages In This Thread
Help with PayDay - by Ivica_Razor - 07.12.2010, 18:27
Re: Help with PayDay - by Ivica_Razor - 07.12.2010, 18:55
Re: Help with PayDay - by Mehtab - 07.12.2010, 19:13
Re: Help with PayDay - by JamesC - 07.12.2010, 19:22
Re: Help with PayDay - by Ivica_Razor - 07.12.2010, 19:54
Re: Help with PayDay - by Ivica_Razor - 07.12.2010, 21:05
Re: Help with PayDay - by JamesC - 07.12.2010, 21:24
Re: Help with PayDay - by Ivica_Razor - 07.12.2010, 23:02
Re: Help with PayDay - by fangoth1 - 08.12.2010, 00:02
Re: Help with PayDay - by Ivica_Razor - 08.12.2010, 14:26

Forum Jump:


Users browsing this thread: 6 Guest(s)