#define DATOS "Usuarios/%s.ini"
public OnPlayerDisconnect(playerid, reason)
{
GuardarDatos(playerid);
return 1;
}
forward GuardarDatos(playerid);
public GuardarDatos(playerid)
{
new Nombre[MAX_PLAYER_NAME], Archivo[13+MAX_PLAYER_NAME+1], Float:Pos[4], Float:VidaChaleco[2];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
GetPlayerFacingAngle(playerid, Pos[3]);
GetPlayerHealth(playerid, VidaChaleco[0]);
GetPlayerArmour(playerid, VidaChaleco[1]);
GetPlayerName(playerid, Nombre, sizeof(Nombre));
if(INI_Exist(Nombre))
{
format(Archivo ,sizeof Archivo, DATOS, Nombre);
new INI:File = INI_Open(Archivo);
INI_SetTag(File,"datos");
INI_WriteInt(File,"Admin",Datos[playerid][pAdmin]);
INI_WriteInt(File,"Dinero",Datos[playerid][pDinero]);
INI_WriteInt(File,"Edad",Datos[playerid][pEdad]);
INI_WriteFloat(File,"Pos_x",Pos[0]);
INI_WriteFloat(File,"Pos_y",Pos[1]);
INI_WriteFloat(File,"Pos_z",Pos[2]);
INI_WriteFloat(File,"Pos_a",Pos[3]);
INI_WriteFloat(File,"Vida",Float:VidaChaleco[0]);
INI_WriteFloat(File,"Chaleco",Float:VidaChaleco[1]);
INI_Close(File);
}
return 1;
}
public OnPlayerConnect(playerid)
{
//jugador nuevo nivel 0 admin
Datos[playerid][pAdmin] = 0;
//demбs variables a 0, false o valor inicial
//si la cuenta existe hace login y le da el nivel que estй en el archivo y sino, se registra con nivel 0
return 1;
}
public OnPlayerConnect(playerid)
{
ResetVariables(playerid);
new Nombre[MAX_PLAYER_NAME];
GetPlayerName(playerid, Nombre, MAX_PLAYER_NAME);
if(INI_Exist(Nombre))
{
INI_ParseFile(UserPath(playerid), "LoadUser_pass", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOGO_INGRESO, DIALOG_STYLE_PASSWORD, "INGRESO", "Ingrese su contraseсa para ingresar al servidor.", "Aceptar", "Salir");
return 1;
}
else
{
ShowPlayerDialog(playerid, DIALOGO_REGISTRO, DIALOG_STYLE_PASSWORD, "REGISTRO", "Bienvenido al servidor, ingrese una contraseсa para registrarte.", "Registrarse", "Salir");
return 1;
}
return 1;
}
public OnPlayerSpawn(playerid)
{
JugadorLogeado[playerid] = 1;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
GuardarDatos(playerid);
JugadorLogeado[playerid] = 0;
return 1;
}
forward GuardarDatos(playerid);
public GuardarDatos(playerid)
{
if(JugadorLogeado[playerid] == 1)
{
new Nombre[MAX_PLAYER_NAME], Archivo[13+MAX_PLAYER_NAME+1], Float:Pos[4], Float:VidaChaleco[2];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
GetPlayerFacingAngle(playerid, Pos[3]);
GetPlayerHealth(playerid, VidaChaleco[0]);
GetPlayerArmour(playerid, VidaChaleco[1]);
GetPlayerName(playerid, Nombre, sizeof(Nombre));
if(INI_Exist(Nombre))
{
format(Archivo ,sizeof Archivo, DATOS, Nombre);
new INI:File = INI_Open(Archivo);
INI_SetTag(File,"datos");
INI_WriteInt(File,"Admin",Datos[playerid][pAdmin]);
INI_WriteInt(File,"Dinero",Datos[playerid][pDinero]);
INI_WriteInt(File,"Edad",Datos[playerid][pEdad]);
INI_WriteFloat(File,"Pos_x",Pos[0]);
INI_WriteFloat(File,"Pos_y",Pos[1]);
INI_WriteFloat(File,"Pos_z",Pos[2]);
INI_WriteFloat(File,"Pos_a",Pos[3]);
INI_WriteFloat(File,"Vida",Float:VidaChaleco[0]);
INI_WriteFloat(File,"Chaleco",Float:VidaChaleco[1]);
INI_Close(File);
}
}
return 1;
}
stock ResetVariables(playerid)
{
Datos[playerid][pAdmin] = 0;
Datos[playerid][pDinero] = 0;
Datos[playerid][pEdad] = 0;
Datos[playerid][pPos_x] = 0.0;
Datos[playerid][pPos_y] = 0.0;
Datos[playerid][pPos_z] = 0.0;
Datos[playerid][pPos_a] = 0.0;
Datos[playerid][pVida] = 0.0;
Datos[playerid][pChaleco] = 0.0;
return 1;
}
En GuardarDatos no es necesario que se verifique si el jugador estб logueado? de ser asн tendrнas un gran problema ahн.
Si tienes un servidor que haga andar bien el SQL lo mejor es eso, en cualquier caso |