24.12.2014, 13:23
Basically, you need to load the user's current cash which can be achieved by using INI_ParseFile. You will then need to save this value to a new variable, which we will define at the top of the script. Feel free to change the name of the variable.
Then, when you want to refund cash, check if the player exists first...
Then get ready to load the cash to a variable assigned to the admin/playerid doing the refund.
It will call the following function:
The current value of 'Cash' will be saved to the variable 'AdminCashRefund[playerid]', where 'playerid' is the ID of the admin doing the refund.
Then you can process the refund...
So your final code would look like...
I've put it in a command called 'refund' just for exemplary purposes.
pawn Code:
new AdminCashRefund[MAX_PLAYERS] = {0, ...}; //At the top of your script
pawn Code:
format(string, sizeof(string), "/JCNR/Users/%s.ini", HouseInfo[h][HouseOwner]); //Format the path
if(!fexist(string)) return SendClientMessage(playerid, -1, "Player does not exist."); //If the user doesn't exist...
pawn Code:
INI_ParseFile(string, "RefundUser_%s", .bExtra = true, .extra = playerid);
pawn Code:
forward RefundUser_UserData(playerid, name[], value[]);
public RefundUser_UserData(playerid, name[], value[])
{
INI_Int("Cash", AdminCashRefund[playerid]);
return 1;
}
Then you can process the refund...
pawn Code:
new INI:File = INI_Open(string);
INI_SetTag(File, "UserData");
INI_WriteInt(File, "Cash", AdminCashRefund[playerid] + Refund);
INI_Close(File);
pawn Code:
new AdminCashRefund[MAX_PLAYERS] = {0, ...};
CMD:refund(playerid, params[])
{
//Stuff should be here...
format(string, sizeof(string), "/JCNR/Users/%s.ini", HouseInfo[h][HouseOwner]);
if(!fexist(string)) return SendClientMessage(playerid, -1, "Player does not exist.");
INI_ParseFile(string, "RefundUser_%s", .bExtra = true, .extra = playerid);
new INI:File = INI_Open(string);
INI_SetTag(File, "UserData");
INI_WriteInt(File, "Cash", AdminCashRefund[playerid] + Refund);
INI_Close(File);
return 1;
}
forward RefundUser_UserData(playerid, name[], value[]);
public RefundUser_UserData(playerid, name[], value[])
{
INI_Int("Cash", AdminCashRefund[playerid]);
return 1;
}