04.06.2012, 14:07
Well, I went on the SAMP wiki in search of a kills/deaths script, and I tried to understand what it meant. I got the fdelete and fcreate code, but it still returns errors when I can see it has already been defined.
That is the entire 97 line script.
The errors that script returns on compiling:
If anyone can explain what I am doing wrong, or even better, provide a better way to create a stats script, I would appreciate it, as the one on the forums clearly states it is primitive, and I've been in search of a stats script for days and days.
I will fix the loose indentation warnings myself, so ignore them for now.
Thanks.
Код:
#include <a_samp>
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 string[256];
new pname[24];
new str[256];
forward fcreate(filename[]);
public fcreate(filename[])
{
if (fexist(filename)){return false;}
new File:fhandle = fopen(filename,io_write);
fclose(fhandle);
return true;
}
fdeleteline(filename[], line[]){
if(fexist(filename)){
new temp[256];
new File:fhandle = fopen(filename,io_read);
fread(fhandle,temp,sizeof(temp),false);
if(strfind(temp,line,true)==-1){return 0;}
else{
fclose(fhandle);
fremove(filename);
for(new i=0;i<strlen(temp);i++){
new templine[256];
strmid(templine,temp,i,i+strlen(line));
if(equal(templine,line,true)){
strdel(temp,i,i+strlen(line));
fcreate(filename);
fhandle = fopen(filename,io_write);
fwrite(fhandle,temp);
fclose(fhandle);
return 1;
}
}
}
}
return 0;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveStats(playerid, d, k)
{
gstats=fopen(FILE_NAME, io_append);
GetPlayerName(playerid, pname, 24); // The name of the player
format(str, sizeof(str), "%s %d %d\n\r",pname, k, d); // format
if(!gstats)// Our check
{
fcreate(FILE_NAME);
}
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
}
}
fclose(gstats);
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/stats", cmdtext, true, 10) == 0)
{
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);
}
new Float:ratio=floatdiv(PKills[playerid], PDeaths[playerid]);
format(str, 256, "%d %d %.2f", PKills[playerid], PDeaths[playerid], ratio);
return 1;
}
return 0;
}
The errors that script returns on compiling:
Код:
SAMP S3RV\filterscripts\stats.pwn(33) : error 017: undefined symbol "equal" SAMP S3RV\filterscripts\stats.pwn(53) : error 017: undefined symbol "SaveStats" SAMP S3RV\filterscripts\stats.pwn(54) : warning 217: loose indentation SAMP S3RV\filterscripts\stats.pwn(57) : error 017: undefined symbol "k" SAMP S3RV\filterscripts\stats.pwn(74) : warning 217: loose indentation SAMP S3RV\filterscripts\stats.pwn(81) : error 017: undefined symbol "ReadStats" SAMP S3RV\filterscripts\stats.pwn(86) : error 017: undefined symbol "GetVal" SAMP S3RV\filterscripts\stats.pwn(87) : error 017: undefined symbol "GetVal" SAMP S3RV\filterscripts\stats.pwn(90) : warning 217: loose indentation Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 6 Errors.
I will fix the loose indentation warnings myself, so ignore them for now.
Thanks.

