SAMP Wiki: Statistics script not working
#1

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.

Код:
#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;
}
That is the entire 97 line script.
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.
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.
Reply
#2

You're calling for functions/variables, which have not been defined (or coded) in your script. For example, when the script says equal(templine,line,true), it has no idea what to do, since it has not been told what to do.

If you add (for example)
pawn Код:
public equal(var1, var2, match)
{
    if((var1 == var2 && match) || (var1 != var2 && !match)){
        return true;
    }else {
        return false;
    }
}
it will know what to do.

But I think you're missing an include, which can be fixed by adding #include <some-file-here> to the start of your script right under the other includes.
Reply
#3

I appreciate the help 3ventric, but I don't think I need any includes, as the source of the script is https://sampwiki.blast.hk/wiki/File_Functions, and it doesn't state I need any includes.

Despite adding in that code, making the script:
Код:
#include <a_samp>
#include <

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[]);
forward equal(var1, var2, match);

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 equal(var1, var2, match)
{
    if((var1 == var2 && match) || (var1 != var2 && !match)){
        return true;
    }else {
        return false;
    }
}

public OnPlayerConnect(playerid)
{
    if(!gstats)// Our check
    {
        fcreate(FILE_NAME);
    }
	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

    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;
}
It still returns a few errors
Код:
SAMP S3RV\filterscripts\stats.pwn(33) : error 035: argument type mismatch (argument 1)
SAMP S3RV\filterscripts\stats.pwn(67) : error 017: undefined symbol "SaveStats"
SAMP S3RV\filterscripts\stats.pwn(68) : warning 217: loose indentation
SAMP S3RV\filterscripts\stats.pwn(71) : error 017: undefined symbol "k"
SAMP S3RV\filterscripts\stats.pwn(83) : warning 217: loose indentation
SAMP S3RV\filterscripts\stats.pwn(90) : error 017: undefined symbol "ReadStats"
SAMP S3RV\filterscripts\stats.pwn(95) : error 017: undefined symbol "GetVal"
SAMP S3RV\filterscripts\stats.pwn(96) : error 017: undefined symbol "GetVal"
SAMP S3RV\filterscripts\stats.pwn(99) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.
Reply
#4

if(!strcmp(templine, line, true))
You Can Use This For It!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)