How To Read Something From an Offline User's Account in YINI? -
gtakillerIV - 19.10.2012
Hey guys as the title says, how can I make something like that? I tried it and this is the result:
PHP код:
CMD:getmoney(playerid,params[])
{
new filestring[55], aname[128];
if(sscanf(params,"s[128]", aname)) return SendClientMessage(playerid, Yellow, "Correct Usage: /getmoney [Player's Name]");
format(filestring,sizeof(filestring), "/Users/%s.ini", aname);
if(!fexist(filestring)) return SendClientMessage(playerid, Yellow, "That account doesn't exist!");
else
{
new cash; //As you see I made this to store the player's cash inside it.
//What Goes here?
new moneystr[40];
format(moneystr, sizeof(moneystr), "Player's Money : %i", cash);
SendClientMessage(playerid,Lime,moneystr);
}
return 1;
}
I read Yini's topic but I didin't understand on how to get something like the one I got above, thanks for reading.
Regards,
gtakillerIV.
Re: How To Read Something From an Offline User's Account in YINI? -
ReneG - 19.10.2012
this should work using sscanf
PHP код:
CMD:getmoney(playerid,params[])
{
new filestring[55], aname[MAX_PLAYER_NAME];
if(sscanf(params,"s[" #MAX_PLAYER_NAME "]", aname)) return SendClientMessage(playerid, Yellow, "Correct Usage: /getmoney [Player's Name]");
format(filestring,sizeof(filestring), "/Users/%s.ini", aname);
if(!fexist(filestring)) return SendClientMessage(playerid, Yellow, "That account doesn't exist!");
else
{
new
cash,
File:file = fopen(filestring, io_read),
string[40],
szIniName[20],
szValue[20];
while(fread(file, string))
{
if(!sscanf(string, "p<=>s[20]s[20]", szIniName, szValue))
{
if(!strcmp(szIniName, "Cash")) // change "Cash" to what it is labeled in your .ini files
{
cash = strval(szValue);
break;
}
}
}
new moneystr[40];
format(moneystr, sizeof(moneystr), "Player's Money : %i", cash);
SendClientMessage(playerid,Lime,moneystr);
}
return 1;
}
Re: How To Read Something From an Offline User's Account in YINI? -
gtakillerIV - 19.10.2012
Doesn't work, it says Unkown Command. Thanks for helping anyways
EDIT: I found out why, it was because OnPlayerCommandPerformed.
And
It works thanks
Now time to understand your code
EDIT 2:
Hmm the value is always 0.
Re: How To Read Something From an Offline User's Account in YINI? -
ReneG - 19.10.2012
Show me an example of one of your .ini files. I'll try explaining in comments
Re: How To Read Something From an Offline User's Account in YINI? -
gtakillerIV - 20.10.2012
Here:
[data]
Name = gtakillerIV
Password = D5D38E74A1E97B9EA0D79E49F2AEEAB95E91E205B4C4869750 40B48522006805AC83C2DDD0F7E8D3839DA92725C4B4BA8BC5 75AAEA5AB0919A303E84DC1DF8FC
Banned = 0
Cash = 900
Admin = 10
Vip = 3
Kills = 0
Score = 0
Ip = 127.0.0.1
Deaths = 0
Sorry for late reply.
One more thing I checked out the Server console when I typed the command, it says something like:
sscanf warning: String buffer overflow.
Re: How To Read Something From an Offline User's Account in YINI? -
Riddick94 - 20.10.2012
Change this one (You should know to what you need to, if you're using Y_Ini)
Код:
YourNameOfLoadingPlayerFiles
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include "YSI\y_ini"
CMD:getmoney(playerid, params[])
{
new AccountName[24], pName[MAX_PLAYER_NAME];
if(sscanf(params, "s[24]", AccountName))return SendClientMessage(playerid, -1, "Correct Usage: /getmoney [PlayerFile]");
{
new filename[64];
format(filename, sizeof(filename), "/Users/%s.ini", AccountName);
if(!fexist(filename))return SendClientMessage(playerid, -1, "That account doesn't exist!");
INI_ParseFile(filename, "YourNameOfLoadingPlayerFiles", .bExtra = true, .extra = playerid);
new giveplayerid = INVALID_PLAYER_ID;
for(new i = 0; i < GetMaxPlayers(); i++)
{
GetPlayerName(i, pName, sizeof(pName));
if(strcmp(pName, AccountName) == 0)
{
giveplayerid = i;
break;
}
}
new string[128];
format(string, sizeof(string), "Player's money from file %s is $%d", filename, GetPlayerMoney(giveplayerid));
SendClientMessage(playerid, -1, string);
}
return true;
}
edit://
You have used a bit of my code. For what?
Re: How To Read Something From an Offline User's Account in YINI? -
ReneG - 20.10.2012
Tested and works for me, you had to account for those extra spaces that y_ini inputs when writing files. Also, instead of using sscanf for one parameter, you can just use isnull()
PHP код:
CMD:getmoney(playerid, params[])
{
if(isnull(params)) {
return SendClientMessage(playerid, -1, "Correct Usage: /getmoney [PlayerFile]");
}
new filename[MAX_PLAYER_NAME+18];
format(filename, sizeof(filename), "/Users/%s.ini", params);
if(!fexist(filename)) {
return SendClientMessage(playerid, -1, "That account doesn't exist!");
}
new
File:file = fopen(filename, io_read),
string[128],
Name[20],
Value[20],
cash;
while(fread(file, string)) {
if(!sscanf(string, "p<=>s[20]s[20]", Name, Value)) {
if(!strcmp(Name, "Cash ")) {
cash = strval(Value);
break;
}
}
}
format(string, sizeof(string), "Money from %s's account is $%d", params, cash);
SendClientMessage(playerid, -1, string);
return true;
}
Ignore the sscanf buffer overflow for now, that was just caused by trying to load the password line, which is a ton of characters.