Online Time System Issue
#1

Well, I scripted an online time script yesterday, while I was testing in the server with 2 players, different time connected...

Example of situation:
First, I joined at 7:30 PM, so the timer started to count. And another player joined at 8:00 PM.

But after 1 hour, which is 8:30PM, I received an hour bonus, but player 2 received it too. And after 30 minutes, 9:00 PM, I received another again.. So how to fix it? Here's the code!

OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
    //Lots of code...
    SetTimer("OneHourBonus", 1000*60*60, 1);
    return 1;
}
forward/public OneHourBonus:
pawn Код:
forward OneHourBonus();
public OneHourBonus()
{
    for (new i, slots = GetMaxPlayers(); i < slots; i ++)
    {
        GivePlayerMoney(i, 5000);
        SetPlayerScore(i,GetPlayerScore(i)+5);
        SendClientMessage(i, -1, "Thanks for playing on our server for 1 hour! As a bonus, $5000 and 5 scores have been given you.");
        pInfo[i][Hours]++;
    }

    return 1;
}
How to fix it? :/
Reply
#2

pawn Код:
SetTimerEx("OneHourBonus", 1000*60*60, true, "i", playerid); //onplayerconnect
 
forward OneHourBonus(i);
public OneHourBonus(i)
{
    GivePlayerMoney(i, 5000);
    SetPlayerScore(i,GetPlayerScore(i)+5);
    SendClientMessage(i, -1, "Thanks for playing on our server for 1 hour! As a bonus, $5000 and 5 scores have been given you.");
    pInfo[i][Hours]++;
    return 1;
}
Reply
#3

Код:
C:\Documents and Settings\User\Desktop\0.3x Script\gamemodes\stuntproject.pwn(1217) : warning 219: local variable "i" shadows a variable at a preceding level
At OneHourBonus***
Reply
#4

EDIT: zcx is totally correct. Don't take into consideration my suggestion for this bonus system. Use fordanz code.

fordawinz way is correct if you replace in forward and in public "i" with "playerid". But creating many ex timers for each connected player is more cpu consuming than this way:
pawn Код:
forward OneHourBonus();

public OnGameModeInit()
{
    SetTimer("OneHourBonus", 3600000, 1);
}

public OneHourBonus()
{
   for (new i=0, i<MAX_PLAYERS;, i++)
   {
       if (IsPlayerConnected(i))
       {
           GivePlayerMoney(i, 5000);
           SetPlayerScore(i, GetPlayerScore(i)+5);
           SendClientMessage(i, -1, "Thanks for playing on our server for 1 hour! As a bonus, $5000 and 5 scores have been given you.");
           pInfo[i][Hours]++;
       }
   }
}
EDIT: zcx is totally correct. Don't take into consideration my suggestion for this bonus system. Use fordanz code.
Reply
#5

You are wrong, for example if I start the gm on 8:00, and log in on 8:59, I'll still receive the bonus, although I did not play an hour.
I guess he has to use SetTimerEx.
Reply
#6

How, ******? GetTickCount on OnPlayerConnect?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)