LastSeen command (IRC & ingame) -
Roperr - 25.11.2012
Hello
I'll be showing you a simple way to save time/date of a player's last visit on the server, then how to read it with a command either on IRC or ingame.
This will surely be useful for quite a lot of people struggling to find something like this, even though it's VERY easy to do.
Needed includes
° IRC
° dini
° zcmd
Needed functions
° ReturnUser
Simply copy the code from
http://pastebin.com/zLqShVXW and add it anywhere in your code below the includes.
Saving time/date
We will be saving time/date using '
getdate()' and '
gettime()' functions, which is easy to do.
getdate(day,month,year);
gettime(hour,minute,second);
Let's start off by defining the file we'll be saving all the data to. I will be using /scriptfiles/accounts, if you use differently named folders, simply adjust it accordingly.
Getting the player's name is needed to define the proper file of his account.
pawn Код:
new dcname[MAX_PLAYER_NAME+1];
GetPlayerName(playerid, dcname, sizeof(dcname));
Located in: OnPlayerDisconnect
Now let's go ahead and define the file.
pawn Код:
new getfile[64];
format(getfile, 64, "/scriptfiles/accounts/%s.ini", dcname);
Located in: OnPlayerDisconnect
Let's use our time and date functions to save our player's last visit in the file we defined earlier.
pawn Код:
new pyear, pmonth, pday;
new phour, pminute, psecond;
new lastseen[80];
getdate(pyear, pmonth, pday);
gettime(phour, pminute, psecond);
format(lastseen, 80, "Time: %02d:%02d:%02d - Date:%02d/%02d/%d", phour, pminute, psecond, pday, pmonth, pyear);
dini_Set(getfile, "lastseen", lastseen);
Located in: OnPlayerDisconnect
That's it for the saving part, now let's move on to the commands. Firstly let's add an IRC command. If the player is online, a message explaining that will be shown.
pawn Код:
IRCCMD:lastseen(botid, channel[], user[], host[], params[])
{
new lsp[30],getfile[40],ircseen[256],gid;
if(sscanf(params,"s",lsp)) return IRC_GroupSay(IRC_Group,channel,"Usage: !lastseen <name>");
gid = ReturnUser(lsp);
if(IsPlayerConnected(gid)) return IRC_GroupSay(IRC_Group,channel,"Error: That player is currently online!");
format(getfile, 40, "/scriptfiles/accounts/%s.ini", lsp);
ircseen = dini_Get(getfile, "lastseen");
IRC_GroupSay(IRC_Group,channel,ircseen);
return 1;
}
Located in: Anywhere in the code below any includes (a_samp, dini, zcmd, irc)
A simple ingame command, you might want to limit this to admins, if you think that's needed.
pawn Код:
CMD:lastseen(playerid, params[])
{
new msp[30],getfile[40],mseen[256],mid;
if(sscanf(params,"s",msp)) return SendClientMessage(playerid, -1, "Usage: /lastseen <name>");
mid = ReturnUser(msp);
if(IsPlayerConnected(mid)) return SendClientMessage(playerid, -1, "Error: That player is currently online!");
format(getfile, 40, "/scriptfiles/accounts/%s.ini", msp);
mseen = dini_Get(getfile, "lastseen");
SendClientMessage(playerid, -1, mseen);
return 1;
}
Located in: Anywhere in the code below any includes (a_samp, dini, zcmd, irc)
And we're done
Re: LastSeen command (IRC & ingame) -
Coder_ - 25.11.2012
Nice1
I will test this later ^^
Re: LastSeen command (IRC & ingame) -
CoDeZ - 26.11.2012
Awesome thanks
Rep+
Re: LastSeen command (IRC & ingame) -
Roperr - 23.12.2012
Quote:
Originally Posted by Coder_
Nice1
I will test this later ^^
|
Quote:
Originally Posted by CoDeZ
Awesome thanks
Rep+
|
Thanks fellas
Re: LastSeen command (IRC & ingame) -
Aagya - 14.09.2015
it says error 017: undefined symbol "ReturnUser"
Re: LastSeen command (IRC & ingame) -
saffierr - 14.09.2015
I dont think the tutorial creater will see your reply as this tutorial is from 2012
Re: LastSeen command (IRC & ingame) -
Kalgon - 14.09.2015
Needed functions
° ReturnUser
Simply copy the code from
http://pastebin.com/zLqShVXW and add it anywhere in your code below the includes.
Read instead of just copy/pasting.
Re: LastSeen command (IRC & ingame) -
Roperr - 02.10.2015
Quote:
Originally Posted by saffierr
I dont think the tutorial creater will see your reply as this tutorial is from 2012
|
Wrong.
Quote:
Originally Posted by Kalgon
Needed functions
° ReturnUser
Simply copy the code from http://pastebin.com/zLqShVXW and add it anywhere in your code below the includes.
Read instead of just copy/pasting.
|
Thank you.
Re: LastSeen command (IRC & ingame) -
DarkLored - 02.10.2015
Would have been better if you'd actually explain how it is done rather than paste the code and tell the reader where to paste it in their script, very uninformative. I won't judge this though, it's a few years old and shouldn't have been bumped, I am sure the one who created this will know better next time he wants to make an actual tutorial.