Код:
dcmd_register(playerid,params[])
{
new pass[24];
if (sscanf(params, "s[24]",pass)) return SendClientMessage(playerid,COLOR_RED,"* Usage: /register <password>");
new name[24];
GetPlayerName(playerid,name,sizeof(name));
if (udb_Exists(name)) return SendClientMessage(playerid,COLOR_RED,"This username is already taken, choose another one!");
new ip[16];
GetPlayerName(playerid,name,sizeof(name));
GetPlayerIp(playerid,ip,16);
if(udb_Create(name,params))
{
SetPVarInt(playerid,"LoggedIn",1);
dUserSet(name).("IPAddress",ip);
SendClientMessage(playerid,COLOR_GREEN, "You have been registered and logged in.");
PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
}
return 1;
}
dcmd_login(playerid,params[])
{
new pass[24];
if (sscanf(params, "s[24]",pass)) return SendClientMessage(playerid,COLOR_RED,"Usage: /login <password>");
new name[24];
GetPlayerName(playerid,name,sizeof(name));
if (!udb_Exists(name)) return SendClientMessage(playerid,COLOR_RED,"Account doesn't exist, please use '/register [password]'.");
if (udb_CheckLogin(name,params))
{
new tmp3[16];
GetPlayerIp(playerid,tmp3,16);
dUserSet(name).("IPAddress",tmp3);
LoginPlayer(playerid);
SendClientMessage(playerid,COLOR_GREEN,"Successfully Logged In");
}
else SendClientMessage(playerid,COLOR_RED,"Login failed! Incorrect Password.");
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SavePlayer(playerid);
TextDrawHideForPlayer(playerid,TextDraw1);
SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
return 1;
}
stock SavePlayer(playerid)
{
if(GetPVarInt(playerid,"LoggedIn") == 1)
{
new name[24];
GetPlayerName(playerid,name,sizeof name);
dUserSetINT(name).("Deaths",GetPVarInt(playerid,"Deaths"));
dUserSetINT(name).("Kills",GetPVarInt(playerid,"Kills"));
dUserSetINT(name).("Money",GetPVarInt(playerid,"Money"));
dUserSetINT(name).("Color",GetPVarInt(playerid,"Color"));
dUserSetINT(name).("Level",GetPVarInt(playerid,"Level"));
new ip[16];
GetPVarString(playerid,"IP",ip,16);
dUserSet(name).("IPAddress",ip);
}
}
stock LoginPlayer(playerid)
{
new name[24];
GetPlayerName(playerid,name,sizeof name);
if(!udb_Exists(name)) return 0;
SetPVarInt(playerid,"Deaths",dUserINT(name).("Deaths"));
SetPVarInt(playerid,"Kills",dUserINT(name).("Kills"));
SetPVarInt(playerid,"Money",dUserINT(name).("Money"));
SetPVarInt(playerid,"Color",dUserINT(name).("Color"));
SetPVarInt(playerid,"Level",dUserINT(name).("Level"));
return 1;
}
When player register his account create in scriptfiles.When he kill someone or get money in game.
But his stats dont save...Please who have time to explain me what i need add.Or you can add and post code.
Can I ask why theres a '.' in between "(name) and ("VariableToSave")? and I recommend you to do a check and see if the player is logged on. If not another player can just log in then out to f&&k up another player's stats.
pawn Код:
stock LoginPlayer(playerid)
{
new name[24];
GetPlayerName(playerid,name,sizeof name);
if(!udb_Exists(name)) return 0;
SetPVarInt(playerid,"Deaths",dUserINT(name).("Deaths"));
SetPVarInt(playerid,"Kills",dUserINT(name).("Kills"));
SetPVarInt(playerid,"Money",dUserINT(name).("Money"));
SetPVarInt(playerid,"Color",dUserINT(name).("Color"));
SetPVarInt(playerid,"Level",dUserINT(name).("Level"));
SetPVarInt(playerid,"LoggedIn",1); // <------ add this line
return 1;
}