Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <sscanf2>
- #include <YSI\y_ini>
- #include <zcmd>
- forward LoadUserData(playerid,name[],value[]);
- forward OnPlayerRegister(playerid,password[]);
- forward OnPlayerLogin(playerid,password[]);
- native WP_Hash(buffer[],len,const str[]);
- new muted[MAX_PLAYERS];
- #define version "0.1"
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- enum PlayerInfo
- {
- Password[129],
- Admin,
- Score,
- Cash,
- Deaths,
- Kills
- }
- new pInfo[MAX_PLAYERS][PlayerInfo];
- /* Callbacks */
- public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
- {
- if(dialogid == DIALOG_REGISTER)
- {
- if(isnull(inputtext)) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Please enter a password.","Register","Quit");
- OnPlayerRegister(playerid,inputtext);
- }
- if(dialogid == DIALOG_LOGIN)
- {
- if(isnull(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Please enter a password.","Login","Quit");
- OnPlayerLogin(playerid,inputtext);
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new pFile[64],pName[24];
- GetPlayerName(playerid,pName,sizeof(pName));
- format(pFile,sizeof(pFile),"Users/%s.ini",pName);
- muted[playerid] = 0;
- if(fexist(pFile))
- {
- INI_ParseFile(pFile,"LoadUserData",.bExtra = true,.extra = playerid);
- ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Please enter a password.","Login","Quit");
- }
- else
- {
- ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Please enter a password.","Register","Quit");
- }
- return 1;
- }
- public LoadUserData(playerid,name[],value[])
- {
- INI_String("Password",pInfo[playerid][Password],129);
- INI_Int("Admin",pInfo[playerid][Admin]);
- INI_Int("Score",pInfo[playerid][Score]);
- INI_Int("Cash",pInfo[playerid][Cash]);
- INI_Int("Deaths",pInfo[playerid][Deaths]);
- INI_Int("Kills",pInfo[playerid][Kills]);
- return 1;
- }
- public OnPlayerRegister(playerid,password[])
- {
- new hashed[129],pFile[64],pName[24],string[124];
- GetPlayerName(playerid,pName,sizeof(pName));
- format(pFile,sizeof(pFile),"Users/%s.ini",pName);
- WP_Hash(hashed,129,password);
- new INI:PlayerFile = INI_Open(pFile);
- INI_WriteString(PlayerFile,"Password",hashed);
- INI_WriteInt(PlayerFile,"Admin",0);
- INI_WriteInt(PlayerFile,"Score",0);
- INI_WriteInt(PlayerFile,"Cash",0);
- INI_WriteInt(PlayerFile,"Deaths",0);
- INI_WriteInt(PlayerFile,"Kills",0);
- INI_Close(PlayerFile);
- format(string,sizeof(string),"%s has registered an account.");
- print(string);
- return 1;
- }
- public OnPlayerLogin(playerid,password[])
- {
- if(strcmp(password,pInfo[playerid][Password]))
- {
- ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Password incorrect.\nPlease enter a password.","Login","Quit");
- }
- else
- {
- SetPlayerScore(playerid,pInfo[playerid][Score]);
- GivePlayerMoney(playerid,pInfo[playerid][Cash]);
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid,reason)
- {
- new pFile[124],pName[124];
- GetPlayerName(playerid,pName,sizeof(pName));
- format(pFile,sizeof(pFile),"Users/%s.ini",pName);
- new INI:PlayerFile = INI_Open(pFile);
- INI_WriteString(PlayerFile,"Password",pInfo[playerid][Password]);
- INI_WriteInt(PlayerFile,"Admin",pInfo[playerid][Admin]);
- INI_WriteInt(PlayerFile,"Score",GetPlayerScore(playerid));
- INI_WriteInt(PlayerFile,"Cash",GetPlayerMoney(playerid));
- INI_WriteInt(PlayerFile,"Deaths",pInfo[playerid][Deaths]);
- INI_WriteInt(PlayerFile,"Kills",pInfo[playerid][Kills]);
- INI_Close(PlayerFile);
- return 1;
- }
- public OnPlayerDeath(playerid,killerid,reason)
- {
- pInfo[killerid][Kills] ++;
- pInfo[playerid][Deaths] ++;
- return 1;
- }
- public OnPlayerText(playerid,text[])
- {
- if(muted[playerid] == 1)
- {
- SendClientMessage(playerid,-1,"ERROR:Your muted.");
- return 0;
- }
- return 1;
- }
- /* Commands */
- CMD:changepass(playerid,params[])
- {
- new newpass[124],hashed[129];
- if(sscanf(params,"s[124]",newpass)) return SendClientMessage(playerid,-1,"USAGE:/changepass [newpass]");
- WP_Hash(hashed,129,newpass);
- pInfo[playerid][Password] = hashed;
- SendClientMessage(playerid,-1,"Changed.");
- return 1;
- }
- CMD:goto(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 1) return 0;
- new target,Float:x,Float:y,Float:z;
- if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"USAGE:/goto [playerid]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerPos(target,x,y,z);
- SetPlayerPos(playerid,x,y,z);
- return 1;
- }
- CMD:get(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 1) return 0;
- new target,Float:x,Float:y,Float:z;
- if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"USAGE:/get [playerid]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerPos(playerid,x,y,z);
- SetPlayerPos(target,x,y,z);
- return 1;
- }
- CMD:mute(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 1) return 0;
- new target,string[124],pName[24];
- if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"USAGE:/mute [playerid]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerName(target,pName,sizeof(pName));
- format(string,sizeof(string),"%s has been muted by an admin.",pName);
- SendClientMessageToAll(-1,string);
- muted[target] = 1;
- return 1;
- }
- CMD:unmute(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 1) return 0;
- new target,string[124],pName[24];
- if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"USAGE:/unmute [playerid]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerName(target,pName,sizeof(pName));
- format(string,sizeof(string),"%s has been unmuted by an admin.",pName);
- SendClientMessageToAll(-1,string);
- muted[target] = 0;
- return 1;
- }
- CMD:kick(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 2) return 0;
- new target,reason[66],string[124],pName[24];
- if(sscanf(params,"us[66]",target,reason)) return SendClientMessage(playerid,-1,"USAGE:/kick [playerid] [reason]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerName(target,pName,sizeof(pName));
- format(string,sizeof(string),"%s has bene kicked by an admin. Reason:%s",pName,reason);
- SendClientMessageToAll(-1,string);
- Kick(target);
- return 1;
- }
- CMD:ban(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 2) return 0;
- new target,reason[66],string[124],pName[24];
- if(sscanf(params,"us[66]",target,reason)) return SendClientMessage(playerid,-1,"USAGE:/ban [playerid] [reason]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerName(target,pName,sizeof(pName));
- format(string,sizeof(string),"%s has bene banned by an admin. Reason:%s",pName,reason);
- SendClientMessageToAll(-1,string);
- Ban(target);
- return 1;
- }
- CMD:ip(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 1) return 0;
- new target,pIP[34],pName[24],string[124];
- if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"USAGE:/ip [playerid]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- GetPlayerName(target,pName,sizeof(pName));
- GetPlayerIp(target,pIP,34);
- format(string,sizeof(string),"%s's IP is %s",pName,pIP);
- SendClientMessage(playerid,-1,string);
- return 1;
- }
- CMD:setlevel(playerid,params[])
- {
- if(pInfo[playerid][Admin] < 3) return 0;
- new target,level,string[124],pName[24];
- if(sscanf(params,"ud",target,level)) return SendClientMessage(playerid,-1,"USAGE:/setlevel [playerid] [level]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"ERROR:Player not connected.");
- if(level < 0 || level > 3) return SendClientMessage(playerid,-1,"ERROR:Invalid level. (1,2,3)");
- GetPlayerName(target,pName,sizeof(pName));
- format(string,sizeof(string),"%s has been promoted to a level %d admin!",pName,level);
- SendClientMessageToAll(-1,string);
- pInfo[playerid][Admin] = level;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement