Timers - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Timers (
/showthread.php?tid=99099)
Timers -
ded - 25.09.2009
Basically, what I would like is to make a command ... which when typed would return how long that player has been connected for (session time) .. for example /timeon [ID] and it would tell me the time that that player has been connected to the server but I have no idea how to do this, could somebody point me in the right direction? I can make the command and everything myself I just need an idea of how I could get the time.
I'm guessing I would have to set a timer OnPlayerConnect or something
Much appreciated.
Re: Timers -
ilikepie2221 - 25.09.2009
pawn Код:
new PlayerTime[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
SetTimer("PlayerTimeOn",60000,true);
return 1;
}
forward PlayerTimeOn(playerid);
public PlayerTimeOn(playerid)
PlayerTime[playerid]++;
public OnPlayerCommandText(playerid,cmdtext[])
{
dcmd(timeon,6,cmdtext);
return 0;
}
dcmd_timeon(playerid,params[])
{
new checkplayerid;
if(sscanf(params,"u",checkplayerid)) return SendClientMessage(playerid,0xFFFFFFFF,"Usage:\"/timeon [ID/part of player name]\"");
else if(checkplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,0xFF0000FF,"Player not found");
else
{
new string[64],name[MAX_PLAYER_NAME];
GetPlayerName(checkplayerid,name,sizeof(name));
format(string,sizeof(string),"%s has been online for %i minutes",name,PlayerTime[checkplayerid]);
SendClientMessage(playerid,0xFFFFFFFF,string);
}
return 1;
}
Untested and very un-refined. Probably also some errors.
Re: Timers -
ded - 25.09.2009
Thanks for the reply
I'll test it out and let you know.
Would you not have to use SetTimerEx ?
Re: Timers -
MadeMan - 25.09.2009
Quote:
Originally Posted by » Pawnst★r «
Would you not have to use SetTimerEx ?
|
Yes
Re: Timers -
ded - 25.09.2009
Quote:
Originally Posted by MadeMan
Quote:
Originally Posted by » Pawnst★r «
Would you not have to use SetTimerEx ?
|
Yes
|
How would you do that then? I'm noob on timers. :/
Re: Timers -
MadeMan - 25.09.2009
pawn Код:
SetTimerEx("PlayerTimeOn",60000,true,"i",playerid);
Re: Timers -
MenaceX^ - 25.09.2009
Quote:
Originally Posted by MadeMan
pawn Код:
SetTimerEx("PlayerTimeOn",60000,true,"i",playerid);
|
I think he meant it in a different way.
I suggest you to use the same code in OnPlayerConnect because if you put it in OnGameModeInit it won't recognize the playerid.
Re: Timers -
ded - 25.09.2009
Quote:
Originally Posted by MadeMan
pawn Код:
SetTimerEx("PlayerTimeOn",60000,true,"i",playerid);
|
That's how I did it .. so I was right \o/
I put it under OnPlayerConnect .. the code works, thanks ilikepie2221