[Tutorial] LastSeen command (IRC & ingame)
#1



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
Reply


Messages In This Thread
LastSeen command (IRC & ingame) - by Roperr - 25.11.2012, 11:32
Re: LastSeen command (IRC & ingame) - by Coder_ - 25.11.2012, 12:44
Re: LastSeen command (IRC & ingame) - by CoDeZ - 26.11.2012, 11:39
Re: LastSeen command (IRC & ingame) - by Roperr - 23.12.2012, 08:41
Re: LastSeen command (IRC & ingame) - by Aagya - 14.09.2015, 10:42
Re: LastSeen command (IRC & ingame) - by saffierr - 14.09.2015, 12:26
Re: LastSeen command (IRC & ingame) - by Kalgon - 14.09.2015, 19:23
Re: LastSeen command (IRC & ingame) - by Roperr - 02.10.2015, 09:05
Re: LastSeen command (IRC & ingame) - by DarkLored - 02.10.2015, 18:38

Forum Jump:


Users browsing this thread: 1 Guest(s)