SA-MP Forums Archive
[Help request] Saving player money - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Help request] Saving player money (/showthread.php?tid=173331)



[Help request] Saving player money - Wennicke - 02.09.2010

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


Re: [Help request] Saving player money - Mystique - 02.09.2010

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.


Re: [Help request] Saving player money - gangstajoe - 02.09.2010

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..


Re: [Help request] Saving player money - Wennicke - 02.09.2010

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.


Re: [Help request] Saving player money - gangstajoe - 02.09.2010

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..


Re: [Help request] Saving player money - LarzI - 02.09.2010

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


Re: [Help request] Saving player money - Voldemort - 02.09.2010

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.


Re: [Help request] Saving player money - LarzI - 02.09.2010

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


Re: [Help request] Saving player money - Mike Garber - 02.09.2010

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.


Re: [Help request] Saving player money - Voldemort - 02.09.2010

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.