[Help request] Saving player money
#1

Hello, I need some help with saving the players money. Here's how my script goes:

pawn Код:
public OnPlayerUpdate(playerid)
{
    new file[256], pname [MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), PlayerFile, pname);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    dini_IntSet(file, "Cash" , PlayerInfo[playerid][pCash]);
    return 1;
}
public OnPlayerLogin(playerid)
{
    new file[256], pname [MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), PlayerFile, pname);
    PlayerInfo[playerid][pCash] = dini_Int(file, "Cash");
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
    return 0;
}
public OnPlayerRegister(playerid)
{
    new file[256], pname [MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), PlayerFile, pname);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    dini_IntSet(file, "Cash", 625);
    GivePlayerMoney(playerid, 625);
    return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    OnPlayerUpdate(playerid);
    return 1;
}

public OnGameModeExit()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        OnPlayerUpdate(i);
    }
    return 1;
}
Well, I get no errors or anything, it reads the player money in OnPlayerUpdate, and it updates i GameModeExit and OnPlayerDisconnect. Can anybody help me because it doesn't save the money, it just sets it back to 0 when restarts or relogging
Reply
#2

I don't find anything but may I ask one thing.. Doesn't the OnPlayerUpdate cause a massive amount of lag since it saves into a dini file prety many times per second.
Reply
#3

try this one, made it myself, and works.
Код:
#include <a_samp>
#include <Dini>

forward LoadPlayerMoney(playerid);
new pname[30];
new PlayerMoney[MAX_PLAYERS];
#define COLOR_RED 0xFA2B25AA

public OnGameModeExit()
{
	return 1;
}

public OnPlayerConnect(playerid)
{
    if(!IsPlayerNPC(playerid))
    {
		GetPlayerName(playerid,pname,30);
	    if(!dini_Exists(pname))
	    	dini_Create(pname);
	    else if(dini_Exists(pname))
	    {
	        PlayerMoney[playerid] = dini_Int(pname,"PlayerMoney");
		}

	    LoadPlayerMoney(playerid);
		return 1;
	}
	return 1;
}

public LoadPlayerMoney(playerid)
{
    if(!IsPlayerNPC(playerid)){	GivePlayerMoney(playerid,PlayerMoney[playerid]); }
}


public OnPlayerDisconnect(playerid, reason)
{
	if(!IsPlayerNPC(playerid))
	{
    	new Pname[24];
    	GetPlayerName(playerid, Pname, 24);
    	dini_IntSet("Skins.ini", Pname, GetPlayerSkin(playerid));
    }
    return 1;
}
Quote:
Originally Posted by Mystique
Посмотреть сообщение
I don't find anything but may I ask one thing.. Doesn't the OnPlayerUpdate cause a massive amount of lag since it saves into a dini file prety many times per second.
Yes, that's true. That's not smart..
Reply
#4

Quote:
Originally Posted by Mystique
Посмотреть сообщение
I don't find anything but may I ask one thing.. Doesn't the OnPlayerUpdate cause a massive amount of lag since it saves into a dini file prety many times per second.
Well I can create a timer for it, but since I am just testing on my local server then there's no need for me to fix it right now.
Reply
#5

Quote:
Originally Posted by Wennicke
Посмотреть сообщение
Well I can create a timer for it, but since I am just testing on my local server then there's no need for me to fix it right now.
if you put a timer in the OnPlayerUpdate, it will start the timer EVERY time that there's a update..
Reply
#6

I recommend just starting a infinite timer to call every 10 seconds or something.. OnPlayerUpdate gets called too often.
Reply
#7

There don't need a Timers, Dini or any other that type of stuffs, use original Pawno file system, on Player Login Load file and on player Disconnect Save file thats it.

You don't need to save to file values each time when their changes, only once when Login and when disconnect.
Reply
#8

Maybe he wants to save it more often, and that is the reason he uses OnPlayerUpdate? That's why I said a timer.
Reply
#9

Well there's no need for It to save more often, you can't get anything out of It.

OnPlayerLogin/Spawn = Load, On‌PlayerDisconnect = Save , and the player will have their money saved perfectly fine...

Unless the player unplugs his power everytime instead of quitting the game.
Reply
#10

Quote:
Originally Posted by Mike Garber
Посмотреть сообщение
Unless the player unplugs his power everytime instead of quitting the game.
Even than player disconnect as usual, you can blow up your PC, but on server player will disconnect as usual.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)