Timers
#1

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

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

Thanks for the reply

I'll test it out and let you know.

Would you not have to use SetTimerEx ?
Reply
#4

Quote:
Originally Posted by » Pawnst★r «
Would you not have to use SetTimerEx ?
Yes
Reply
#5

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

pawn Код:
SetTimerEx("PlayerTimeOn",60000,true,"i",playerid);
Reply
#7

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

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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)