Saving system
#1

So that's another Issue I have, The admin level perfectly saves!

Now my points, score, kills,deaths won't save inside the ini file

Here's on player disconnect callback code

Код:
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"Admin", pInfo[playerid][Admin]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
        INI_WriteInt(file,"Score",GetPlayerScore(playerid));
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);
        INI_WriteInt(file,"Points",pInfo[playerid][Points]);
        INI_Close(file);
        return 1;
    }
 	InArena1[playerid] = 0;
    return 1;
}
and loadaccount

Код:
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129);
    INI_Int("Admin",pInfo[playerid][Admin]);
    INI_Int("Money",pInfo[playerid][Money]);
    INI_Int("Score",pInfo[playerid][Score]);
    INI_Int("Kills",pInfo[playerid][Kills]);
    INI_Int("Deaths",pInfo[playerid][Deaths]);
    return 1;
}
Reply
#2

First of all,

Код:
INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
is a MAJOR security issue. Why? If I use a hack / any tool that can set my money to X value, saving system will fetch my current money. That means, If I receive $100k from the hack, it will actually save and I might be able to use that money. That is why we store Player's Money into a variable.

Also,
Код:
INI_Int("Score",pInfo[playerid][Score]);
here you're loading player's store that you HAVE NOT saved into pInfo[playerid][Score] variable.

Add this before you save the score
Код:
 pInfo[playerid][Score] = GetPlayerScore(playerid);
Show us 'OnPlayerDeath' callback for kills/deaths.
Reply
#3

Ok, forgot to remove the money thingy, Ignore that since I have a custom made point system by me and by my friend so no worries about that, It doesn't save either, I'll remove the money later

Here's the callback

Код:
public OnPlayerDeath(playerid,killerid,reason)
{
	// Kills Deaths & Ratio TD.
	PlayerKills[killerid]++; // Addes a score to player killed.
	PlayerDeaths[playerid]++; // Addes a score to player death.
	new iString[100]; // string cells.
	new Float:ratio = PlayerKills[killerid]/PlayerDeaths[playerid];
	format(iString, sizeof iString, "Kills: %i", PlayerKills[killerid]); // Here we put the amout of Killed players.
	TextDrawSetString(KILLS[killerid], iString);
	format(iString, sizeof iString, "Deaths: %i", PlayerDeaths[playerid]); // Here we put the amout of Deaths.
	TextDrawSetString(DEATHS[playerid], iString);
	format( iString, sizeof( iString ), "Ratio: %.2f", ratio);
	TextDrawSetString(RATIO[playerid], iString);
	
	// Killing spree system. 
 	PlayerTotalKills[killerid]++;
    PlayerTotalKills[playerid] = 0;
    if(PlayerTotalKills[killerid] == 2) {
      	new string[128];
      	new name[MAX_PLAYER_NAME];
	    GetPlayerName(killerid, name, sizeof(name));
		format(string, sizeof(string), "(Killing-Spree) %s is on a killing spree with 2 killed players! and earns +5 points!",name);
		SendClientMessageToAll(-1, string);
        format(iString, sizeof iString, "Killing Spree= %i", PlayerTotalKills[killerid]); // TD's format to the actual KillingSpree system.
		TextDrawSetString(KILLINGSPREE[playerid], iString);
		SetPlayerScore(killerid, GetPlayerScore(killerid) + 5);
       	pInfo[killerid][Points] += 5;
       	new INI:file = INI_Open(Path(playerid));
       	INI_WriteInt(file, "Points", pInfo[killerid][Points]);
    }
    
    // Saving kills and deaths on player's config file.
    pInfo[killerid][Kills]++;
    pInfo[playerid][Deaths]++;
    
    // sending the death message icons
	if(IsPlayerConnected(killerid)) SendDeathMessage(killerid, playerid, reason);
    return 1;
}
Reply
#4

The code is (once again) properly written (https://sampforum.blast.hk/showthread.php?tid=273088).

Are you sure that you have field 'Kills' & 'Deaths' in your user configuration file? Then again, how do you know if data isn't loaded? Do you have a command that displays stats or something like so?
Reply
#5

That code is not from his tutorial(His one is really buggy), It's from newbienoob's one(It was also bugged but I managed to fix it somehow lol.)

I don't have stats, and yes

Код:
[Player's Data]
Points = 0
Deaths = 0
Kills = 0
Score = 0
Money = 0
Admin = 0
Password = 2284011421411A104799568D490F01DAB30240E4248DF1981911B727811D6F4D7EDD2EFCE86963BFE8BC4C6E95438E60CA18C6A8C66DB77873DCE268E28BDB4E
Reply
#6

bump
Reply
#7

just switch to mysql and forget stupid ini system already, its just waste of time and funcinality is poor.
Reply
#8

You're not really helping me here, Anyone else?
Reply
#9

I wonder why you are using 2 variables for death and kills?
Код:
PlayerKills[killerid]++;
PlayerDeaths[playerid]++; 

pInfo[killerid][Kills]++;
pInfo[playerid][Deaths]++;
Remove one of them and print both variable values at OnPlayerDisconnect. Show me the output.
Reply
#10

2 variables are to calculate the current deaths and kills that are shown on the textdraw (and will be to 0 at relog), other are to save on ini files
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)