Server Sided Money
#1

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).
Reply
#2

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]);
}
Reply
#3

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.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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]);
}
Reply
#7

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

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.
Reply
#9

Ugghhhh what Calgon said.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)