How to code a payday?
#4

@Rajat_Pawar - Nice try but I don't think that code would be very nice

@rickisme

pawn Код:
foreach(Player, i)
    {
        if(IsPlayerLogged(i))
        {
You serious ? lol

Here is how I would do it.

pawn Код:
#include <timerfix> // https://sampforum.blast.hk/showthread.php?tid=289675
#include <YSI\y_hooks>

static PayDayTime[MAX_PLAYERS];

// Called when it's a players payday
forward OnPlayerPayDay(playerid);

// Start payday update
hook OnGameModeInit()
{
    SetTimer("PayDayUpdate", 60000, true);
    return 1;
}

// Reset players payday time when they connect
hook OnPlayerConnect(playerid)
{
    PayDayTime[playerid] = gettime();
    return 1;
}

// Check for paydays once a minute is good
forward PayDayUpdate();
public PayDayUpdate()
{
    foreach(new i : Player)
    {
        // It's payday!
        if(gettime() - PayDayTime[i] >= 3600)
        {
            PayDayTime[i] = gettime();
            CallLocalFunction("OnPlayerPayDay", "i", i);
        }
    }
    return 1;
}

// Set the players payday time (Called from inside gamemode/other includes)
forward SetPayDayTime(playerid);
public SetPayDayTime(playerid) { PayDayTime[playerid] = gettime(); }

// Get the players payday time (Called from inside gamemode/other includes)
forward GetPayDayTime(playerid);
public GetPayDayTime(playerid) { return PayDayTime[playerid]; }

// Used when a player logs in we can restore their payday time
forward UpdatePayDayTime(playerid, seconds);
public UpdatePayDayTime(playerid, seconds) { PayDayTime[playerid] = gettime() - seconds; }
Reply


Messages In This Thread
How to code a payday? - by Unri - 26.10.2013, 05:38
Re: How to code a payday? - by RajatPawar - 26.10.2013, 05:45
Re: How to code a payday? - by rickisme - 26.10.2013, 05:53
Re: How to code a payday? - by Pottus - 26.10.2013, 06:15
Re: How to code a payday? - by RajatPawar - 26.10.2013, 06:31
Re: How to code a payday? - by rickisme - 26.10.2013, 13:35
Re: How to code a payday? - by BigGroter - 26.10.2013, 13:43
Re: How to code a payday? - by Memoryz - 26.10.2013, 14:02
Re: How to code a payday? - by rickisme - 26.10.2013, 14:03

Forum Jump:


Users browsing this thread: 2 Guest(s)