OnPlayerUpdate is not a good place to save user data to files.
It gets called too often. |
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#include <a_samp>
#include <dini>
public OnPlayerConnect(playerid)
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
if(dini_Exists(String))
{
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
}
else
{
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid==DIALOG_LOGIN)
{
if(response==0)
{
SendClientMessage(playerid,BLUE,"You have been kicked for not loging in.");
Kick(playerid);
return 1;
}
if(response==1)
{
if(!strlen(inputtext))
{
SendClientMessage(playerid,RED,"This password is too short");
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
return 1;
}
else
{
Login(playerid,inputtext);
PlayerPlaySound(playerid,1057,0,0,0);
return 1;
}
}
}
if(dialogid==DIALOG_REGISTER)
{
if(response==0)
{
SendClientMessage(playerid,BLUE,"You have been kicked for not registering in.");
Kick(playerid);
return 1;
}
if(response==1)
{
if(!strlen(inputtext))
{
SendClientMessage(playerid,BLUE,"This password is too short");
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
return 1;
}
else
{
Register(playerid,inputtext);
return 1;
}
}
}
return 1;
}
stock Register(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
dini_Create(String);
dini_Set(String,"Password",key);
SendClientMessage(playerid,BLUE,"Successfully registered");
dini_IntSet(String,"Level",0);
return 1;
}
stock Login(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
if(!strcmp(key,dini_Get(String,"Password"),false))
{
SetPlayerScore(playerid,dini_Int(String,"Level"));
SendClientMessage(playerid,BLUE,"Successfully logged");
return 1;
}
else
{
SendClientMessage(playerid,RED,"Wrong password.");
PlayerPlaySound(playerid,1055,0,0,0);
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
return 1;
}
}
Make a new function, for example 'SavePlayer' and save user data there.
Then use SavePlayer(playerid); in your script where user data changes, like when player gets new score or money or etc. |
for(new i=0; i<MAX_PLAYERS; i++)
{
CallLocalFunction("OnPlayerDisconnect", "%d", i);
}
By the way;
This system also saves position (so you will spawn where you logged out) and is also saves weapons and ammo. Where do you want me to call the SavePlayer function there? Thank you very much |
for(new i=0; i < MAX_PLAYERS; i++)
{
SavePlayer(i);
}