#include <a_samp>
new Float:ratio=floatdiv(PKills[playerid], PDeaths[playerid]);
format(str, 256, "%d %d %.2f", PKills[playerid], PDeaths[playerid], ratio);
public OnPlayerConnect(playerid)
{
new pname[24], File:ftw=fopen("userinfo/users.cfg", io_append);
GetPlayerName(playerid, pname, 24);
fwrite(ftw, pname);
new string[30];
format(string, 30, "%s\r\n", pname); // formatting the string with the escape codes
fwrite(ftw, string);
fclose(ftw);
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[256];
new Float:X, Float:Z, Float:Y, Float:Rotation; // Floats to save the pos in
if (strcmp(cmdtext, "/pos", true)==0)
{
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, Rotation);
new File:pos=fopen("userinfo/positions.cfg", io_append);
format(string, 256, "AddPlayerClass(0, %f, %f, %f, %f, 0,0,0,0,0,0);", X, Y, Z,Rotation);
fwrite(pos, string);
fclose(pos);
return 1;
}
return 0;
}
new PKills[MAX_PLAYERS]; // Kill Tracker
new PDeaths[MAX_PLAYERS]; // Death tracker
#define FILE_NAME "stats.txt" // The name of the file
new File:gstats; // The file
new str[256];
if(!gstats)
{
fcreate(FILE_NAME);}
SaveStats(playerid, d, k) {
gstats=fopen(FILE_NAME, io_append);
GetPlayerName(playerid, pname, 24); // The name of the player
format(str, 256, "%s %d %d\n\r",pname, k, d); // format
if(!gstats) { fcreate(FILE_NAME); } // Our check
while(fread(gstats, string)) {
if(strcmp(string, pname, false, strlen(pname))==0) { // To check if the players name is in the file
fdeleteline(FILE_NAME, string); // delete the line
fwrite(gstats, str); // write the string
}
else if(strcmp(string, pname, false, strlen(pname))!=0) { // Its NOT true
fwrite(gstats, str);
}
}
fclose(gstats);
}
ReadStats(playerid) {
gstats=fopen(FILE_NAME, io_read);
GetPlayerName(playerid, pname, 24);
while(fread(gstats, string)) {
if(strcmp(str, pname, false, strlen(pname))==0) {
PKills[playerid]=GetVal(1, str);
PDeaths[playerid]=GetVal(2, str);
}
}
fclose(gstats);
}