Money problem
#1

Hello i have a save money problem with a job filterscript. When i start the job and finish gives me money but when i save accounts and restart server the money is gone.. How to fix this?
Reply
#2

Can you show us the saving system in the gamemode, and the filterscript?
Reply
#3

The gamemode have but the filterscript dont..

Код:
public OnPlayerDataSave(playerid)
{
    if(IsPlayerConnected(playerid))
	{
		if(gPlayerLogged[playerid] && gPlayerSpawned[playerid])
		{
		    new string[256], playersip[64];
		    format(string, sizeof(string), "%s.ini", PlayerName(playerid));
		    GetPlayerIp(playerid, playersip, sizeof(playersip));
		    if(dini_Exists(string))
		    {
		        dini_Set(string, "Key", PlayerInfo[playerid][pKey]);
		        dini_Set(string, "IP", PlayerInfo[playerid][pIP]);
		        dini_IntSet(string, "AdminLevel", PlayerInfo[playerid][pAdmin]);
		        dini_IntSet(string, "aDuty", PlayerInfo[playerid][aDuty]);
		        dini_IntSet(string, "aTog", PlayerInfo[playerid][aTog]);
		        dini_IntSet(string, "pMember", PlayerInfo[playerid][pMember]);
		        dini_IntSet(string, "pRank", PlayerInfo[playerid][pRank]);
		        dini_IntSet(string, "Banned", PlayerInfo[playerid][pBanned]);
		        dini_IntSet(string, "DonateRank", PlayerInfo[playerid][pDonateRank]);
		        dini_IntSet(string, "Registered", PlayerInfo[playerid][pReg]);
		        dini_IntSet(string, "Warnings", PlayerInfo[playerid][pWarns]);
		        dini_IntSet(string, "Cash", PlayerInfo[playerid][pCash]);
		        dini_IntSet(string, "Kills", PlayerInfo[playerid][pKills]);
		        dini_IntSet(string, "Deaths", PlayerInfo[playerid][pDeaths]);
		        dini_IntSet(string, "Muted", PlayerInfo[playerid][pMuted]);
		        dini_IntSet(string, "TimeMuted", PlayerInfo[playerid][ptMuted]);
		        dini_IntSet(string, "VipMuted", PlayerInfo[playerid][pvMuted]);
		        dini_IntSet(string, "KillSpree", PlayerInfo[playerid][pSpree]);
		        dini_IntSet(string, "CWons", PlayerInfo[playerid][pCWons]);
		        dini_IntSet(string, "Hide", PlayerInfo[playerid][pHide]);
                dini_IntSet(string, "pJailed", PlayerInfo[playerid][pJailed]);
                dini_IntSet(string, "pArrested", PlayerInfo[playerid][pArrested]);
		        dini_IntSet(string, "pCrimes", PlayerInfo[playerid][pCrimes]);
		        dini_IntSet(string, "pJail", PlayerInfo[playerid][pJail]);
            	dini_IntSet(string, "pJailTime", PlayerInfo[playerid][pJailTime]);
            	dini_IntSet(string, "pWantedDeaths", PlayerInfo[playerid][pWantedDeaths]);
		    }
		}
	}
    return 1;
}
Reply
#4

Wow i have that problem with all filterscripts, how to fix it please help me..?
Reply
#5

Your posted code is from your gamemode?
And I guess the filterscript uses GivePlayerMoney to reward the player?

Then it's obvious.

The "pCash" variable inside your gamemode doesn't hold the money given by the filterscript, therefore it's not saved.

You can add a small function in your gamemode to allow the filterscript to send the money to your gamemode, so the variable is updated and saved as a result.

Just create a public function like this one in your gamemode:
pawn Код:
// This function is used to give the player some money
forward GM_GivePlayerMoney(playerid, Money);
public GM_GivePlayerMoney(playerid, Money)
{
    // Add the given money to the player's account
    PlayerInfo[playerid][pCash] = PlayerInfo[playerid][pCash] + Money;

    // Return that the function had success
    return 1;
}
Then, inside your filterscript, remotely call that function wherever the script gives your player some money:
pawn Код:
CallRemoteFunction("GM_GivePlayerMoney", "ii", playerid, Money);
This way, the filterscript uses a remote call to your gamemode and sends the playerid and money to be rewarded along with it.

The gamemode executes that function and adds the given amount of money to the given player.
That way, your pCash variable will also hold the money rewarded by your filterscript(s) and will be saved of course whenever your gamemode saves the player's data.

I'm using the same setup in my own PPC_Trucking V2, as my filterscript holds the admin-system, and also the cash/score of every player, but the gamemode can reward players as well.
Reply
#6

The reason it is not "giving" You anything when You log-in is because the money is not saved.
It is not same to save money and deaths or kills, as You don't really automatically update the money.

You need to GetPlayerMoney(); on 'OnPlayerDateSave', THEN, it will save!

replace this:

pawn Код:
dini_IntSet(string, "Cash", PlayerInfo[playerid][pCash]);
with this:

pawn Код:
dini_IntSet(string, "Cash", GetPlayerMoney(playerid));
And this is how You'll load it:

pawn Код:
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
Reply
#7

Where to add this in filterscript "CallRemoteFunction("GM_GivePlayerMoney", "ii", playerid, Money);"?
Reply
#8

Quote:
Originally Posted by dundolina
Посмотреть сообщение
Where to add this in filterscript "CallRemoteFunction("GM_GivePlayerMoney", "ii", playerid, Money);"?
That is not necessary, just see what I wrote.
Reply
#9

Ok, but where to add this "GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);"?
Reply
#10

Quote:
Originally Posted by dundolina
Посмотреть сообщение
Where to add this in filterscript "CallRemoteFunction("GM_GivePlayerMoney", "ii", playerid, Money);"?
You need to add this everywhere in your filterscript where you can find GivePlayerMoney.
You can of course replace all those GivePlayerMoney-lines by the line posted above.
Then your filterscript uses the same anti-money hack system used by your gamemode.

Your gamemode seems to use some sort of server-sided money so players cannot hack their money.
Using GetPlayerMoney to save your money is absolutely out of the question and renders your entire server-based money system obsolete.
Players would just hack some money, exit the server to save it, relog and voila, they have all the money they need "legally" obtained because now their client-sided money is equal to the value stored in your pCash variable.

BTW, does your gamemode update the player's money every second or so?
Seems to me, according to your explanation, that your filterscript uses GivePlayerMoney (which is client-sided money) and your server doesn't update that frequently.

You could also add a timer that runs every second and updates the client's money with the value of pCash.
Even if they hack their money on their client, the hack will be rendered useless because your timer would reset the client-sided money to 0 first, then use GivePlayerMoney with the value of your pCash variable.
Their hacked money is gone within a second using this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)