25.11.2012, 11:32
(
Последний раз редактировалось Roperr; 24.02.2013 в 16:29.
)
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));
Now let's go ahead and define the file.
pawn Код:
new getfile[64];
format(getfile, 64, "/scriptfiles/accounts/%s.ini", dcname);
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);
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;
}
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;
}
And we're done