How to write in to another players INI file -
Spikmun - 11.05.2013
Okay so each user who registers to my server has an INI file where I store all of their data such as there cash, weapons etc so that when they log back in they still have all this stuff (pretty basic I know). I understand how to write into the playerid's INI file but how do I write into another players INI file that isn't the playerid.
For example I want to make a set hit command so I'll
start it like this (I'm using ZCMD and sscanf)
Код:
CMD:sethit(playerid, params[])
{
new receiver, amount;
if (!sscanf(params, "ii", receiver, amount)
{
new INI:File = INI_Open(UserPath(playerid));
INI_WriteInt(File,"Hit",amount);
INI_Close(File);
}
}
But this would write into the player who typed the commands INI file instead of the targets INI file. So where do I put the "receiver" variable so that I can make it write to the receivers file? Do I replace the UserPath(playerid) with UserPath(receiver) or how does it work?
Help will be much appreciated! Thanks in advance.
Re: How to write in to another players INI file -
Frede - 11.05.2013
Код:
CMD:sethit(playerid, params[])
{
new receiver, amount;
if (!sscanf(params, "ii", receiver, amount)
{
new INI:File = INI_Open(UserPath(receiver));
INI_WriteInt(File,"Hit",amount);
INI_Close(File);
}
}
Re: How to write in to another players INI file -
Spikmun - 11.05.2013
Quote:
Originally Posted by Frede
Код:
CMD:sethit(playerid, params[])
{
new receiver, amount;
if (!sscanf(params, "ii", receiver, amount)
{
new INI:File = INI_Open(UserPath(receiver));
INI_WriteInt(File,"Hit",amount);
INI_Close(File);
}
}
|
For some reason when I do this the players file looks like
Код:
Hit = 100
[data]
Password =
Cash = 200
Admin = 2
Kills = 52
Deaths = 31
Weapon0 = 0
Ammo0 = 0
Weapon1 = 0
Ammo1 = 0
Weapon2 = 0
Ammo2 = 0
Weapon3 = 0
Ammo3 = 0
Weapon4 = 0
Ammo4 = 0
Weapon5 = 0
Ammo5 = 0
Weapon6 = 0
Ammo6 = 0
Weapon7 = 0
Ammo7 = 0
Weapon8 = 0
Ammo8 = 0
Weapon9 = 0
Ammo9 = 0
Weapon10 = 0
Ammo10 = 0
Weapon11 = 0
Ammo11 = 0
Weapon12 = 0
Ammo12 = 0
Bank = 0
Hit = 0
It doesn't change the Hit it just makes a new one on top that is never used and doesn't work :S
Re: How to write in to another players INI file -
JJB562 - 12.05.2013
How about this?
pawn Код:
CMD:sethit(playerid, params[])
{
new receiver, amount;
if (!sscanf(params, "ii", receiver, amount)
{
new INI:File = INI_Open(UserPath(receiver));
INI_WriteInt(File,"Hit",amount);
INI_Close(File);
}
}
Re: How to write in to another players INI file -
Chenko - 12.05.2013
This is how it should be, I've explained everything with comments.
PHP код:
CMD:sethit(playerid, params[])
{
new receiver, amount;
if (!sscanf(params, "ui", receiver, amount) //You want to use "u" instead of "i" because that is the sscanf specifier for playerid
{
if(!IsPlayerConnected(receiver)) //Making sure the player is connected.
return SendClientMessage(playerid, -1, "That player isn't connected!");
new INI:File = INI_Open(UserPath(receiver)); //Getting the userpath of the playerid that sscanf got
INI_SetTag(File, "data"); //Setting the tag so it goes underneath data and not above.
INI_WriteInt(File,"Hit",amount);
INI_Close(File);
}
}
Re: How to write in to another players INI file -
Spikmun - 12.05.2013
Quote:
Originally Posted by Chenko
This is how it should be, I've explained everything with comments.
PHP код:
CMD:sethit(playerid, params[])
{
new receiver, amount;
if (!sscanf(params, "ui", receiver, amount) //You want to use "u" instead of "i" because that is the sscanf specifier for playerid
{
if(!IsPlayerConnected(receiver)) //Making sure the player is connected.
return SendClientMessage(playerid, -1, "That player isn't connected!");
new INI:File = INI_Open(UserPath(receiver)); //Getting the userpath of the playerid that sscanf got
INI_SetTag(File, "data"); //Setting the tag so it goes underneath data and not above.
INI_WriteInt(File,"Hit",amount);
INI_Close(File);
}
}
|
Hey, thanks the comments were helpful but now when I use the /sethit command the players Hit is not changed in their file. I use the command, then check the players file but Hit = 0 instead of the value I put in the command.