Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #pragma tabsize 0
- #include <YSI\y_ini>
- #include <zcmd>
- #include <sscanf2>
- #define dregister 2011
- #define dlogin 2012
- #define acmds 2013
- #define UserPath "Users/%s.ini"
- //COLORS
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_RED 0xFF0000AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_VIOLETBLUE 0x8A2BE2AA
- #define COLOR_DEADCONNECT 0x808080AA
- #define COLOR_BLUE 0x0000FFAA
- #define COLOR_FORESTGREEN 0x228B22AA
- #define COLOR_DODGERBLUE 0x1E90FFAA
- #define COLOR_DARKOLIVEGREEN 0x556B2FAA
- #define COLOR_ORANGE 0xFFA500AA
- #define COLOR_PURPLE 0x800080AA
- #define COLOR_ROYALBLUE 0x4169FFAA
- #define COLOR_ERROR 0xD2691EAA
- #define COLOR_PINK 0xFF0080FF
- #define COLOR_SEXYGREEN 0x00FF00FF
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- #define COLOR_LIME 0x10F441AA
- #define COLOR_ADMIN 0x10F441AA
- #define COLOR_CYAN 0x40FFFFFF
- #define COLOR_ORANGERED 0xFF4500AA
- #define COLOR_NAVY 0x000080AA
- #define COLOR_LIME 0x10F441AA
- forward GivePlayerScore(targetid,Value);
- native WP_Hash(buffer[],len,const str[]);
- enum PlayerInfo
- {
- Pass[129],
- Adminlevel,
- VIPlevel,
- Regularlevel,
- Money,
- Scores,
- Kills,
- Deaths
- }
- new pInfo[MAX_PLAYERS][PlayerInfo];
- new WarnTimes[MAX_PLAYERS];
- stock Path(playerid)
- {
- new str[128],name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- format(str,sizeof(str),UserPath,name);
- return str;
- }
- forward loadaccount_user(playerid, name[], value[]);
- public loadaccount_user(playerid, name[], value[])
- {
- INI_String("Password", pInfo[playerid][Pass],129);
- INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);
- INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);
- INI_Int("RegularPlayerLevel",pInfo[playerid][Regularlevel]);
- INI_Int("Money",pInfo[playerid][Money]);
- INI_Int("Scores",pInfo[playerid][Scores]);
- INI_Int("Kills",pInfo[playerid][Kills]);
- INI_Int("Deaths",pInfo[playerid][Deaths]);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name)); //Get player's name
- if(fexist(Path(playerid)))
- {
- INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
- ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
- }
- else
- {
- ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
- return 1;
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == dregister) //If dialog id is a register dialog
- {//then
- if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
- if(response) //if they clicked the first button "Register"
- {//then
- if(!strlen(inputtext)) //If they didn't enter any password
- {// then we will tell to them to enter the password to register
- ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
- return 1;
- }
- //If they have entered a correct password for his/her account...
- new hashpass[129]; //Now we will create a new variable to hash his/her password
- WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
- new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
- INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
- INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
- INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
- INI_WriteInt(file,"VIPLevel",0);//As explained above
- INI_WriteInt(file,"RegularPlayerLevel",0);
- INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
- INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
- INI_WriteInt(file,"Kills",0);//As explained above
- INI_WriteInt(file,"Deaths",0);//As explained above
- INI_Close(file);//Now after we've done saving their data, we now need to close the file
- SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
- return 1;
- }
- }
- if(dialogid == dlogin) //If dialog id is a login dialog
- {//then
- if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
- if(response) //if they clicked the first button "Register"
- {//then
- new hashpass[129]; //Will create a new variable to hash his/her password
- WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
- if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
- {//then
- INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
- SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
- GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
- SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
- }
- else //If they've entered an incorrect password
- {//then
- ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
- return 1;
- }
- }
- }
- if(dialogid == acmds)
- {
- {
- if(response)
- {
- switch(listitem)
- {
- case 0: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 1 commands","/clearchat /goto /warn /asay","Exit","Back");
- case 1: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 2 commands","/sethp /setarmour /kick","Exit","Back");
- case 2: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 3 commands","/ban /unbanip","Exit","Back");
- case 3: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 4 commands","/setscore /givemoney","Exit","Back");
- case 4: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 5 commands","/makeadmin /fly","Exit","Back");
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- //Same as OnDialogResponse, we will save their stats inside of their user's account
- new INI:file = INI_Open(Path(playerid)); //will open their file
- INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
- INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
- INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
- INI_WriteInt(file,"RegularPlayerLevel",pInfo[playerid][Regularlevel]);//Regular Player Level
- INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
- INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
- INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
- INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
- INI_Close(file);//Now after we've done saving their data, we now need to close the file
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
- pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
- return 1;
- }
- COMMAND:acmds(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- ShowPlayerDialog(playerid,acmds,DIALOG_STYLE_LIST,"Admin commands","Level 1\nLevel 2\nLevel 3\nLevel 4\nLevel 5","Go","Exit");
- return 1;
- }
- COMMAND:goto(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 2) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new Float:x,Float:y,Float:z,id;
- if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /goto [playerid]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This id isnt logged in!");
- GetPlayerPos(id,x,y,z);
- SetPlayerPos(playerid,x,y,z);
- SendClientMessage(playerid, 0x33AA33AA, "[ADMIN] You have succesfully telported to the player!");
- }
- return 1;
- }
- COMMAND:clearchat(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- for(new i = 0; i < 250; i++) SendClientMessageToAll(0xFFC800," An administrator has cleared the chat ");
- return 1;
- }
- COMMAND:kick(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 2) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new id;
- new reason;
- if(sscanf(params,"u",id,reason)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /kick [playerid] [reason]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This id isnt online!");
- if(pInfo[playerid][Adminlevel] < pInfo[id][Adminlevel]) return SendClientMessage(playerid,COLOR_RED,"You can't kick a higher admin level than you");
- Kick(id);
- SendClientMessage(playerid, 0x33AA33AA, "[ADMIN] You have succesfully kicked the player!");
- }
- return 1;
- }
- COMMAND:makeadmin(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 5) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new id,level,string[128];
- if(sscanf(params,"ui",id,level)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /makeadmin [playerid] [level 1-5]");
- if(level < 1 && level > 5) return SendClientMessage(playerid,COLOR_RED,"[ERROR] Level not found.");
- format(string,sizeof(string),"You has been PROMOTED to admin level %i",level);
- SendClientMessage(id,COLOR_RED,string);
- pInfo[id][Adminlevel] = level;
- SendClientMessage(playerid, 0x33AA33AA, "[ADMIN] You have succesfully used /makeadmin command!");
- }
- return 1;
- }
- COMMAND:sethp(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new id,Float:health;
- if(sscanf(params,"uf",id,health)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /sethp [playerid] [hp]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Player not found!");
- if(pInfo[id][Adminlevel] > pInfo[playerid][Adminlevel]) return SendClientMessage(playerid,COLOR_RED,"You cannot use this command on another admin high level than you");
- SetPlayerHealth(id,health);
- SendClientMessage(id, 0xFFC800, "[GIFT] An administrator has healed you");
- }
- return 1;
- }
- COMMAND:setarmour(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new id,Float:ar;
- if(sscanf(params,"uf",id,ar)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /setarmor [playerid] [armour]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Player not found!");
- if(pInfo[id][Adminlevel] > pInfo[playerid][Adminlevel]) return SendClientMessage(playerid,COLOR_RED,"You can't use this command on a nother admin high level than you");
- SetPlayerArmour(id,ar);
- SendClientMessage(id, 0xFFC800, "[GIFT] An administrator has given you armour");
- }
- return 1;
- }
- COMMAND:givemoney(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 4) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new id,money;
- if(sscanf(params,"ui",id,money)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /givemoney [playerid] [ammount]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Player not found!");
- GivePlayerMoney(id,money);
- SendClientMessage(id, 0xFFC800, "[GIFT] An administrator has given you money");
- SendClientMessage(playerid, 0x33AA33AA, "You have succesfully used /givemoney!");
- }
- return 1;
- }
- command(warn, playerid, params[])
- {
- if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- {
- new i, reason[50];
- new name[50];
- new string[250];
- if(sscanf(params, "us[50]", i, reason)) SendClientMessage(playerid, COLOR_RED, "USAGE: /warn [id] [reason]");
- else if(i == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Player is not connected!");
- else
- {
- GetPlayerName(i, name, sizeof(name));
- if(playerid!=i)
- {
- if(WarnTimes[i]>=2)
- {
- format(string, 128,"[AUTO-KICK]: %s[%d] Has Been Kicked From The Server, [3/3 Warnings]", name, i);
- SendClientMessageToAll(0xFFC800, string);
- SetPlayerHealth(i, 999999999);
- SetPlayerInterior(i, 10);
- SetPlayerPos(i,226.9807,111.1730,999.0156);
- format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
- GameTextForPlayer(i ,string, 99999999999999999999999, 3);
- Kick(i);
- }
- else
- {
- WarnTimes[i]+=1;
- if(WarnTimes[i]==1)
- {
- format(string, 128,"[ADMIN-WARN]: You Have Received A Warning, Reason: %s, [1/3 Warnings]", reason);
- SendClientMessage(i, 0xFFC800, string);
- }
- else if(WarnTimes[i]==2)
- {
- format(string, 128,"[ADMIN-WARN]: You Have Received A Warning, Reason: %s, [2/3 Warnings]", reason);
- SendClientMessage(i,0xFFC800, string);
- }
- format(string, 128,"[ADMIN-WARN]: %s[%d] Has Received A Warning, Reason: %s", name, i, reason);
- SendClientMessageToAll(0xFFC800, string);
- GameTextForPlayer(i,"~W~You Have Received A ~n~ ~R~Warning",5000,3);
- }
- }
- else SendClientMessage(playerid, COLOR_RED, "You Cannot Warn Yourself");
- }
- }
- return 1;
- }
- CMD:ban(playerid, params[])
- {
- new id, reason[50], string[128], banned[MAX_PLAYER_NAME];
- if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- if(sscanf(params, "uz", id, reason))return SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason(optional)]");
- GetPlayerName(id, banned, sizeof(banned));
- format(string, sizeof(string), "AdmCmd: %s has been banned by %s. reason: %s", banned, GetName(playerid), reason);
- SendClientMessageToAll(COLOR_RED, string);
- BanEx(id, reason);
- return 1;
- }
- CMD:fly(playerid, params[])
- {
- if(pInfo[playerid][Adminlevel] >= 5) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
- return 1;
- }
- stock GetName(playerid)
- {
- new
- pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
- return pName;
- }
- CMD:unbanip(playerid,params[])
- {
- new ip[32], dformat[64];
- if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- if(sscanf(params,"s[32]",ip)) return SendClientMessage(playerid,0xff0000ff,"USAGE: /unban [ip]");
- format(dformat,sizeof dformat,"unbanip %s",ip);
- SendRconCommand(dformat);
- return 1;
- }
- CMD:setscore(playerid, params[]) {
- new id; // "defines" the targets id.
- new score; // Gets the targets score ( was added to prevent an error.)
- new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
- GetPlayerName(playerid, name, sizeof(name));
- if(pInfo[playerid][Adminlevel] >= 4) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- if(sscanf(params, "ui", id, score)) return SendClientMessage(playerid, COLOR_NAVY, "USAGE: /setscore [ID] [SCORE]"); //If there aren't enough params typed in(ex - /setscore ID)
- if(score < 1) return SendClientMessage(playerid, COLOR_ORANGE, "You need to give more than 1 score."); //This isn't really needed, but it "forces" the admin to give the player more than 1 score.
- if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is not online."); //If the targets id isn't "valid", the admin will receive this "error" message, cause there was no ID found.
- SetPlayerScore(id, score); //Sets the targets score.
- format(string, sizeof(string), "Administrator %s has given you some score!", name); //Target receives this message.
- SendClientMessage(id, COLOR_ORANGE, string);
- return 1;
- }
- CMD:asay(playerid,params[])
- {
- if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
- if (isnull(params)) return SendClientMessage(playerid,COLOR_GREY, "Usage : /asay <text>");
- new string[256];
- format(string, sizeof(string), "ADMIN: %s",params);
- SendClientMessageToAll(0xFF0000FF, string);
- printf("%s",params);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment