How To Read Something From an Offline User's Account in YINI?
#1

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(playeridYellow"Correct Usage: /getmoney [Player's Name]");
    
format(filestring,sizeof(filestring), "/Users/%s.ini"aname);
    if(!
fexist(filestring)) return SendClientMessage(playeridYellow"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(moneystrsizeof(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.
Reply
#2

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(playeridYellow"That account doesn't exist!"); 
    else 
    { 
        new 
            
cash,
            
File:file fopen(filestringio_read),
            
string[40],
            
szIniName[20],
            
szValue[20];
            
        while(
fread(filestring)) 
        {
            if(!
sscanf(string"p<=>s[20]s[20]"szIniNameszValue)) 
            {
                if(!
strcmp(szIniName"Cash")) // change "Cash" to what it is labeled in your .ini files
                
{    
                    
cash strval(szValue);
                    break;
                }
            }
        }
        new 
moneystr[40]; 
        
format(moneystrsizeof(moneystr), "Player's Money : %i"cash); 
        
SendClientMessage(playerid,Lime,moneystr); 
    } 
    return 
1

Reply
#3

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.
Reply
#4

Show me an example of one of your .ini files. I'll try explaining in comments
Reply
#5

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.
Reply
#6

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?
Reply
#7

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(playeridparams[])
{
   
    if(
isnull(params)) {
        return 
SendClientMessage(playerid, -1"Correct Usage: /getmoney [PlayerFile]");
    }
    
    new 
filename[MAX_PLAYER_NAME+18];
    
format(filenamesizeof(filename), "/Users/%s.ini"params);
    
    if(!
fexist(filename)) {
        return 
SendClientMessage(playerid, -1"That account doesn't exist!");
    }
        
    new 
        
File:file fopen(filenameio_read),
        
string[128],
        
Name[20],
        
Value[20],
        
cash;
        
    while(
fread(filestring)) {
        if(!
sscanf(string"p<=>s[20]s[20]"NameValue)) {
            if(!
strcmp(Name"Cash ")) {
                
cash strval(Value);
                break;
            }
        }
    }
    
format(stringsizeof(string), "Money from %s's account is $%d"paramscash);
    
SendClientMessage(playerid, -1string);
    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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)