rendered paste body#include <a_samp>
#define COLOR_PINK 0xFF66FFAA
new Val;
new gPlayerKills[MAX_PLAYERS];
new gPlayerDeaths[MAX_PLAYERS];
public OnFilterScriptInIt() {
print("Saveable stats script..");
print("..Loading..");
print("Load Succesfull!");
}
public OnPlayerDisconnect(playerid)
{
new File:stats = fopen("stats.txt", io_write);
new pname[256];
new str[256];
GetPlayerName(playerid, pname, 256);
format(str, sizeof(str), "%s %d %d", pname, gPlayerDeaths[playerid], gPlayerKills[playerid]);
fwrite(stats, str);
fclose(stats);
}
public OnPlayerConnect(playerid) {
new File:stats = fopen("stats.txt", io_read);
new pname[256];
new str[256];
GetPlayerName(playerid, pname, 256);
if(fmatch("stats.txt", pname)) {
fread(stats, str);
GetVal(str); gPlayerDeaths[playerid] = Val;
GetSecondVal(str); gPlayerKills[playerid] = Val;
fclose(stats);
SendClientMessage(playerid, 0xAA3333AA, "Your stats has been restored.");
}
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/stats", true)==0) {
GetPlayerStats(playerid);
return 1;
}
return 0;
}
public GetPlayerStats(playerid) {
new Float:ratio = floatdiv(gPlayerKills[playerid], gPlayerDeaths[playerid]);
new string[256];
format(string, sizeof(string), "* PM From Admin: Kills: %d, Deaths: %d, Ratio: %.2f", gPlayerKills[playerid], gPlayerDeaths[playerid], ratio);
SendClientMessage(playerid, COLOR_PINK, string);
}
public GetVal(string[])
{
new tmp[32];
new idx;
tmp = strtok(string, idx);
tmp = strtok(string, idx);
Val = strval(tmp);
}
public GetSecondVal(string[])
{
new tmp[32];
new idx;
tmp = strtok(string, idx);
tmp = strtok(string, idx);
tmp = strtok(string, idx);
Val = strval(tmp);
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}