Question [+REP]
#1

Hello again,

I am just trying to add a textdraw when a player gets money, I have already made the textdraw but I don't know how can I detect that player's money changed and to put there my code
Reply
#2

Make a players variable (array) and update the array with money changes like
PHP код:
new Money[MAX_PLAYERS];
//Any where of script
GivePlayerMoney(playerid50000);
Money[playerid] += 50000
//OnPlayerUpdate
if(GetPlayerMoney(playerid) > Money[playerid])
{
      
//your code here
      
Money[playerid] = GetPlayerMoney(playerid); /// << To avoid spamming if you will send messages or w/e

Reply
#3

Why you put that?

Код:
GivePlayerMoney(playerid, 50000);
Money[playerid] += 50000
Reply
#4

You can find some info in here https://sampforum.blast.hk/showthread.php?tid=324939
Reply
#5

Quote:
Originally Posted by TheSnaKe
Посмотреть сообщение
I am not so noob, the textdraw will say how much money the player got
Reply
#6

Quote:
Originally Posted by SecretBoss
Посмотреть сообщение
Why you put that?

Код:
GivePlayerMoney(playerid, 50000);
Money[playerid] += 50000
Hmm, Because if player money variable isn't updated, it will show the textdraw everytime he gets cash from admin command / reaction tests / or any server side cash source, Sorry i thought you need only to check if money updated in client only, If you need it to show everytime money update from client / server, just don't use it while giving cash
Also i didn't meant to put it exactly
I mean, update the variable everytime you give the player cash
Reply
#7

Quote:
Originally Posted by karemmahmed22
Посмотреть сообщение
Hmm, Because if player money variable isn't updated, it will show the textdraw everytime he gets cash from admin command / reaction tests / or any server side cash source, Sorry i thought you need only to check if money updated in client only, If you need it to show everytime money update from client / server, just don't use it while giving cash
Also i didn't meant to put it exactly
I mean, update the variable everytime you give the player cash
Look, the textdraw will say to player how much money he got for ex. +1000$ and it will hide after 5 sec I made the code but I don't know how to detect if money changed
Reply
#8

Ok, Now Put the array (variable) on top of your script under your defines / variables,
And OnPlayerUpdate:-
PHP код:
if(GetPlayerMoney(playerid) > Money[playerid])
{
      new 
IncreasedAmount GetPlayerMoney(playerid) - Money[playerid];
      
// your code.
      
Money[playerid] = GetPlayerMoney(playerid); // this to update the variable with the current cash so, it does the same again after cash gets increased again..

Edit: OnPlayerDisconnect
PHP код:
Money[playerid] = 0
To reset the array
For decreased cash;
OnPlayerConnect:-
PHP код:
Money[playerid] = PlayerInfo[playerid][pMoney]; // Change to your saved cash for player, if theres no, remove it. 
PHP код:
if(GetPlayerMoney(playerid) < Money[playerid])
{
      new 
DecreasedAmount =  Money[playerid] - GetPlayerMoney(playerid);
      
// your code.
      
Money[playerid] = GetPlayerMoney(playerid// this to update the variable with the current cash so, it does the same again after cash gets increased again..

Reply
#9

Quote:
Originally Posted by karemmahmed22
Посмотреть сообщение
Ok, Now Put the array (variable) on top of your script under your defines / variables,
And OnPlayerUpdate:-
PHP код:
if(GetPlayerMoney(playerid) > Money[playerid])
{
      new 
IncreasedAmount GetPlayerMoney(playerid) - Money[playerid];
      
// your code.
      
Money[playerid] = GetPlayerMoney(playerid// this to update the variable with the current cash so, it does the same again after cash gets increased again..

Edit: OnPlayerConnect
PHP код:
Money[playerid] = 0
To reset the array
Yea but this can't detect if the player has gain or lost money for example if the player got money I will put + increasedamount$ or if lost -increasedamount$
Код:
Money[playerid] += 50000
This will mean that will send the message if the player has 50k+, so can I only put new Money[playerid]?

- EDIT -
I didn't see the edit, sorry gotta test it
Reply
#10

Hmmm, No.. It just will update the variable with changes,
Lemme explain how it works
the variable 'Money' contains the player money it gets updated on OnPlayerConnect by player's cash (see the edit again)
in OnPlayerUpdate, The script checks if theres cash changes, ('Money' variable wont be changed unless the player gained cash) It will check if GetPlayerMoney(id) (The player cash in client) > Money[id] (The variable in server)
So it will set the variable to the new cash (if you didn't that, it will spam the text draw) and it gets the Increased/decreased cash and storing on IncreasedAmount / DecreasedAmount variables
You have to just update the textdraw with the Amount..
I hope i explained you

Edit:
Sorry, i typed it wrong in forums
PHP код:
Money[playerid] = PlayerInfo[playerid][pMoney]; 
instead of
PHP код:
Money[playerid] = PlayerInfo[playerid][pMoney
missed; :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)