SA-MP Forums Archive
Problem With INI (+REP for helper) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem With INI (+REP for helper) (/showthread.php?tid=319477)



Problem With INI (+REP for helper) - Danyal - 19.02.2012

Register Dialog:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Red"Registering...",""WHITE"You have entered an "Red"Invalid Password.\n"WHITE"Type your "Red"Password "WHITE"below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                GetPlayerName(playerid,PlayerInfo[playerid][pUsername],MAX_PLAYER_NAME);
                INI_WriteString(File,"Username",PlayerInfo[playerid][pUsername]);
                INI_WriteInt(File,"Password",udb_hash(inputtext));
................................
Login Dialog:
pawn Код:
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]);
i have this on player register & login but the problem is that when ever a player joins into my server and leaves without registering the account is saved on the next time if other player puts the same name instead of register dialog login dialog is appeared please help me fix that


Re: Problem With INI (+REP for helper) - emokidx - 19.02.2012

show the OnPlayerDisconnect or where ever you save the players stats.


Re: Problem With INI (+REP for helper) - Danyal - 19.02.2012

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    SaveStats(playerid);
    return 1;
}

stock SaveStats(playerid)
{
    new string[320];
    format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    INI_WriteInt(File,"Bank",PlayerInfo[playerid][pBank]);
...................................



Re: Problem With INI (+REP for helper) - emokidx - 19.02.2012

just make a var to check if the player has registered/logged in

pawn Код:
new logged[MAX_PLAYERS]; //global var
pawn Код:
case DIALOG_REGISTER:
        {
 if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Red"Registering...",""WHITE"You have entered an "Red"Invalid Password.\n"WHITE"Type your "Red"Password "WHITE"below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                GetPlayerName(playerid,PlayerInfo[playerid][pUsername],MAX_PLAYER_NAME);
                INI_WriteString(File,"Username",PlayerInfo[playerid][pUsername]);
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                logged[playerid] = 1;
pawn Код:
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]);
                    logged[playerid] = 1;
then check On the savestats
pawn Код:
stock SaveStats(playerid)
{
    if (logged[playerid] ==1)
    {
        new string[320];
        format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    }
i think should work x:


Re: Problem With INI (+REP for helper) - L0zaix - 19.02.2012

it will work except this one

pawn Код:
stock SaveStats(playerid)
{
    if (logged[playerid] ==1)
    {
        new string[320];
        format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    }
you forget the brackets (})

this is the correct one

pawn Код:
stock SaveStats(playerid)
{
    if (logged[playerid] ==1)
    {
        new string[320];
        format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    }
}



Re: Problem With INI (+REP for helper) - Danyal - 19.02.2012

+REP FOR BOTH OF YOU