Simple functions doubles the amount.
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
pawn Код:
stock Hook_GivePlayerMoney(playerid, amount)
{
    Account[playerid][PocketMoney] += amount;

    ResetPlayerMoney(playerid);
    return GivePlayerMoney(playerid, Account[playerid][PocketMoney]);
}

#if defined _ALS_GivePlayerMoney
    #undef GivePlayerMoney
#else
    #define _ALS_GivePlayerMoney
#endif

#define GivePlayerMoney Hook_GivePlayerMoney

stock SetPlayerMoney(playerid, amount)
{
    Account[playerid][PocketMoney] = amount;

    ResetPlayerMoney(playerid);
    return GivePlayerMoney(playerid, amount);
}
There's no need for any "Ex" functions. Put the hook in your script before it is used anywhere.

Use "SetPlayerMoney" when a player logs in and use "GivePlayerMoney" everywhere else.

P.S. There are 3 LSL CNR servers now? Seriously?

And so much CNR edits this year...
Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
PHP код:
stock GivePlayerMoneyEx(playeridamount)
{
    
Account[playerid][PocketMoney] += amount;
        
ResetPlayerMoney(playerid); // You just missed this
    
GivePlayerMoney(playeridAccount[playerid][PocketMoney]);
    return 
true;

You only needed to add ResetPlayerMoney first.

If you had 5000, and add 1000 to it, your server-var "PocketMoney" will hold 6000.
But since your client already has 5000, you'll be adding the 6000 to it, and you'll end up with 11000 while the server only holds 6000.

You need to reset the client money to 0 first, then send the new amount.
May I ask why you guys both decide to go for an extra function while that's not needed at all? It might not make a huge difference in performance in this case but it will when you for example do it in a really fast timer or what ever, you should always try to optimize your code as good as you can.

In this case he shouldn't use 'ResetPlayerMoney(playerid)' but simply 'GivePlayerMoney(playerid, amount)', his code was optimized and perfectly fine.

Best regards,
Jesse
Reply


Messages In This Thread
Simple functions doubles the amount. - by CrazyChoco - 27.12.2015, 16:53
Re: Simple functions doubles the amount. - by SecretBoss - 27.12.2015, 17:03
Re: Simple functions doubles the amount. - by SickAttack - 27.12.2015, 17:06
Re: Simple functions doubles the amount. - by CrazyChoco - 27.12.2015, 18:16
Re: Simple functions doubles the amount. - by AmigaBlizzard - 27.12.2015, 23:24
Re: Simple functions doubles the amount. - by SickAttack - 28.12.2015, 00:52
Re: Simple functions doubles the amount. - by jessejanssen - 28.12.2015, 02:23
Re: Simple functions doubles the amount. - by SickAttack - 28.12.2015, 03:04
Re: Simple functions doubles the amount. - by AmigaBlizzard - 05.01.2016, 19:39

Forum Jump:


Users browsing this thread: 1 Guest(s)