How to set a variable to GetPlayerMoney?
#1

I'm trying to make
pawn Код:
pInfo[playerid][pCash];
equal to
pawn Код:
GetPlayerMoney(playerid);
No matter what pInfo[playerid]pCash] is always equivalent to Zero.
This is my code.
pawn Код:
public OnPlayerConnect(playerid)
{
    pInfo[playerid][pCash] += GetPlayerMoney(playerid);
    return 1;
}
What is the problem?
+rep
Reply
#2

OnPlayerConnect() happens when a player comes online, in this case he has no money, so GetPlayerMoney() returns 0.
Reply
#3

Can't you just use GetPlayerMoney? Make the cash load from your dini/mysql/ or w/e you have, a example of dini,
pawn Код:
GivePlayerMoney(playerid,dini_Int(file,"Cash"));
when player disconnect just make the cash will save from whatever you have
pawn Код:
dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
i think i made a mistake because i never used dini in a while
Reply
#4

Hmm, wouldn't you want to do it the other way around...SetPlayerMoney(playerid, pInfo[playerid][pCash]);?
Reply
#5

Firstly, there really is no reason to ever need that variable if it is ALWAYS going to be equivalent to GetPlayerMoney, you could just use the function. However, since you would want it to be constantly updated, you would need to either put it under OnPlayerUpdate, or use it along with the GivePlayerMoney function.
pawn Код:
public OnPlayerUpdate(playerid)
{
   pInfo[playerid][pCash] = GetPlayerMoney(playerid);
   return 1;
}
Reply
#6

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Hmm, wouldn't you want to do it the other way around...SetPlayerMoney(playerid, pInfo[playerid][pCash]);?
There is SetPlayerMoney? I am sure there is not, i only know there is
ResetPlayerMoney
GetPlayerMoney
GivePlayerMoney
Reply
#7

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
There is SetPlayerMoney? I am sure there is not, i only know there is
ResetPlayerMoney
GetPlayerMoney
GivePlayerMoney
Right, wasn't thinkin of it lol


Now there is :P


pawn Код:
stock SetPlayerMoney(playerid, var)
{
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid, var);
}
Reply
#8

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
Can't you just use GetPlayerMoney? Make the cash load from your dini/mysql/ or w/e you have, a example of dini,
pawn Код:
GivePlayerMoney(playerid,dini_Int(file,"Cash"));
when player disconnect just make the cash will save from whatever you have
pawn Код:
dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
i think i made a mistake because i never used dini in a while
The reason I'm not doing that is because I haven't learned how to save/load RP stats using YSI yet. I'm just using this as a substitution until I do learn how.
Reply
#9

Save the money either on "OnPlayerDisconnect" or at some sort of time intervals..
Reply
#10

Agree with iPLEOMAX, maybe you should save it on OnPlayerDeath().
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)