Y_INI: Can i get how much is the player's money while he's offline?
#9

Don't use a players actual cash variable. You are going to store an offline players cash in that variable, which means your money will be replaced with the offline players money. Use an unused variable or new variable, do not use one that you use regularly. The '{0, ...}' just sets the default value to 0 for all elements when created.
pawn Code:
format(string), sizeof(string), "JCNR/Users/%s.ini", name);
Formats a string to store the file path to the offline players user file.

pawn Code:
if(!fexist(string))
If users file does not exist...

pawn Code:
INI_ParseFile(string, "LoadUser_%s", .bExtra = true, .extra = playerid);
Call the function LoadUser and load all tags. You use the tag 'UserData', so our public function must be LoadUser_UserData.

pawn Code:
INI_Int("Cash", NewVar[playerid]);
Load the cash value and save it to NewVar[playerid] where playerid is the person who typed the command. Because we passed playerid through INI_ParseFile. We only use playerid because that variable is assigned to the admin, and assures us that it's value will not change between loading and using th variable. And no it won't load the admins money, because we passed 'strong' through parsefile, which is the offline players file... Not the admins file...

pawn Code:
INI_WriteInt(File, "Cash", NewVar[playerid] + money);
NewVar now contains the offline players cash, so if we add money into it, we get the total value that the offline players cash should now be. Then you just issue that new value into the offline players account...

It's really very simple. Hopefully I don't need to explain this again, on my phone, at work.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)