#include <a_samp>
#include <INI>
#define USER_PATH "Accounts/%s.ini"
enum Info
{
IP[16],
Password[129],
Admin,
Score,
Money,
Deaths,
Kills,
Float:PosX,
Float:PosY,
Float:PosZ,
Float:PosA,
IsRegistered,
MyMotto[128]
}
new PlayerInfo[MAX_PLAYERS][Info];
native WP_Hash(buffer[], len, const str[]);
stock UserPath(playerid)
{
new pName[MAX_PLAYER_NAME], Path[60];
GetPlayerName(playerid, pName, sizeof(pName));
format(Path, sizeof(Path), USER_PATH, pName);
return Path;
}
file_OS();
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave");
}
else
{
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 0) // If it is the register dialog
{
if(response) // if the player pressed the first button in our case Register.
{
if(!strlen(inputtext) || strlen(inputtext) > 100) // if the text ISN'T between 1 - 100 characters.
{
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
SendClientMessage(playerid, -1, "Your password must be between (1 - 100) characters");
}
else // if the text IS between 1 - 100 characters.
{
new pName[MAX_PLAYER_NAME], pIP[16], HashPass[129]; // Creating 3 variables for player's name, IP, and a variable for hasing user's password.
GetPlayerName(playerid, pName, sizeof(pName)); // getting player's name and storing it inside the pName variable we created above ^.
GetPlayerIp(playerid, pIP, sizeof(pIP)); // getting player's IP and saving it inside the pIP variable we created before.
WP_Hash(HashPass, sizeof(HashPass), inputtext); // we are hashing inputtext (meaning the text the player wrote under the register dialog).
file_Create(UserPath(playerid)); // Creating the file in (Accounts/%s.ini)
file_Open(UserPath(playerid)); // opening the file
file_SetStr("Password", HashPass); // setting the player's password to the hashed number.
file_SetStr("IP", pIP); // setting player's IP to his IP
file_SetVal("Admin", 0); // setting his admin level to 0
file_SetVal("Score", 0); // setting his score to 0
file_SetVal("Money", 500); // setting his money to 500 (NOTE: you also need to use GivePlayerMoney under OnPlayerSpawn).
file_SetVal("Deaths", 0); // setting his kills to 0
file_SetVal("Kills", 0); // setting his deaths to 0
file_SetFloat("PosX", 0.0); // setting his X position to 0.0
file_SetFloat("PosY", 0.0); // setting his Y position to 0.0
file_SetFloat("PosZ", 0.0); // setting his Z position to 0.0
file_SetFloat("PosA", 0.0); // setting his Angle to 0.0
file_SetVal("IsRegistered", 1);
file_SetStr("MyMotto", "You Don't Have A Motto Set One Using /setmotto");
file_Save(UserPath(playerid)); // saving the file.
file_Close(); // closing the file (NOTE: ALWAYS AND I DO MEAN ALWAYS close a file don't keep it open)
SendClientMessage(playerid, -1, "you have been reged successfully"); // Sending a message to the player telling him he have been successfully registered the color -1 is white.
}
}
}
else if(dialogid == 1) // if he is registered then show him the login dialog
{
if(response) // if he clicked the first button in our case LOGIN
{
new HashPass[129]; // creating a variable to store get the hashed password from his file
WP_Hash(HashPass, sizeof(HashPass), inputtext); // hashing the text he entered under the login dialog
if(!strcmp(HashPass, PlayerInfo[playerid][Password])) // comparing it to the text in his file if it is true
{
file_Open(UserPath(playerid)); // open his file
PlayerInfo[playerid][Admin] = file_GetVal("Admin"); // set each variable in his enum to the one in his file
PlayerInfo[playerid][Score] = file_GetVal("Score");
PlayerInfo[playerid][Money] = file_GetVal("Money");
PlayerInfo[playerid][Deaths] = file_GetVal("Deaths");
PlayerInfo[playerid][Kills] = file_GetVal("Kills");
PlayerInfo[playerid][PosX] = file_GetFloat("PosX");
PlayerInfo[playerid][PosY] = file_GetFloat("PosY");
PlayerInfo[playerid][PosZ] = file_GetFloat("PosZ");
PlayerInfo[playerid][PosA] = file_GetFloat("PosA");
PlayerInfo[playerid][IsRegistered] = file_GetVal("IsRegistered");
file_Close(); // Closing the file.
}
else
{
SendClientMessage(playerid, -1, "wrong password entered try again"); // if the password doesn't match the one in his file then tell him that it is incorrect
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave"); // and re-show the login dialog
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(fexist(UserPath(playerid)))
{
GetPlayerPos(playerid, PlayerInfo[playerid][PosX], PlayerInfo[playerid][PosY], PlayerInfo[playerid][PosZ]);
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][PosA]);
file_Open(UserPath(playerid));
file_SetVal("Admin", PlayerInfo[playerid][Admin]);
file_SetVal("Score", PlayerInfo[playerid][Score]);
file_SetVal("Money", PlayerInfo[playerid][Money]);
file_SetVal("Deaths", PlayerInfo[playerid][Deaths]);
file_SetVal("Kills", PlayerInfo[playerid][Kills]);
file_SetFloat("PosX", PlayerInfo[playerid][PosX]);
file_SetFloat("PosY", PlayerInfo[playerid][PosY]);
file_SetFloat("PosZ", PlayerInfo[playerid][PosZ]);
file_SetFloat("PosA", PlayerInfo[playerid][PosA]);
file_SetVal("IsRegistered", PlayerInfo[playerid][IsRegistered]);
file_SetStr("MyMotto", PlayerInfo[playerid][MyMotto]);
file_Close();
}
return 1;
}
CMD:setmotto(playerid, params[])
{
if(PlayerInfo[playerid][IsRegistered] == 1) // if he is registered
{
if(IsNull(params)) return SendClientMessage(playerid, -1, "USAGE: /setmotto [your motto]"); // if he didn't write any parameters
PlayerInfo[playerid][MyMotto] = params; // set his motto to the parameter he wrote
SendClientMessage(playerid, -1, "SUCCESS: you have been successfully changed your motto into %s", params); // send him a success message
}
else SendClientMessage(playerid, -1, "You are not registered so you can't use this command"); // if he isn't registered
return 1; // the command is successfully done
}
public OnPlayerSpawn(playerid)
{
PlayerInfo[playerid][MyMotto] = file_dGetStr(UserPath(playerid), "MyMotto"); // setting the MyMotto variable inside our enum to the MyMotto line in the player's user file
new Str[128];
format(Str, sizeof(Str), "Welcome Back Your Motto Is : %s", PlayerInfo[playerid][MyMotto]); // formatting the message that we are going to send him.
SendClientMessage(playerid, -1, Str);
return 1;
}
This looks great, but i'm wondering one thing.. How can I make a command to make someone as an administrator?
|
CMD:setadmin(playerid, params[])
{
new pName[MAX_PLAYER_NAME], Str[128], tName[MAX_PLAYER_NAME], Level, targetid;
if(IsPlayerAdmin(playerid))
{
if(sscanf(params, "ui", targetid, Level))
{
SendClientMessage(playerid, -1, "{FFFF00}Usage : {FFFFFF}/setadmin [playerid] [level]");
SendClientMessage(playerid, -1, "{FF0000}Levels : {FFFFFF}(0 - Normal Player, 1 - VIP Member, 2 - Moderator, 3 - Admin, 4 - Server Developer, 5 - Server Owner)");
}
else
{
GetPlayerName(playerid, pName, sizeof(pName));
GetPlayerName(targetid, tName, sizeof(tName));
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "{FF0000}Error : {FFFFFF}The Player Is Not Connected");
format(Str, sizeof(Str), "You Have Made %s an admin level %i", tName, Level);
SendClientMessage(playerid, -1, Str);
format(Str, sizeof(Str), "%s has made you an admin level %i", pName, Level);
SendClientMessage(targetid, -1, Str);
GameTextForPlayer(targetid, "~g~Promoted", 5000, 5);
PlayerInfo[targetid][Admin] = Level;
}
}
else SendClientMessage(playerid, -1, "{FF0000}Error : {FFFFFF}Only Server {FF0000}Owners{FFFFFF} Can Use This Command");
return 1;
}
Looks great, thanks Lexi!
I will add this to the thread, I might update the script soon too, maybe with some new features such as tagging and hopefully a speed increase |
public OnPlayerDisconnect(playerid, reason)
{
if(fexist(UserPath(playerid)))
{
file_Open(UserPath(playerid));
file_SetVal("Admin", PlayerInfo[playerid][Admin]);
file_SetVal("Health", PlayerInfo[playerid][Health]);
file_SetVal("Armor", PlayerInfo[playerid][Armor]);
file_SetVal("Money", PlayerInfo[playerid][Money]);
file_SetVal("Skin", PlayerInfo[playerid][Skin]);
file_SetVal("Level", PlayerInfo[playerid][Level]);
file_SetVal("Banned", PlayerInfo[playerid][Banned]);
file_SetFloat("Posx", PlayerInfo[playerid][Posx]);
file_SetFloat("Posy", PlayerInfo[playerid][Posy]);
file_SetFloat("Posz", PlayerInfo[playerid][Posz]);
file_Close();
}
return 1;
}
if(PlayerInfo[playerid][Banned] == 0)
{
TogglePlayerSpectating(playerid, 0);
SetSpawnInfo(playerid, NO_TEAM, PlayerInfo[playerid][Skin], PlayerInfo[playerid][Posx],PlayerInfo[playerid][Posy],PlayerInfo[playerid][Posz], 0.0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetPlayerSkin(playerid, PlayerInfo[playerid][Skin]);
SetPlayerScore(playerid, PlayerInfo[playerid][Level]);
GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
}
else if(PlayerInfo[playerid][Banned] == 1)
{
SendClientMessage(playerid, COLOR_RED, "YOU HAVE BEEN BANNED FROM THIS SERVER.");
Kick(playerid);
}
For me the x, y, and z positions keep going back to 0.00000 in my player file when I /q
pawn Код:
I'm not sure why it is not saving them. |