24.09.2012, 17:30
Okay for the past 3 WEEKS i've been trieing to fix this but i just can't!
I dont know what to do it just won't save
I'm USING SII! https://sampforum.blast.hk/showthread.php?tid=58458
I dont know what to do it just won't save
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(PInfo[playerid][Logged] == 1)
{
PInfo[playerid][Logged] = 0;
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME], file[64];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "** %s has left United Kingdom TDM", name);
SendClientMessageToAll(-1, string);
format(file, sizeof file, "Admin/%s.ini", name);
INI_Open(file);
INI_WriteInt("Level", PInfo[playerid][Level]);
INI_WriteInt("Score", GetPlayerScore(playerid));
INI_WriteInt("Money",GetPlayerMoney(playerid));
INI_Save();
INI_Close();
}
return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid,-1,"Welcome to United Kingdom TDM! Dont forget to check /updates ! ");
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "** %s has joined United Kingdom TDM", name);
SendClientMessageToAll(-1, string);
new file[64],PlayerName[25];//Creating a variable where we can store the file path, and the variable to store the player's name.
GetPlayerName(playerid,PlayerName,sizeof PlayerName);//Storing the players name in the PlayerName variable.
format(file,sizeof file,"Admin/%s.ini",PlayerName);//Storing the file path with the players name.
if(!fexist(file))//Checking if the file exists
{//Here goes the stuff you want to do if the user is not registered.
SendClientMessage(playerid,-4,"You are not registered! Please use /register <password>");
}
else
{//Here goes the stuff you want to do if the user is registered.
SendClientMessage(playerid,-4,"You are registered! Use /login <password>");
}
return 1;
}
pawn Код:
CMD:register(playerid,params[])
{
if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");
new password[23];
if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /register <password>");
new file[64],PlayerName[24];
GetPlayerName(playerid,PlayerName,sizeof PlayerName);
format(file,sizeof file,"Admin/%s.ini",PlayerName);
if(fexist(file)) return SendClientMessage(playerid,-4,"Somehow you're already registered!");
INI_Open(file);
INI_WriteString("Password",password);
INI_WriteInt("Level",PInfo[playerid][Level]);
INI_WriteInt("Score",0);
INI_WriteInt("Money",2000);
INI_Save();
INI_Close();
SendClientMessage(playerid,-1,"You have successfully registered!");
PInfo[playerid][Logged] = 1;
return 1;
}
CMD:login(playerid,params[])
{
if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");//Checking if the player is logged in, if he is, it won't allow him to login
new password[23],password2[23];//Creating a variable to store the password, and another one to store the password from the user's file.
if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /login <password>");//Here we're checking if the player inputs any password, if not, it will return to him a message saying the proper usage.
new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
GetPlayerName(playerid,PlayerName,sizeof PlayerName);
format(file,sizeof file,"Admin/%s.ini",PlayerName);
if(!fexist(file)) return SendClientMessage(playerid,-4,"Please use /register");//Checking if the player is not registered, again....
INI_Open(file);//Opening the file with SII include
INI_ReadString(password2,"Password");
if(strcmp(password,password2) != 0) return SendClientMessage(playerid,-4,"Wrong password!"),INI_Close();//Checking if he inputted the correct password, if not, retrieve him a message and closing the file;
PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
PInfo[playerid][Score] = INI_ReadInt("Score"); // Setting the score of player
PInfo[playerid][Score] = INI_ReadInt("Money"); // Setting the score of player
INI_Close();//"Closing the file", that means that we're not using it anymore :P
SetPlayerScore(playerid, PInfo[playerid][Score]);
SendClientMessage(playerid,-1,"You have been successfully logged in!");
PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
return 1;
}
pawn Код:
enum PlayerInfo
{
Logged,
Level,
Score,
Money,
}
pawn Код:
#define PATH "/Admin/%s.ini"
pawn Код:
public UserDataLoad_data(playerid,name[],value[]) {
INI_Int("Money",PInfo[playerid][Money]);
INI_Int("Score",PInfo[playerid][Score]);
INI_Int("Level",PInfo[playerid][Level]);
return 1;
}