SA-MP Forums Archive
Update players money when they get it..? - 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: Update players money when they get it..? (/showthread.php?tid=96236)



Update players money when they get it..? - _Vortex - 07.09.2009

Hello, I'm making an admin system. And I'm wondering how I can make it update someones money in their user file, when they get it..

Here's my enum if it helps..

Код:
enum PlayerInfo {
  gName,
  Password,
  Level,
  Regged,
  Logged,
  Money,
  Kills,
  Deaths,
}
new pInfo[MAX_PLAYERS][PlayerInfo];



Re: Update players money when they get it..? - RaFsTar - 07.09.2009

pawn Код:
forward SaveData(playerid);
public SaveData(playerid)
{
    new player[128];new saver[128];
    new pname[MAX_PLAYER_NAME];
   
    GetPlayerName(playerid,pname,sizeof(pname));
   
    format(player, sizeof(player), "users/%s.txt",pname);

    format(saver,sizeof(saver),"Password");
     dini_Set(player,saver,PlayerData[playerid][Pass]);
 
     PlayerData[playerid][Job]=GetPlayerMoney(playerid);
    format(saver,sizeof(saver),"Money");
    dini_IntSet(player,saver,PlayerData[playerid][Money]);
   
    return 1;
}
This is my saving system, hust change it as u need !


Re: Update players money when they get it..? - _Vortex - 07.09.2009

Quote:
Originally Posted by RaFsTar
forward SaveData(playerid);
public SaveData(playerid)
{
new player[128];new saver[128];
new pname[MAX_PLAYER_NAME];

GetPlayerName(playerid,pname,sizeof(pname));

format(player, sizeof(player), "users/%s.txt",pname);

format(saver,sizeof(saver),"Password");
dini_Set(player,saver,PlayerData[playerid][Pass]);

PlayerData[playerid][Job]=GetPlayerMoney(playerid);
format(saver,sizeof(saver),"Money");
dini_IntSet(player,saver,PlayerData[playerid][Money]);

return 1;
}
That doesn't help at all, that has stuff I don't even need, looks like you just coppied and pasted from somewhere :S


Re: Update players money when they get it..? - RaFsTar - 07.09.2009

Quote:
Originally Posted by [B
Vortex
That doesn't help at all, that has stuff I don't even need, looks like you just coppied and pasted from somewhere :S
Sure, from my saving system.

Dude you just need to change it as u need, then use SaveData(playerid); when player data changes.




Re: Update players money when they get it..? - _Vortex - 07.09.2009

Quote:
Originally Posted by RaFsTar
Quote:
Originally Posted by [B
Vortex
That doesn't help at all, that has stuff I don't even need, looks like you just coppied and pasted from somewhere :S
Sure, from my saving system.

Dude you just need to change it as u need, then use SaveData(playerid); when player data changes.

I'm new to codeing, I dont know how to do this kind of stuff. Hence why I asked for help.


Re: Update players money when they get it..? - RaFsTar - 07.09.2009

Try to use this:

pawn Код:
forward SaveData(playerid);
public SaveData(playerid)
{
  new player[128];new saver[128];
  new pname[MAX_PLAYER_NAME];
 
  GetPlayerName(playerid,pname,sizeof(pname));
 
  format(player, sizeof(player), "users/%s.txt",pname); // Saving folder

  PlayerInfo[playerid][Money]=GetPlayerMoney(playerid); //Gets player money
  format(saver,sizeof(saver),"Money");
  dini_IntSet(player,saver,PlayerInfo[playerid][Money]); // Saves it into users/Player.txt as "Money".
 
  return 1;
}



Re: Update players money when they get it..? - snoob - 07.09.2009

hi
from what i understand you whant to update your player cash when they get it??

if so, one way would be to create yourself a new callback like OnPlayerMoneyChange(playerid, OldMoney, NewMoney)

one way to do that is to use the evil OnPlayerUpdate callback
ie:

At top of script:
pawn Код:
new ActiveMoney[MAX_PLAYERS];// reset this to zero at onplayerexit...
In public OnPlayerUpdate(playerid):
pawn Код:
public OnPlayerUpdate(playerid)
{
 new CurMoney = GetPlayerMoney(playerid);
 if(CurMoney != ActiveMoney[playerid]) OnPlayerMoneyChange(playerid, ActiveMoney[playerid], CurMoney);
 return 1;
}
if you dont have onplayerupdate simply ad it.

Any where in script or at the end:
pawn Код:
forward OnPlayerMoneyChange(playerid, OldMoney, NewMoney);
public OnPlayerMoneyChange(playerid, OldMoney, NewMoney)
{
 // this is your new callback, its called every time a player change money.
 //the current player money is NewMoney...
 //the money he had before is OldMoney...
 printf("player: %i as change money from: %i to: %i",playerid, OldMoney, NewMoney);
 //we print the info, just for shit and giggle...
 
 ActiveMoney[playerid] = NewMoney;// we save our current active money...

 //you can save your data here using NewMoney or ActiveMoney[playerid]

 return 1;
}
I hope you already know how to save your data
also you probably dont need to know exactly when the money changed so you might not need to use onplayerupdate. if you decide to use this you might wanna read this https://sampwiki.blast.hk/wiki/OnPlayerUpdate