Adding values every minute to an MySQL column
#1

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

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';
Reply
#3

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)