26.12.2014, 02:25
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.
Formats a string to store the file path to the offline players user file.
If users file does not exist...
Call the function LoadUser and load all tags. You use the tag 'UserData', so our public function must be LoadUser_UserData.
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...
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.
pawn Code:
format(string), sizeof(string), "JCNR/Users/%s.ini", name);
pawn Code:
if(!fexist(string))
pawn Code:
INI_ParseFile(string, "LoadUser_%s", .bExtra = true, .extra = playerid);
pawn Code:
INI_Int("Cash", NewVar[playerid]);
pawn Code:
INI_WriteInt(File, "Cash", NewVar[playerid] + money);
It's really very simple. Hopefully I don't need to explain this again, on my phone, at work.