SA-MP Forums Archive
YSI\y_ini Save System help - 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: YSI\y_ini Save System help (/showthread.php?tid=455855)



YSI\y_ini Save System help - wind0wS_8 - 03.08.2013

Code:
#include <a_samp>
#include <YSI\y_ini>

//DIALOG DEFINITIONS
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4

//Saving path definition

#define PATH "Users/%s.ini"

//Colors
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"

main()
{
        print("\n----------------------------------");
        print(" Registration System is loaded 100% :P");
        print("----------------------------------\n");
}

enum pInfo
{
	pPass,
	pLevel,
	pKills,
	pDeaths,
	pScore,
	pCash,
	pIP,
	pBanned,
	pHours,
	pMinutes,
	pSeconds
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Level",PlayerInfo[playerid][pLevel]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Score",PlayerInfo[playerid][pScore]);
    INI_Int("IP",PlayerInfo[playerid][pIP]);
    INI_Int("Banned",PlayerInfo[playerid][pBanned]);
    INI_Int("Hour",PlayerInfo[playerid][pHours]);
    INI_Int("Minutes",PlayerInfo[playerid][pMinutes]);
    INI_Int("Seconds",PlayerInfo[playerid][pSeconds]);
    return 1;
}

stock UserPath(playerid)
{
	new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"PlayerData");
    INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Score",PlayerInfo[playerid][pScore]);
    INI_WriteInt(File,"IP",PlayerInfo[playerid][pIP]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File,"Hour",PlayerInfo[playerid][pHours]);
    INI_WriteInt(File,"Minutes",PlayerInfo[playerid][pMinutes]);
    INI_WriteInt(File,"Seconds",PlayerInfo[playerid][pSeconds]);
    INI_Close(File);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}

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_PASSWORD, "Regester Failed!", "{}You have entered an {}invalid password.\n\n{}Enter a {}Password {}below to {}Register {}this account.", "Register", "Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"PlayerData");
                INI_WriteString(File,"Password",inputtext);
                INI_WriteInt(File,"Level",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Score",0);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"IP",0);
                INI_WriteInt(File,"Banned",0);
                INI_WriteInt(File,"Hour",0);
                INI_WriteInt(File,"Minutes",0);
                INI_WriteInt(File,"Seconds",0);
                INI_Close(File);
				ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX, "Account Created", "{}You Account: {}%s {}has been {}Registed!\n\n {}Your {}Password is: {}%s {}[And has been {}hashed!{}]\n\n{}Don't {}forget {}or {}share {}your {}Password!", "Ok", "");
            	INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
                GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
             }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(strcmp(inputtext, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
                    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_PASSWORD, "Login", "You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
        return 1;
}
it save the .ini file but does not edit it.... the inside (Kills= ; Deaths = ; Score = ; Cash =).....
can someone please tell me my mistake,


Re: YSI\y_ini Save System help - wind0wS_8 - 03.08.2013

please guys help me


Re: YSI\y_ini Save System help - Ayumi - 03.08.2013

Could you debug it for me please?


Re: YSI\y_ini Save System help - wind0wS_8 - 03.08.2013

Quote:
Originally Posted by Ayumi
View Post
Could you debug it for me please?
im looking for help