y_ini saving help
#1

Hello, I am trying to make it save when the player quits the game, here is what I have:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new playname[MAX_PLAYER_NAME];
    new string[128];
    GetPlayerName(playerid, playname, sizeof(playname));
    format(string, sizeof(string), "%s.ini", playname);
    if(fexist(string))
    {
        new playerName[MAX_PLAYER_NAME];
        new userfile[128];
        new Float:pHealth, Float:pArmour;
        GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
        format(userfile, sizeof(userfile), "%s.ini", playerName);
        new INI:file = INI_Open(userfile);
        INI_SetTag(file, "Player Stats");
        INI_WriteInt(file, "Level", GetPlayerScore(playerid));
        INI_WriteInt(file, "Money", GetPlayerMoney(playerid));
        INI_WriteInt(file, "Health", GetPlayerHealth(playerid, pHealth));
        INI_WriteInt(file, "Armour", GetPlayerArmour(playerid, pArmour));
        INI_WriteInt(file, "Skin", GetPlayerSkin(playerid));
        INI_Close(file);
        return 1;
    }
    return 1;
}
Why isn't it saving the file? When I go to the scriptfiles folder, the playerfile is not there.
Reply
#2

why this need to spawn 2 times?
pawn Код:
format(string, sizeof(string), "%s.ini", playname);
//and
format(userfile, sizeof(userfile), "%s.ini", playerName);
those return doesnt need in fexist
Reply
#3

I removed it so now it is like this:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new playname[MAX_PLAYER_NAME];
    new userfile[128];
    new string[128];
    GetPlayerName(playerid, playname, sizeof(playname));
    format(string, sizeof(string), "%s.ini", playname);
    if(fexist(string))
    {
        new Float:pHealth, Float:pArmour;
        new INI:file = INI_Open(userfile);
        INI_SetTag(file, "Player Stats");
        INI_WriteInt(file, "Level", GetPlayerScore(playerid));
        INI_WriteInt(file, "Money", GetPlayerMoney(playerid));
        INI_WriteInt(file, "Health", GetPlayerHealth(playerid, pHealth));
        INI_WriteInt(file, "Armour", GetPlayerArmour(playerid, pArmour));
        INI_WriteInt(file, "Skin", GetPlayerSkin(playerid));
        INI_Close(file);
        return 1;
    }
    return 1;
}
Still it isnt creating and saving the file in the filterscripts folder
Reply
#4

try this

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new playname[MAX_PLAYER_NAME];
    new userfile[128];
    new string[128];
    GetPlayerName(playerid, playname, sizeof(playname));
    format(string, sizeof(string), "%s.ini", playname);
    if(fexist(string))
    {
        new Float:pHealth, Float:pArmour;
        new INI:file = INI_Open(string);
        INI_WriteInt(file, "Level", GetPlayerScore(playerid));
        INI_WriteInt(file, "Money", GetPlayerMoney(playerid));
        INI_WriteInt(file, "Health", GetPlayerHealth(playerid, pHealth));
        INI_WriteInt(file, "Armour", GetPlayerArmour(playerid, pArmour));
        INI_WriteInt(file, "Skin", GetPlayerSkin(playerid));
        INI_Close(file);
    }
    return 1;
}
EDIT: why this
pawn Код:
INI_WriteInt(file, "Level", GetPlayerScore(playerid));
used GetPlayerScore? xD use AccInfo [ playerid ] [ ENUM ] ;
Reply
#5

Yeah but im not so great with enums I dont know how to create them and I dont get what they do? I mean what does a enum that is pLevel do? How can I give it a value? Thanks
Reply
#6

sorry off topic

try this link it might help u for the enum management

How to create an Admin Filterscript
Reply
#7

But the actual .ini file wont even create do you see a problem that is causing that?
Reply
#8

Quote:
Originally Posted by Tommy_Mandaz
Посмотреть сообщение
But the actual .ini file wont even create do you see a problem that is causing that?
because the player dint register...
Reply
#9

Here is my registration:

