Leveling system only working for 1 person, and bad. -
ricardo178 - 28.05.2012
Hello, i tried to make my own leveling system, but it is kinda bugged. It doesn't work for everyplayer when more than one is online, and sometimes it takes less than 60 seconds to pass 1 minute..
Here is the code:
pawn Код:
Under OnPlayerConnect i have:
SetTimer("PlayingTime", 60000, true);
Than the function is:
forward PlayingTime(playerid);
public PlayingTime(playerid)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
PlayerInfo[playerid][PlayingMinutes]++;
if(PlayerInfo[playerid][PlayingMinutes] >= 60)
{
PlayerInfo[playerid][PlayingHours]++;
PlayerInfo[playerid][RespectPoints]++;
PlayerInfo[playerid][PlayingMinutes] = 0;
format(file, sizeof(file), "RRP/users/%s.ini", Name);
if(fexist(file))
{
dini_IntSet(file, "PlayingHours", PlayerInfo[playerid][PlayingHours]);
dini_IntSet(file, "RespectPoints", PlayerInfo[playerid][RespectPoints]);
dini_IntSet(file, "PlayingMinutes", PlayerInfo[playerid][PlayingMinutes]);
}
return 1;
}
format(file, sizeof(file), "RRP/users/%s.ini", Name);
if(fexist(file))
{
dini_IntSet(file, "PlayingMinutes", PlayerInfo[playerid][PlayingMinutes]);
}
return 1;
}
Thanks. I am really bad with timers.. :S
Re: Leveling system only working for 1 person, and bad. -
MP2 - 28.05.2012
Quote:
Under OnPlayerConnect i have:
pawn Код:
SetTimer("PlayingTime", 60000, true);
|
Going to stop right there. You need to use SetTimerEx, with a variable to store the timer ID so you can kill it under OnPlayerDisconnect.
pawn Код:
new TIMER_pOnlineTime[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
TIMER_pOnlineTime[playerid] = SetTimerEx("OnlineTime", 60000, true, "i", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(TIMER_pOnlineTime[playerid]);
return 1;
}
Also I recommend just saving the minutes, as you can convert it in to hours/days etc. with maths. Less memory needed.
Re: Leveling system only working for 1 person, and bad. -
iggy1 - 28.05.2012
pawn Код:
SetTimerEx("PlayingTime", 60000, true, "d", playerid);
If you use set a variable to gettime() when the player connects, when they disconnect subtract that from gettime() and thats how many seconds they have been on server, w/0 a timer. Also better than down to the munute.
Re: Leveling system only working for 1 person, and bad. -
MP2 - 28.05.2012
Quote:
Originally Posted by iggy1
pawn Код:
SetTimerEx("PlayingTime", 60000, true, "d", playerid);
If you use set a variable to gettime() when the player connects, when they disconnect subtract that from gettime() and thats how many seconds they have been on server, w/0 a timer. Also better than down to the munute.
|
Server could crash. Imagine playing for two hours then the server crashes.
Re: Leveling system only working for 1 person, and bad. -
ricardo178 - 28.05.2012
Will try this way, will post here the result when i test. Thanks once again.
Re: Leveling system only working for 1 person, and bad. -
iggy1 - 28.05.2012
pawn Код:
new gPlayTime[ MAX_PLAYERS ];
new gPlayerJoinTime[ MAX_PLAYERS ];
public OnPlayerConnect(playerid)
{
gPlayerJoinTime[ playerid ] = gettime();
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
gPlayTime[ playerid ] = ( gettime()-gPlayerJoinTime[playerid] );
return 1;
}
@ Mp2s comment : Make sure you also save this where your player data saves in case the server crashes
![Wink](images/smilies/wink.png)
As you should with all player stats.
Re: Leveling system only working for 1 person, and bad. -
IceCube! - 28.05.2012
Quote:
Originally Posted by MP2
Server could crash. Imagine playing for two hours then the server crashes.
|
Stats will also be lost... Example I just lost my brand new car but on the brighter side I kept my 2 hour playing time.
Re: Leveling system only working for 1 person, and bad. -
MP2 - 28.05.2012
@iggy1: True actually, you could save it every few mins.
Re: Leveling system only working for 1 person, and bad. -
ricardo178 - 28.05.2012
It looks to work. Thank you all.
Re: Leveling system only working for 1 person, and bad. -
milanosie - 28.05.2012
Sorry to be rude, but this is the 5th topic within 2 weeks from you about the same exact problem.
I'm getting the feeling that even after we told you the right way of using things, like TimerEx you still keep doing it the wrong way.
Might be an idea to write it down, so you won't need to open 5 topics on the same problem