Player score
#1

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 0MAX_PLAYERSi++)
    {
        if(!
IsPlayerConnected(i) || LoggedIn[i] != 1) continue;
        new 
string[128], hms;
        
TotalGameTime(i,h,m,s);
        if(
playedTime[i] == 3)
        {
            
PlayerInfo[i][Score] = PlayerInfo[i][Score] +1;
            
SetPlayerScore(iPlayerInfo[i][Score]);
            
GameTextForPlayer(i"~w~+$1000"80003);
            
GivePlayerMoney(i,1000);
            
format(string,sizeof(string), "You have leveled up! Your new level is %d."PlayerInfo[i][Score]);
            
SendClientMessage(iCOLOR_WHITEstring);
        }
    }
TotalGameTime(playerid, &h=0, &m=0, &s=0)
{
    
PlayerInfo[playerid][TotalTime] = ( (gettime() - gPlayerJoin[playerid]) + (PlayerInfo[playerid][TotalTime]) );
    new 
p;
    
floatround(PlayerInfo[playerid][TotalTime] / 10800floatround_floor);
    
floatround(PlayerInfo[playerid][TotalTime] / 3600floatround_floor);
    
floatround(PlayerInfo[playerid][TotalTime] / 60,   floatround_floor) % 60;
    
floatround(PlayerInfo[playerid][TotalTime] % 60,   floatround_floor);
    
playedTime[playerid] = p;
    return 
PlayerInfo[playerid][TotalTime];

Reply
#2

I would Recommend u to make a timer and after certain time You can give Score and other stuffs.
Reply
#3

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

I would rather not use timers. That's why I've got this function this function uses gettime rather than adding another timer
Reply
#5

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..
}
Reply
#6

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

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..
}
Reply
#8

konstantin pm respond pls
Reply
#9

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(
Playeri)
    {
        new 
seconds NetStats_GetConnectedTime(i) / 1000;
        new 
minutes seconds 60;
        if(
minutes >= 60)
        {
            
SendClientMessage(iCOLOR_RED"You've been online for 1 hour!");
            
PayDay(i);
        }
// and so on...

Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)