It's been a long time since I've done any scripting and the last time I used dini for my script.
I'm trying to use y_ini now but I can't figure out what I'm doing wrong although I've read the tutorials about y_ini.
Код:
#define PlayerPath "/Users/%s.ini"
forward LoadUser_data(playerid, name[], value[]);
forward Save();//I use this to save online players' info every 5 sec
forward Spawn(playerid);//I use this to spawn a player
enum PlayerInfo
{
Float:X,
Float:Y,
Float:Z,
Float:Fa,
Sex,
Age,
Skin,
Vw,
Int,
Money,
Hour,
Exp,
Job,
AdminLvl,
RegStatus
}
new PlayerI[50][PlayerInfo];
public LoadUser_data(playerid, name[], value[])
{
INI_Int("RegStatus",PlayerI[playerid][RegStatus]);
INI_String("Password", PassW[playerid],120);
INI_Int("Sex",PlayerI[playerid][Sex]);
INI_Int("Skin",PlayerI[playerid][Skin]);
INI_Float("Fa",PlayerI[playerid][Fa]);
INI_Float("Z",PlayerI[playerid][Z]);
INI_Float("Y",PlayerI[playerid][Y]);
INI_Float("X",PlayerI[playerid][X]);
INI_Int("Vw",PlayerI[playerid][Vw]);
INI_Int("Int",PlayerI[playerid][Int]);
INI_Int("Job",PlayerI[playerid][Job]);
INI_Int("Exp",PlayerI[playerid][Exp]);
INI_Int("Hour",PlayerI[playerid][Hour]);
INI_Int("Age",PlayerI[playerid][Age]);
INI_Int("AdminLvl",PlayerI[playerid][AdminLvl]);
INI_Int("Money",PlayerI[playerid][Money]);
return 1;
}
public Save()
{
for(new i=0;i<50;i++)
{
if(IsPlayerLoggedIn(i))
{
new INI:File = INI_Open(UserPath(i));
INI_SetTag(File, "data");
INI_WriteInt(File,"Money",PlayerI[i][Money]);
INI_WriteInt(File,"AdminLvl",PlayerI[i][AdminLvl]);
INI_WriteInt(File,"Sex",PlayerI[i][Sex]);
INI_WriteInt(File,"Age",PlayerI[i][Age]);
INI_WriteInt(File,"Hour",PlayerI[i][Hour]);
INI_WriteInt(File,"Exp",PlayerI[i][Exp]);
INI_WriteInt(File,"Job",PlayerI[i][Job]);
INI_WriteInt(File,"Int",GetPlayerInterior(i));
INI_WriteInt(File,"Vw",GetPlayerVirtualWorld(i));
INI_WriteInt(File,"Skin",PlayerI[i][Skin]);
GetPlayerPos(i,PlayerI[i][X],PlayerI[i][Y],PlayerI[i][Z]);
GetPlayerFacingAngle(i,PlayerI[i][Fa]);
INI_WriteFloat(File,"X",PlayerI[i][X]);
INI_WriteFloat(File,"Y",PlayerI[i][Y]);
INI_WriteFloat(File,"Z",PlayerI[i][Z]);
INI_WriteFloat(File,"Fa",PlayerI[i][Fa]);
INI_Close(File);
}
}
return 1;
}
public Spawn(playerid)
{
SetPlayerPos(playerid,PlayerI[playerid][X],PlayerI[playerid][Y],PlayerI[playerid][Z]);
SetPlayerFacingAngle(playerid, PlayerI[playerid][Fa]);
SetPlayerSkin(playerid, PlayerI[playerid][Skin]);
new string[100];
format(string, 100,"%f\n%f\n%f",PlayerI[playerid][X],PlayerI[playerid][Y],PlayerI[playerid][Z]);//I used this to figure out what's wrong
SayTo(playerid,COLOR_WHITE,string);
}
public OnGameModeInit()
{
SetGameModeText("Test");
SetTimer("Save",5000,1);
return 1;
}
public OnPlayerConnect(playerid)
{
if(CheckName(playerid)==1)
{
RegLog(playerid);
}
}
public OnPlayerSpawn(playerid)
{
SetTimerEx("Spawn",1000,0,"%i",playerid);
return 1;
}
stock RegLog(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra =playerid);
ShowPlayerDialog(playerid, D_Login, DIALOG_STYLE_INPUT,"Login","Type your password","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, D_Rules, 0,"Welcome","-","Accept","Deny");
}
}
stock UserPath(playerid)
{
new string[50],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PlayerPath,playername);
return string;
}
This code sometimes loads the info saved in the .ini file(it saves with no problems)
And most of the time doesn't work, when I checked the floats I saw that only PlayerI[playerid][X] is being read and the Y and Z are 0.0000000.