pawn Код:
public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new playname[MAX_PLAYER_NAME];
    new string[128];
    GetPlayerName(playerid, playname, sizeof(playname));
    format(string, sizeof(string), "%s.ini", playname);
    if(!fexist(string))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "New Player Registration", "Please Type In Your Desired Password Below:", "Register", "Cancle");
    }
    else
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Player Login", "Please Type In Your Password Below:", "Login", "Cancle");
    }
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1) //Register
    {
        if(response)
        {
            if(strlen(inputtext) >= 50)
            {
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "New Player Registration", "Please Type In Your Desired Password Below:", "Register", "Cancle"); //Register
                SendClientMessage(playerid, 0xFFFFFFAA, "[SYSTEM]: Password is too long.");
                return 0;
            }
            else
            {
                if(!strlen(inputtext))
                {
                    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "New Player Registration", "Please Type In Your Desired Password Below:", "Register", "Cancle"); //Register
                    SendClientMessage(playerid, 0xFFFFFFAA, "[SYSTEM]: Please Type In A Password To Register!");
                    return 1;
                }
                new pregistername[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pregistername, sizeof(pregistername));
                new string[128];
                format(string, sizeof(string), "%s.ini", pregistername);
                if(fexist(string))
                {
                    SendClientMessage(playerid, 0xFFFFFFAA, "[SYSTEM]: The Name You Have Chosen Is Already Taken!");
                    return 1;
                }
                new tmppass[64];
                strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
                Encrypt(tmppass);
                OnPlayerRegister(playerid,tmppass);
            }
        }
        else
        {
            ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "New Player Registration", "Please Type In Your Desired Password Below:", "Register", "Cancle"); //Register
        }
    }
    if(dialogid == 2) //Login
    {
        if(response)
        {
            if(!strlen(inputtext))
            {
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Player Login", "Please Type In Your Password Below:", "Login", "Cancle"); //Login
                SendClientMessage(playerid, 0xFFFFFFAA, "[SYSTEM]: Please Type In A Password To Login!");
                return 1;
            }
            if(strlen(inputtext) >= 50)
            {
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Player Login", "Please Type In Your Password Below:", "Login", "Cancle"); //Login
                SendClientMessage(playerid, 0xFFFFFFAA, "[SYSTEM]: Password is too long.");
                return 0;
            }
            new tmppass[64];
            Encrypt(tmppass);
            OnPlayerLogin(playerid,tmppass);
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Player Login", "Please Type In Your Password Below:", "Login", "Cancle"); //Login
        }
    }
    return 1;
}
pawn Код:
public OnPlayerLogin(playerid,password[])
{
    gPlayerLogged[playerid] = 1;
    SetPlayerSkillLevel(playerid, WEAPONSKILL_SAWNOFF_SHOTGUN, 1);
    SetPlayerSkillLevel(playerid, WEAPONSKILL_MICRO_UZI, 1);
    SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL, 1);
    SetPlayerScore(playerid, GetPVarInt(playerid, "Level"));
    GivePlayerMoney(playerid, GetPVarInt(playerid, "Money"));
    SetPlayerSkin(playerid, GetPVarInt(playerid, "Skin"));
    SetPlayerHealth(playerid, GetPVarInt(playerid, "Health"));
    SetPlayerArmour(playerid, GetPVarInt(playerid, "Armour"));
    OnPlayerSpawn(playerid);
    return 1;
}

public OnPlayerRegister(playerid, password[])
{
    new playname[MAX_PLAYER_NAME];
    new string[128];
    GetPlayerName(playerid, playname, sizeof(playname));
    format(string, sizeof(string), "%s.ini", playname);
    if(fexist(string))
    {
        gPlayerLogged[playerid] = 1;
        new INI:file = INI_Open(string);
        INI_SetTag(file, "Player Stats");
        INI_WriteInt(file, "Level", 1);
        INI_WriteInt(file, "Money", 5000);
        INI_WriteInt(file, "Health", 100);
        INI_WriteInt(file, "Armour", 0);
        INI_Close(file);
        new tmppass[64];
        Encrypt(tmppass);
        OnPlayerLogin(playerid, tmppass);
    }
    return 1;
}
Still isnt saving
Reply
#10

idk what method u using..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)