yini loading / reading string
#1

I just can't figure out how to load string from file.. /makewanted doesn't save reason I write, and /wanted ofc isn't showing nothing it shows only "your crimes: 0" ...
So far I did this:

pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_String("Crimes",PlayerInfo[playerid][pCrimes],24);
    return 1;
}
pawn Код:
CMD:makewanted(playerid,params[])
{
    new id, reason[80], string[50];
    PlayerInfo[playerid][pCrimes] = reason[70];
    //strmid(PlayerInfo[playerid][Crime], reason, 0, strlen(reason), 255);
    if(sscanf(params, "us[80]",id ,reason)) return SendClientMessage(playerid,-1,"USAGE: /report <PlayerID/Part of Name> <Reason>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Player Not connected");
   
    new INI:File = INI_Open(UserPath(playerid));
    INI_WriteString(File,"Crimes",PlayerInfo[playerid][pCrimes]);
    INI_Close(File);
   
    format(string, sizeof(string), "Crime %s saved", reason);
    SendClientMessage(playerid, -1, string);
    return 1;
}

CMD:wanted(playerid,params[])
{
    new string[128];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,24);
    new INI:File = INI_Open(UserPath(playerid));
    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
    //INI_WriteString(File,"Crimes",PlayerInfo[playerid][pCrimes]);
    format(string, sizeof(string), "Your current crimes: %s", PlayerInfo[playerid][pCrimes]);
    SendClientMessage(playerid, -1, string);
    //INI_WriteString(File,"Crimes",string);
    INI_Close(File);
    return 1;
}
Reply
#2

maybe will be help you , idk what you want, :v

pawn Код:
CMD:makecrime(playerid,params[])
{
    new reason[56],string[128];
    if(sscanf(params,"s[128]"reason)) return SendClientMessage(playerid, -1, "/makecrime [The Crime]");
   
    format(PlayerInfo[playerid][pCrimes], 128, reason);
    format(string,sizeof(string), "Crime %s", reason);
    SendClientMessage(playerid, -1, string)
    return 1;
}
CMD:mycrime(playerid)
{
    new string[128];
    format(string,sizeof(string), "Current my Crime is: %s", PlayerInfo[playerid][pCrimes]);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply
#3

Well this is working somehow but I need to save those crimes when player will login with his account it will load his crimes? It's for roleplay server I want to save player's crimes and than load it via /showcrime or whatever... I'm struggling for about 3 days to make that, so if anyone but really anyone can help me with this it's more than welcome!
Reply
#4

show your saving system please
Reply
#5

It's from tutorial from one guy I added only that "pCrimes" crap to test it it so far I can't figure out on my own :S

pawn Код:
#define PATH "/Users/%s.ini"
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pCrimes[24]
}
new PlayerInfo[MAX_PLAYERS][pInfo];
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_String("Crimes",PlayerInfo[playerid][pCrimes],24);
    return 1;
}
pawn Код:
UserPath(playerid)
{
    new str[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));

    for(new d,len = strlen(name); d != len; d++)
        name[d] = tolower(name[d]);

    format(str,sizeof(str),PATH,name);
    return str;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteString(File, "Crimes", PlayerInfo[playerid][pCrimes]);
    INI_Close(File);
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                //INI_WriteInt(File,"Crimes",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
        case DIALOG_TEXT:
        {
            new string[256];
            if(!response) return 1;
            if(response)
            {
                format(string, sizeof(string), "%s", inputtext);
                SendClientMessage(playerid,-1,string);
            }
        }
    }
    return 1;
}
Reply
#6

Try this:

Код:
//here you set on crime playerid,how i see in this cmd you set wanted level for id
CMD:makewanted(playerid,params[])
{
	new id, reason[80], string[50];
    if(sscanf(params, "us[80]",id ,reason)) return SendClientMessage(playerid,-1,"USAGE: /report <PlayerID/Part of Name> <Reason>");
   	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Player Not connected");
   	format(PlayerInfo[id][pCrimes], 80, reason);
    new INI:File = INI_Open(UserPath(id));
    INI_WriteString(File,"Crimes",PlayerInfo[id][pCrimes]);
    INI_Close(File);
    
    format(string, sizeof(string), "Crime %s saved", reason);
    SendClientMessage(playerid, -1, string);
	return 1;
}

//if you load player when he connect,you dont need to load him again in this command
CMD:wanted(playerid,params[])
{
	new string[128];
	format(string, sizeof(string), "Your current crimes: %s", PlayerInfo[playerid][pCrimes]);
	SendClientMessage(playerid, -1, string);
	return 1;
}
Reply
#7

So far this is working as I wanted, but it doesn't save crime reason into file I mean my file is:

pawn Код:
[data]
Password = 208667266
Cash = 0
Admin = 0
Kills = 0
Deaths = 0
Is this fine or how is this saving system working right now ?
Reply
#8

hmm try this cmd then:

Код:
CMD:makewanted(playerid,params[])
{
	new id, reason[80], string[50];
    if(sscanf(params, "us[80]",id ,reason)) return SendClientMessage(playerid,-1,"USAGE: /report <PlayerID/Part of Name> <Reason>");
   	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Player Not connected");
   	format(PlayerInfo[id][pCrimes], 80, reason);
    new INI:File = INI_Open(UserPath(id));
    INI_SetTag(File,"data");
    INI_WriteString(File,"Crimes",PlayerInfo[id][pCrimes]);
    INI_Close(File);
    format(string, sizeof(string), "Crime %s saved", reason);
    SendClientMessage(playerid, -1, string);
	return 1;
}
Reply
#9

well this is working do you maybe know how can I make that if I will write /makewanted it won't rewrite current crime but it will add another crime to person, rep+ for you both.
Reply
#10

Well, make 3 or more fields, depending on how many recent crimes you want to save. It's how you would do it in a database, and files are no different. Why save everything into a "big ass" string?
Simply add like pCrime# to your enumerator and the enumerator and file structure should look like:
Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pCrime1[24],
    pCrime2[24],
    pCrime3[24]
    // more if you want
}
new PlayerInfo[MAX_PLAYERS][pInfo];


[data]
Password = 208667266
Cash = 0
Admin = 0
Kills = 0
Deaths = 0
Crime1 = N/A
Crime2 = N/A
Crime3 = N/A
You should save and read Crime# as a string. I feel you're competent enough to script that on your own.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)