Online Time System Issue -
LeeXian99 - 23.04.2013
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? :/
Re: Online Time System Issue -
fordawinzz - 23.04.2013
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;
}
Re: Online Time System Issue -
LeeXian99 - 23.04.2013
Код:
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***
AW: Online Time System Issue -
HurtLocker - 23.04.2013
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.
Re: Online Time System Issue -
zxc1 - 23.04.2013
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.
Re: Online Time System Issue -
LeeXian99 - 23.04.2013
How, ******? GetTickCount on OnPlayerConnect?