SA-MP Forums Archive
Adding values every minute to an MySQL column - 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: Adding values every minute to an MySQL column (/showthread.php?tid=380671)



Adding values every minute to an MySQL column - HighFlyer - 26.09.2012

Hi there,

I am looking to incorporate certain limits for my payday system. I want to add one value every minute to Player[playerid][PaydayTime] field, in order to give players their payday if they've played 30 or more minutes. How can I achieve this? I know how to define the "if" statement for the payday, but I'm struggling to work out a formula to add one value to the array every minute in game.


Re: Adding values every minute to an MySQL column - Sinner - 26.09.2012

pawn Код:
// Under OnGameModeInit()
SetTimer("RaisePayDayTime", 1000 * 30, true);

// Timer
forward RaisePayDayTime();
public RaisePayDayTime() {
    for(new i=0; i<MAX_PLAYERS; i++) {    // Or use foreach
        if(IsPlayerConnected(i)) {
            Player[playerid][PaydayTime]++;
        }
    }
}
Or if you're looking for the query to do it:

pawn Код:
UPDATE `table_name` SET `field_name` = (`field_name` + 1) WHERE `username` = 'player_username';



Re: Adding values every minute to an MySQL column - HighFlyer - 26.09.2012

I guess a code will do, it's just all about adding onto a value in the column.

Код:
Player[playerid][PaydayTime]++;
And this adds 1 every minute, does it? I thought it's different, hence I was probably going somewhere wrong with my useless code. Also, I don't need to kill the timer OnGameModeExit in this case, do I? I'll test the code, thank you.


Re: Adding values every minute to an MySQL column - HighFlyer - 29.09.2012

Not sure why, but it only works for ID 0, any offers?