Player score -
Tass007 - 22.09.2016
Hey guys, I'm trying to create a system so that every 3 hours a player is in game they get 1 score. For example say if a player played 24 hours their score would be 8. I'm having trouble working out the equation that calculates the score.
Here is what I have.
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || LoggedIn[i] != 1) continue;
new string[128], h, m, s;
TotalGameTime(i,h,m,s);
if(playedTime[i] == 3)
{
PlayerInfo[i][Score] = PlayerInfo[i][Score] +1;
SetPlayerScore(i, PlayerInfo[i][Score]);
GameTextForPlayer(i, "~w~+$1000", 8000, 3);
GivePlayerMoney(i,1000);
format(string,sizeof(string), "You have leveled up! Your new level is %d.", PlayerInfo[i][Score]);
SendClientMessage(i, COLOR_WHITE, string);
}
}
TotalGameTime(playerid, &h=0, &m=0, &s=0)
{
PlayerInfo[playerid][TotalTime] = ( (gettime() - gPlayerJoin[playerid]) + (PlayerInfo[playerid][TotalTime]) );
new p;
p = floatround(PlayerInfo[playerid][TotalTime] / 10800, floatround_floor);
h = floatround(PlayerInfo[playerid][TotalTime] / 3600, floatround_floor);
m = floatround(PlayerInfo[playerid][TotalTime] / 60, floatround_floor) % 60;
s = floatround(PlayerInfo[playerid][TotalTime] % 60, floatround_floor);
playedTime[playerid] = p;
return PlayerInfo[playerid][TotalTime];
}
Re: Player score -
Shaheen - 22.09.2016
I would Recommend u to make a timer and after certain time You can give Score and other stuffs.
Re: Player score -
Marricio - 22.09.2016
Use a separate variable similar to TotalTime that resets when it hits 60 minutes. In a minute timer, add 1 minute to the variable and once it hits 60: add 1 Score, reset variable, repeat. Of course, ideally you would have to save this in a player file so the player can play 30 minutes today and 30 minutes tomorrow to hit 1 score. TotalGameTime is also a neat function, you could modify it to work this out too but I think the other method I mentioned is more practical.
Re: Player score -
Tass007 - 22.09.2016
I would rather not use timers. That's why I've got this function this function uses gettime rather than adding another timer
Re: Player score -
Konstantinos - 22.09.2016
Quote:
Originally Posted by Tass007
I would rather not use timers. That's why I've got this function this function uses gettime rather than adding another timer
|
At least 1 timer is needed in order to check the time. The explanation was kind of confusing, every 3 hours connected or in total?
A timer with interval of 1 hour would do and then:
pawn Код:
// every 3 hours currently connected:
if (!(((gettime() - gPlayerJoin[playerid]) / 3600) % 3))
{
// level up..
}
or
pawn Код:
// every 3 hours in total:
PlayerInfo[playerid][TotalTime] = (gettime() - gPlayerJoin[playerid]) + PlayerInfo[playerid][TotalTime];
if (!((PlayerInfo[playerid][TotalTime] / 3600) % 3))
{
// level up..
}
Re: Player score -
Tass007 - 22.09.2016
Quote:
Originally Posted by Konstantinos
At least 1 timer is needed in order to check the time. The explanation was kind of confusing, every 3 hours connected or in total?
A timer with interval of 1 hour would do and then:
pawn Код:
// every 3 hours currently connected: if (!(((gettime() - gPlayerJoin[playerid]) / 3600) % 3)) { // level up.. }
or
pawn Код:
// every 3 hours in total: PlayerInfo[playerid][TotalTime] = (gettime() - gPlayerJoin[playerid]) + PlayerInfo[playerid][TotalTime];
if (!((PlayerInfo[playerid][TotalTime] / 3600) % 3)) { // level up.. }
|
Sorry for the confusion but every three hours total.
Re: Player score -
Konstantinos - 22.09.2016
If a player has less than 3600 seconds in total, mod 3 will give 0 so to fix it:
pawn Код:
PlayerInfo[playerid][TotalTime] = (gettime() - gPlayerJoin[playerid]) + PlayerInfo[playerid][TotalTime];
if (PlayerInfo[playerid][TotalTime] >= 3600 && !((PlayerInfo[playerid][TotalTime] / 3600) % 3))
{
// level up..
}
Re: Player score -
StR_MaRy - 22.09.2016
konstantin pm respond pls
Re: Player score - iLearner - 22.09.2016
There's a samp function that counts the miliseconds since player was connected... simply use that...
this is mine, something similiar to yours:
PHP код:
forward TimeOnline();
public TimeOnline()
{
foreach(Player, i)
{
new seconds = NetStats_GetConnectedTime(i) / 1000;
new minutes = seconds / 60;
if(minutes >= 60)
{
SendClientMessage(i, COLOR_RED, "You've been online for 1 hour!");
PayDay(i);
}
// and so on...
}
Re: Player score -
Marricio - 22.09.2016
And what if the player crashes, his electricity shuts down, internet fails or a strange script opcode occurs? The player will have to wait 3 hours in-game again since his time will be reset to 0 once he connects again.
If you use a 1 minute timer and save the player time you will avoid this. Perhaps, if you don't want a timer just save the time played when a player disconnects, but you will not be able to check when a player reaches exactly 3 hours since you're not using a timer. You must use one in order to make it work properly.