19.05.2017, 22:52
I tried to rewrite your code a little bit.Here's what I did:
Also, in your code you were using INI_ParseFile to read a string from the file
That should be
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(string, sizeof(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(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Server - Login", string, "Login", "Exit");
}
else
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Server - Register","Enter a new password to create a new account:", "Register", "Exit");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if(!response)
return Kick(playerid);
else
{
if(!strlen(inputtext))
return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_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(playerid, DIALOG_SEX, DIALOG_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(playerid, PlayerInfo[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 i = 0; i < MAX_PLAYER_VEHICLES; i++)
{
format(field, sizeof(field), "Vehicle[%d]", i);
INI_WriteInt(File, field, PlayerCars[playerid][i][pVehicle]);
format(field, sizeof(field), "VehicleModel[%d]", i);
INI_WriteInt(File, field, PlayerCars[playerid][i][pVehicleModel]);
format(field, sizeof(field), "VehicleX[%d]", i);
INI_WriteFloat(File, field, PlayerCars[playerid][i][pVehicleX]);
format(field, sizeof(field), "VehicleY[%d]", i);
INI_WriteFloat(File, field, PlayerCars[playerid][i][pVehicleY]);
format(field, sizeof(field), "VehicleZ[%d]", i);
INI_WriteFloat(File, field, PlayerCars[playerid][i][pVehicleZ]);
format(field, sizeof(field), "VehicleC[%d]", i);
INI_WriteFloat(File, field, PlayerCars[playerid][i][pVehicleC]);
format(field, sizeof(field), "VehicleColor1[%d]", i);
INI_WriteInt(File, field, PlayerCars[playerid][i][pVehicleColor1]);
format(field, sizeof(field), "VehicleColor2[%d]", i);
INI_WriteInt(File, field, PlayerCars[playerid][i][pVehicleColor2]);
format(field, sizeof(field), "VehicleValue[%d]", i);
INI_WriteInt(File, field, PlayerCars[playerid][i][pVehicleValue]);
format(field, sizeof(field), "VehicleLock[%d]", i);
INI_WriteInt(File, field, PlayerCars[playerid][i][pVehicleLock]);
format(field, sizeof(field), "VehiclePlate[%d]", i);
INI_WriteString(File, field, PlayerCars[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 i = 0; i < MAX_PLAYER_VEHICLES; i++)
{
format(field, sizeof(field), "Vehicle[%d]", i);
INI_Int(field, PlayerCars[playerid][i][pVehicle]);
format(field, sizeof(field), "VehicleModel[%d]", i);
INI_Int(field, PlayerCars[playerid][i][pVehicleModel]);
format(field, sizeof(field), "VehicleX[%d]", i);
INI_Float(field, PlayerCars[playerid][i][pVehicleX]);
format(field, sizeof(field), "VehicleY[%d]", i);
INI_Float(field, PlayerCars[playerid][i][pVehicleY]);
format(field, sizeof(field), "VehicleZ[%d]", i);
INI_Float(field, PlayerCars[playerid][i][pVehicleZ]);
format(field, sizeof(field), "VehicleC[%d]", i);
INI_Float(field, PlayerCars[playerid][i][pVehicleC]);
format(field, sizeof(field), "VehicleColor1[%d]", i);
INI_Int(field, PlayerCars[playerid][i][pVehicleColor1]);
format(field, sizeof(field), "VehicleColor2[%d]", i);
INI_Int(field, PlayerCars[playerid][i][pVehicleColor2]);
format(field, sizeof(field), "VehicleValue[%d]", i);
INI_Int(field, PlayerCars[playerid][i][pVehicleValue]);
format(field, sizeof(field), "VehicleLock[%d]", i);
INI_Int(field, PlayerCars[playerid][i][pVehicleLock]);
format(field, sizeof(field), "VehiclePlate[%d]", i);
INI_String(field, PlayerCars[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(playerid, playername, sizeof(playername));
format(string, sizeof(string), VEHICLE_PATH, playername);
return string;
}
stock UserPath(playerid)
{
new string[64], playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, sizeof(string), USER_PATH, playerName);
return string;
}
//
stock udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
stock RPName(playerid)
{
new playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, sizeof(playerName));
return playerName;
}
Код:
INI_ParseFile("Vehicle2Plate",PlayerCars[playerid][pVehicle2Plate]);
Код:
INI_String("Vehicle2Plate", PlayerCars[playerid][pVehicle2Plate], 32); //Replace 32 with the size of pVehicle2Plate