Loading system failing
#7

I tried to rewrite your code a little bit.Here's what I did:

PHP код:
#include <a_samp>
#include <YSI\y_ini>
#define DIALOG_REGISTER 2
#define DIALOG_LOGIN 3
#define DIALOG_SEX 4
#define VEHICLE_PATH "Vehicles/%s.ini"
#define USER_PATH "Players/%s.ini"
#define MAX_PLAYER_VEHICLES 3
enum CarInfo
{
    
pVehicle,
    
pVehicleModel,
    
Float:pVehicleX,
    
Float:pVehicleY,
    
Float:pVehicleZ,
    
Float:pVehicleC,
    
pVehicleColor1,
    
pVehicleColor2,
    
pVehicleValue,
    
pVehiclePlate[32],
    
pVehicleLock
}
new 
PlayerCars[MAX_PLAYERS][MAX_PLAYER_VEHICLES][CarInfo];
enum pInfo
{
    
pPass,
    
pAdmin,
    
Faccion,
    
Rango,
    
Payday,
    
Respeto,
    
Nivel,
    
pAccent,
    
Sexo,
    
Edad,
    
Skin,
    
Cartera,
    
Float:pPos_x,
    
Float:pPos_y,
    
Float:pPos_z
};
new 
PlayerInfo[MAX_PLAYERS][pInfo];
public 
OnPlayerConnect(playerid)
{
    if(
fexist(UserPath(playerid)))
    {
        new 
string[128];
        
format(stringsizeof(string), "{FFFFFF}Welcome {00CF00}%s{FFFFFF}. \nEnter your password below:"RPName(playerid));
        
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
        
INI_ParseFile(UserCars(playerid), "LoadCars_%s", .bExtra true, .extra playerid);
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Server - Login"string"Login""Exit");
    }
    else
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Server - Register","Enter a new password to create a new account:""Register""Exit");
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_REGISTER:
        {
            if(!
response)
                return 
Kick(playerid);
            else
            {
                if(!
strlen(inputtext))
                    return 
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Registering...","You've entered an invalid password.\nEnter a new password to create a new account.","Register","Exit");
                
PlayerInfo[playerid][pPass] = udb_hash(inputtext);
                
/*
                Code to init your variables like:
                PlayerInfo[playerid][Admin] = 0;
                Just if it's needed
                */
                
SaveAccountStats(playerid); //Saves the stats from pInfo enum
                
SaveAccountCars(playerid); //Saves the account's cars stats from CarInfo enum
                
ShowPlayerDialog(playeridDIALOG_SEXDIALOG_STYLE_MSGBOX"- Sex -","Put your gender","Male","Female");
            }
        }
    }
    return 
1;
}
//Save Functions
stock SaveAccountStats(playerid)
{
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File"data");
    
    
GetPlayerPos(playeridPlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
    
PlayerInfo[playerid][Cartera] = GetPlayerMoney(playerid);
    
PlayerInfo[playerid][Skin] = GetPlayerSkin(playerid);
    
    
INI_WriteInt(File,"Password"udb_hash(PlayerInfo[playerid][pPass]));
    
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File,"Faccion",PlayerInfo[playerid][Faccion]);
    
INI_WriteInt(File,"Rango",PlayerInfo[playerid][Rango]);
    
INI_WriteInt(File,"Payday",PlayerInfo[playerid][Payday]);
    
INI_WriteInt(File,"Respeto",PlayerInfo[playerid][Respeto]);
    
INI_WriteInt(File,"Nivel",PlayerInfo[playerid][Nivel]);
    
INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]);
    
INI_WriteInt(File,"Sexo",PlayerInfo[playerid][Sexo]);
    
INI_WriteInt(File,"Edad",PlayerInfo[playerid][Edad]);
    
INI_WriteInt(File,"Skin",PlayerInfo[playerid][Skin]);
    
INI_WriteInt(File,"Cartera",PlayerInfo[playerid][Cartera]);
    
    
INI_Close(File);
}
stock SaveAccountCars(playerid)
{
    new 
INI:File INI_Open(UserCars(playerid));
    
INI_SetTag(File"Vehicles");
    
    new 
field[48];
    for(new 
0MAX_PLAYER_VEHICLESi++)
    {
        
format(fieldsizeof(field), "Vehicle[%d]"i);
        
INI_WriteInt(FilefieldPlayerCars[playerid][i][pVehicle]);
        
format(fieldsizeof(field), "VehicleModel[%d]"i);
        
INI_WriteInt(FilefieldPlayerCars[playerid][i][pVehicleModel]);
        
        
format(fieldsizeof(field), "VehicleX[%d]"i);
        
INI_WriteFloat(FilefieldPlayerCars[playerid][i][pVehicleX]);
        
format(fieldsizeof(field), "VehicleY[%d]"i);
        
INI_WriteFloat(FilefieldPlayerCars[playerid][i][pVehicleY]);
        
format(fieldsizeof(field), "VehicleZ[%d]"i);
        
INI_WriteFloat(FilefieldPlayerCars[playerid][i][pVehicleZ]);
        
format(fieldsizeof(field), "VehicleC[%d]"i);
        
INI_WriteFloat(FilefieldPlayerCars[playerid][i][pVehicleC]);
        
        
format(fieldsizeof(field), "VehicleColor1[%d]"i);
        
INI_WriteInt(FilefieldPlayerCars[playerid][i][pVehicleColor1]);
        
format(fieldsizeof(field), "VehicleColor2[%d]"i);
        
INI_WriteInt(FilefieldPlayerCars[playerid][i][pVehicleColor2]);
        
format(fieldsizeof(field), "VehicleValue[%d]"i);
        
INI_WriteInt(FilefieldPlayerCars[playerid][i][pVehicleValue]);
        
format(fieldsizeof(field), "VehicleLock[%d]"i);
        
INI_WriteInt(FilefieldPlayerCars[playerid][i][pVehicleLock]);
        
format(fieldsizeof(field), "VehiclePlate[%d]"i);
        
INI_WriteString(FilefieldPlayerCars[playerid][i][pVehiclePlate]);
    }
    
INI_Close(File);
}
//Load functions
forward LoadUser_data(playerid,name[],value[]);
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("Password",PlayerInfo[playerid][pPass]);
    
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    
INI_Int("Faccion",PlayerInfo[playerid][Faccion]);
    
