Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a comment
- // uncomment the line below if you want to write a filterscript
- //#define FILTERSCRIPT
- #include <a_samp>
- #include <YSI\y_ini>
- #include <zcmd>
- #include <sscanf2>
- #define dregister 2011 //Defining register dialog so it won't mixed up with other dialog
- #define dlogin 2012 //Defining login dialog so it won't mixed up with other dialog
- #define UserPath "Users/%s.ini" //Will define user account path. In this case, will store in Scriptfiles/Users. So create a file inside of your Scriptfiles folder called Users
- #define COLOR_PINK 0xFF80FFC8
- #define COLOR_UNEMD 0x99CEFFFF
- #define COLOR_ORANGE 0xffcc00FF
- #define COLOR_GRAD1 0xB4B5B7FF
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_USAGE 0xEFEFF7AA
- #define COLOR_YELLOW 0xFFFF00C8
- native WP_Hash(buffer[],len,const str[]); // Whirlpool native, add it at the top of your script under includes
- enum PlayerInfo
- {
- Pass[129],
- pAdmin,
- pMoney,
- pScores,
- pKills,
- pDeaths,
- }
- new pInfo[MAX_PLAYERS][PlayerInfo];
- new levels,ID,Nam[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
- stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
- {
- 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[]); //forwarding a new function to load user's data
- //Now we will use our own function that we have created above
- public loadaccount_user(playerid, name[], value[])
- {
- INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
- ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length or hashed user's password. Whirlpool will hash 128 characters + NULL*/
- INI_Int("AdminLevel",pInfo[playerid][pAdmin]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
- INI_Int("Money",pInfo[playerid][pMoney]); //As explained above
- INI_Int("Scores",pInfo[playerid][pScores]);//As explained above
- INI_Int("Kills",pInfo[playerid][pKills]);//As explained above
- INI_Int("Deaths",pInfo[playerid][pDeaths]);//As explained above
- return 1;
- }
- CMD:setadmin(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid))return 0; //This command only works for rcon
- if(sscanf(params,"ui",ID,levels)) return SendClientMessage(playerid,0xFF9900AA, "USAGE: /setadmin [ID] [Level 1-4]");//it will show this if you dont use the format properly
- if(levels > 6) return SendClientMessage(playerid,0xFF0000FF,"LEVELS AVAILABLE 1-4!");//Available levels
- if(!IsPlayerConnected(ID))return SendClientMessage(playerid,0x99CEFFFF,"That user is not connected.");//Detect if the id/partofname is connected
- if(pInfo[ID][pAdmin] == levels) return SendClientMessage(playerid,0xFF0000FF, "ERROR: That person is already this admin level!");//Detect if the guy is already the level you setted
- GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);//define the playerid name
- GetPlayerName(ID,pname,MAX_PLAYER_NAME);//define the other person name
- new str[128];
- if(levels == 0)
- {
- format(str, sizeof(str),"%s has your Admin level to %d on the server. *cry *cry",Nam,levels);
- SendClientMessage(ID,0xFF9900AA,str);
- format(str, sizeof(str),"You had set %s Admin level to %d!",pname,levels);
- SendClientMessage(playerid,0xFF9900AA,str);
- pInfo[ID][pAdmin] = levels;//this sets the player level
- return 1;
- }
- format(str, sizeof(str),"%s has your Admin level to %d on the server.",Nam,levels);
- SendClientMessage(ID,0xFF9900AA,str);
- format(str, sizeof(str),"You had set %s Admin level to %d!",pname,levels);
- SendClientMessage(playerid,0xFF9900AA,str);
- pInfo[ID][pAdmin] = levels;
- return 1;
- }
- CMD:heal(playerid, params[])
- {
- new Player;
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFF00C8, "ERROR: You are not a RCON Admin!");
- else if (sscanf(params, "u", Player)) return SendClientMessage(playerid, 0xFFFF00C8, "Usage: /heal [PlayerID]");
- else if (Player == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFF00C8, "Player not found");
- else
- {
- SetPlayerHealth(Player, 100.0);
- SendClientMessage(Player, 0x00FF00AA, "You have been healed");
- SendClientMessage(playerid, 0x00FF00AA, "Player healed");
- }
- return 1;
- }
- COMMAND:veh(playerid, params[])
- {
- if(IsPlayerAdmin(playerid))
- {
- new
- toplayerid, // the player we want to give money to
- vehid;
- // extracting player's ID and amount from params
- if (!sscanf(params, "ii", toplayerid, vehid))
- {
- if (toplayerid != INVALID_PLAYER_ID)
- {
- new
- message[40];
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- CreateVehicle(vehid, x +3, y, z, 0, 0,0, -1);
- format(message, sizeof(message), "Admin has gave you a %d Vehicle!!", vehid);
- SendClientMessage(toplayerid, 0xFFFF00C8, message);
- }
- else SendClientMessage(playerid, 0xFFFF00C8, "That player is not connected");
- }
- else SendClientMessage(playerid, 0xFFFF00C8, "Usage: /veh <playerid> <vehicleid>");
- }
- else SendClientMessage(playerid, 0xFFFF00C8, "Only admins can use this command!");
- return 1;
- }
- CMD:pm(playerid, params[])
- {
- new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
- if(sscanf(params, "us", id, str2))
- {
- SendClientMessage(playerid, 0xFFFF00C8, "Usage: /pm <id> <message>");
- return 1;
- }
- if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFFFF00C8, "ERROR: Player not connected");
- if(playerid == id) return SendClientMessage(playerid, 0xFFFF00C8, "ERROR: You cannot pm yourself!");
- {
- GetPlayerName(playerid, Name1, sizeof(Name1));
- GetPlayerName(id, Name2, sizeof(Name2));
- format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
- SendClientMessage(playerid, 0xFFFF00C8, str);
- format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
- SendClientMessage(id, 0xFFFF00C8, str);
- }
- return 1;
- }
- main()
- {
- print("\n----------------------------------");
- print(" RolePlay");
- print("----------------------------------\n");
- }
- public OnGameModeInit()
- {
- // Don't use these lines if it's a filterscript
- SetGameModeText("RolePlay");
- AddPlayerClass(281,1380.9154,-1088.9073,27.3844,272.3928,0,0,0,0,0,0); //
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
- GetPlayerName(playerid,name,sizeof(name)); //Get player's name
- if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
- {// then
- INI_ParseFile(Path(playerid),"loadaccount_user", .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 //If the connected user is not registered,
- {//then we will 'force' him to register :)
- 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 OnPlayerDisconnect(playerid, reason)
- {
- //Same as OnDialogResponse, we will save their stats inside of their user's account
- if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
- {
- new INI:file = INI_Open(Path(playerid)); //will open their 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][pAdmin]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
- INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his score inside of his account
- INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//As explained above
- INI_WriteInt(file,"Kills",pInfo[playerid][pKills]);//As explained above
- INI_WriteInt(file,"Deaths",pInfo[playerid][pDeaths]);//As explained above
- INI_Close(file);//Now after we've done saving their data, we now need to close the file
- return 1;
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- pInfo[killerid][pKills]++;//Will give 1 score to killer and it will be saved inside of his/her account
- pInfo[playerid][pDeaths]++;//Will give 1 deaths each time they die and it will be saved inside of his/her account
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/mycommand", cmdtext, true, 10) == 0)
- {
- // Do something here
- return 1;
- }
- return 0;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- return 1;
- }
- public OnPlayerObjectMoved(playerid, objectid)
- {
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnVehicleMod(playerid, vehicleid, componentid)
- {
- return 1;
- }
- public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
- {
- return 1;
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnRconLoginAttempt(ip[], password[], success)
- {
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- return 1;
- }
- public OnPlayerStreamIn(playerid, forplayerid)
- {
- return 1;
- }
- public OnPlayerStreamOut(playerid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamOut(vehicleid, forplayerid)
- {
- 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 has entered a password for his 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 has their password
- new INI:file = INI_Open(Path(playerid)); //will create a new variable to register their acount 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 in of 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,"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);//As explained above
- 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 entered a correct password
- {//then
- INI_ParseFile(Path(playerid),"loadaccount_user",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
- SetPlayerScore(playerid,pInfo[playerid][pScores]);//We will get their score inside of his user's account and we will set it here
- GivePlayerMoney(playerid,pInfo[playerid][pMoney]);//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;
- }
- }
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement