SA-MP Forums Archive
Server Sided 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: Server Sided Money (/showthread.php?tid=167090)



Server Sided Money - Toni - 11.08.2010

Hey there, I'm a little confused, I am trying to create a server side money system, and that isn't going to well.

Can someone help me?

(I'm not gonna share the code I made cause it didn't work at all).


Re: Server Sided Money - Dudits - 11.08.2010

Add this to the top of your script.
pawn Код:
enum pInfo
{
    pMoney
}
new PlayerInfo[MAX_PLAYERS][pInfo];

Change your
pawn Код:
GivePlayerMoney(playerid, amount);
to
pawn Код:
PlayerInfo[playerid][pMoney] += amnount; // Gives playerid money
// OR
PlayerInfo[playerid][pMoney] -= amnount; // Takes playerid money

Add this under OnPlayerUpdate.
pawn Код:
if(PlayerInfo[playerid][pMoney] != GetPlayerMoney(playerid))
{
    SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
}



Re: Server Sided Money - Hiddos - 11.08.2010

pawn Код:
stock GiveServerMoney(playerid, amount)
{
  SetPVarInt(playerid, "Money", GetPVarInt(playerid, "Money") + amount);
  SetPlayerMoney(playerid, GetPlayerMoney(playerid) + amount);
}

stock SetServerMoney(playerid, amount)
{
  SetPVarInt(playerid, "Money",  amount);
  SetPlayerMoney(playerid, amount);
}

stock ResetServerMoney(playerid)
{
  ResetPlayerMoney(playerid);
  SetPVarInt(playerid, "Money", 0);
}

stock GetServerMoney(playerid)
{
  return GetPVarInt(playerid, "Money"); // To compare with client side money
}
Edit to dudit: Setting a variable won't increase his money, neither is it efficient to use OnPlayerUpdate for checking money.


Re: Server Sided Money - Dudits - 11.08.2010

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
pawn Код:
stock GiveServerMoney(playerid, amount)
{
  SetPVarInt(playerid, "Money", GetPVarInt(playerid, "Money") + amount);
  SetPlayerMoney(playerid, GetPlayerMoney(playerid) + amount);
}

stock SetServerMoney(playerid, amount)
{
  SetPVarInt(playerid, "Money",  amount);
  SetPlayerMoney(playerid, amount);
}

stock ResetServerMoney(playerid)
{
  ResetPlayerMoney(playerid);
  SetPVarInt(playerid, "Money", 0);
}

stock GetServerMoney(playerid)
{
  return GetPVarInt(playerid, "Money"); // To compare with client side money
}
Edit to dudit: Setting a variable won't increase his money, neither is it efficient to use OnPlayerUpdate for checking money.
It is and I'm using it for my server.
It's MUCH easier to be understood too.

As I said, he just has to increase the amount instead of GivePlayerMoney.


Re: Server Sided Money - Hiddos - 11.08.2010

Quote:
Originally Posted by Dudits
Посмотреть сообщение
It is and I'm using it for my server.
It's MUCH easier to be understood too.

As I said, he just has to increase the amount instead of GivePlayerMoney.
Then his money won't increase, only the variable that contains his server money.


Re: Server Sided Money - Dudits - 12.08.2010

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
Then his money won't increase, only the variable that contains his server money.
This is why we have this on "OnPlayerUpdate"
pawn Код:
if(PlayerInfo[playerid][pMoney] != GetPlayerMoney(playerid))
{
    SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
}



Re: Server Sided Money - 0ne - 12.08.2010

there is a tutorial for it, why won't anyone search for god sake.


Re: Server Sided Money - Hiddos - 12.08.2010

Quote:
Originally Posted by Dudits
Посмотреть сообщение
This is why we have this on "OnPlayerUpdate"
pawn Код:
if(PlayerInfo[playerid][pMoney] != GetPlayerMoney(playerid))
{
    SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
}
How about you don't need OnPlayerUpdate, just check his clientside money with his serverside money whenever he makes a transaction or leaves the server. No useless coding needed when there is no possible harm. Also, OnPlayerUpdate is called around 20 times a second when a player moves, and isn't called when someone is AFK. Checking that much a second isn't necessary.


Re: Server Sided Money - Dudits - 12.08.2010

Ugghhhh what Calgon said.