INI_Int("Rango",PlayerInfo[playerid][Rango]);
    
INI_Int("Payday",PlayerInfo[playerid][Payday]);
    
INI_Int("Respeto",PlayerInfo[playerid][Respeto]);
    
INI_Int("Nivel",PlayerInfo[playerid][Nivel]);
    
INI_Float("Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_Float("Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_Float("Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_Int("Accent",PlayerInfo[playerid][pAccent]);
    
INI_Int("Sexo",PlayerInfo[playerid][Sexo]);
    
INI_Int("Edad",PlayerInfo[playerid][Edad]);
    
INI_Int("Skin",PlayerInfo[playerid][Skin]);
    
INI_Int("Cartera",PlayerInfo[playerid][Cartera]);
    
    return 
1;
}
forward LoadCars_Vehicles(playerid,name[],value[]);
public 
LoadCars_Vehicles(playerid,name[],value[])
{
    new 
field[48];
    for(new 
0MAX_PLAYER_VEHICLESi++)
    {
        
format(fieldsizeof(field), "Vehicle[%d]"i);
        
INI_Int(fieldPlayerCars[playerid][i][pVehicle]);
        
format(fieldsizeof(field), "VehicleModel[%d]"i);
        
INI_Int(fieldPlayerCars[playerid][i][pVehicleModel]);
        
        
format(fieldsizeof(field), "VehicleX[%d]"i);
        
INI_Float(fieldPlayerCars[playerid][i][pVehicleX]);
        
format(fieldsizeof(field), "VehicleY[%d]"i);
        
INI_Float(fieldPlayerCars[playerid][i][pVehicleY]);
        
format(fieldsizeof(field), "VehicleZ[%d]"i);
        
INI_Float(fieldPlayerCars[playerid][i][pVehicleZ]);
        
format(fieldsizeof(field), "VehicleC[%d]"i);
        
INI_Float(fieldPlayerCars[playerid][i][pVehicleC]);
        
        
format(fieldsizeof(field), "VehicleColor1[%d]"i);
        
INI_Int(fieldPlayerCars[playerid][i][pVehicleColor1]);
        
format(fieldsizeof(field), "VehicleColor2[%d]"i);
        
INI_Int(fieldPlayerCars[playerid][i][pVehicleColor2]);
        
format(fieldsizeof(field), "VehicleValue[%d]"i);
        
INI_Int(fieldPlayerCars[playerid][i][pVehicleValue]);
        
format(fieldsizeof(field), "VehicleLock[%d]"i);
        
INI_Int(fieldPlayerCars[playerid][i][pVehicleLock]);
        
format(fieldsizeof(field), "VehiclePlate[%d]"i);
        
INI_String(fieldPlayerCars[playerid][i][pVehiclePlate], 32); //32 is the size of pVehiclePlate in enum
    
}
    
    return 
1;
}
//Path stocks
stock UserCars(playerid)
{
    new 
string[128], playername[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayernamesizeof(playername));
    
format(stringsizeof(string), VEHICLE_PATHplayername);
    return 
string;
}
stock UserPath(playerid)
{
    new 
string[64], playerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayerNamesizeof(playerName));
    
format(stringsizeof(string), USER_PATHplayerName);
    return 
string;
}
//
stock udb_hash(buf[]) {
    new 
length=strlen(buf);
    new 
s1 1;
    new 
s2 0;
    new 
n;
    for (
n=0n<lengthn++)
    {
       
s1 = (s1 buf[n]) % 65521;
       
s2 = (s2 s1)     % 65521;
    }
    return (
s2 << 16) + s1;
}
stock RPName(playerid)
{
    new 
playerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayerNamesizeof(playerName));
    return 
playerName;

Also, in your code you were using INI_ParseFile to read a string from the file
Код:
INI_ParseFile("Vehicle2Plate",PlayerCars[playerid][pVehicle2Plate]);
That should be
Код:
INI_String("Vehicle2Plate", PlayerCars[playerid][pVehicle2Plate], 32); //Replace 32 with the size of pVehicle2Plate
Reply


Messages In This Thread
Loading system failing - by Antenastyle - 19.05.2017, 17:33
Re: Loading system failing - by Aly - 19.05.2017, 17:39
Re: Loading system failing - by Antenastyle - 19.05.2017, 17:50
Re: Loading system failing - by Aly - 19.05.2017, 18:33
Re: Loading system failing - by Vince - 19.05.2017, 18:56
Re: Loading system failing - by Antenastyle - 19.05.2017, 21:37
Re: Loading system failing - by Aly - 19.05.2017, 22:52
Re: Loading system failing - by Antenastyle - 20.05.2017, 11:16
Re: Loading system failing - by Aly - 20.05.2017, 11:24
Re: Loading system failing - by Antenastyle - 20.05.2017, 11:45

Forum Jump:


Users browsing this thread: 1 Guest(s)