Remember stats on 2 mins after quit/crash

Started by rww, Jul 16, 2018, 04:50 PM

Previous topic - Next topic

rww

This is an example script. The server remembers the stats for 2 minutes after leaving the server. After 2 mins, score will be reset to value 0.

function onScriptLoad()
{
RememberPlrStats <- {};
PlayersScore <- {};
NewTimer("refresh",5000,0);
return 1;
}

function onPlayerJoin(player)
{
if (PlayersScore.rawin(p.UniqueID)) KillsA[p.ID] = PlayersScore.rawget(p.UniqueID);
if (PlayersScore.rawin(p.UniqueID)) PlayersScore.rawdelete(p.UniqueID);
if (RememberPlrStats.rawin(p.UniqueID)) RememberPlrStats.rawdelete(p.UniqueID);
return 1;
}

function onPlayerPart(player,reason)
{
RememberPlrStats.rawset(player.UniqueID,GetTickCount())
PlayersScore.rawset(player.UniqueID,player.Score);
return 1;
}

function onPlayerKill(killer,player,reason,body)
{
killer.Score ++;
return 1;
}

function refresh()
{
foreach (uid, tick in RememberPlrStats)
{
local count = GetTickCount() - tick;
print(count);
if (count > 120000) //in ms (here it's 2min)
{
if (PlayersScore.rawin(uid)) PlayersScore.rawdelete(uid);
if (RememberPlrStats.rawin(uid)) RememberPlrStats.rawdelete(uid);
}
}
}
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X