Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <sscanf>
- #include <YSI\y_ini>
- #include <foreach>
- /* We now have this at the top of our gamemode, an #include is basically a DIRECTIVE which inserts code from a specified file and puts it into whatever you have put the #include line in, so:
- #include <zcmd> is including the code from the zcmd.inc file located in your Pawno/include file
- Includes are important so remember them
- Okay, so now we need to use some defines so that we can get our script running
- */
- #define COLOR_BLUE 0x0000FFAA
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define PATH "/Users/%s.ini" // Very important line
- /* These are our colours, so when you send a client message or a string or whatever, you can simply type: SendClientMessage(playerid, COLOR_BLUE, "Hello."); and it will send it the colour blue, and vice versa for whatever colour you want to send. */
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- #define DIALOG_SUCCESS_1 3
- #define DIALOG_SUCCESS_2 4
- // These defines are what we are going to be using for allowing our players to register and login to our server so that we can save all of the information.
- enum pInfo // <---------- Here
- { // Opening the brackets to show that we are including our array tags
- pPass,
- pAdmin,
- pSkin,
- pLevel,
- pMoney,
- pEXP
- }
- new
- PlayerInfo[MAX_PLAYERS][pInfo]; // pInfo is the name for all of our arrays which is HERE
- //////// STOCKS ////////
- /* Okay, we don't need that stock, but we do need this very important stock: */
- stock UserPath(playerid)
- {
- new
- string[128],
- playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid, playername, sizeof(playername));
- format(string, sizeof(string), PATH, playername);
- return string;
- }
- /* Okay, now we need yet another stock which will allow for passwords to be hidden and make them safe and secure from hackers. If you ever want to reset a password, you go to Users/Playername and then just change the password line, simpleeessssss. Okay, so copy and paste this - this is very complicated */
- stock udb_hash(buf[])
- {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
- //////// FUNCTIONS ////////
- forward LoadUser_data(playerid,name[],value[]);
- public LoadUser_data(playerid,name[],value[])
- {
- INI_Int("Password",PlayerInfo[playerid][pPass]);
- INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
- INI_Int("Level",PlayerInfo[playerid][pLevel]);
- INI_Int("Skin",PlayerInfo[playerid][pSkin]);
- INI_Int("Money",PlayerInfo[playerid][pMoney]);
- INI_Int("Experience",PlayerInfo[playerid][pEXP]);
- return 1;
- }
- // Okay, so now we are LOADING all of this information from our Arrays. We have also given each of our arrays nice little names, good eh? So, inside the document we will have all of that but you will only see what is in the speechmarks, and whatever the data is.
- main() {}
- public OnGameModeInit()
- {
- 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)
- {
- // We want it so when a player hasn't connected to the server, we want there name to be a colour
- SetPlayerColor(playerid, COLOR_GREY);
- // You might not have COLOR_GREY at the top, if not, add this: #define COLOR_GREY 0xAFAFAFAA
- // Now we want to check if a player actually fucking exists, so lets use file exist (fexist)
- if(fexist(UserPath(playerid)))
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- // This line is a little more complicated, only reason I am not going into detail is because
- // You will most likely not use INI again if you get a mySQL database, I will help you later with
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type your password below", "Login", "Quit"); // Put this all on line in your pawn file
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering...", "Type your password below to register a new account", "Register", "Quit");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new
- playername[MAX_PLAYER_NAME]; // This is where we will store the players name
- GetPlayerName(playerid, playername, sizeof(playername)); // This is us obtaining the players name
- new
- date1, // Year
- date2, // Month
- date3; // Day
- getdate(date3, date2, date1); // Putting the date together backwards so it's day/month/year
- new
- INI:File = INI_Open(UserPath(playerid)); // Opening the file of the player who has quit.
- INI_SetTag(File, "Player Information"); // This will be at the top of each players info
- // So let's copy and paste what we had originally to speed this shit up
- INI_WriteInt(File, "Admin",PlayerInfo[playerid][pAdmin]);
- INI_WriteInt(File, "Level",PlayerInfo[playerid][pLevel]);
- INI_WriteInt(File, "Skin",PlayerInfo[playerid][pSkin]);
- INI_WriteInt(File, "Money",PlayerInfo[playerid][pMoney]);
- INI_WriteInt(File, "Experience",PlayerInfo[playerid][pEXP]);
- // Now, what we're doing here is updating all of the information and writing it into the file
- // So now that the player has left the server, we have updated his skin and shit like that
- INI_Close(File); // Closing the file because we are done with it
- printf("[ %s ] has disconnected from the server on [ %d / %d / %d]", playername, date1, date2, date3);
- // This is us just making a log to show when a player leaves, just for safety purposes
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- new playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid, playername, sizeof(playername));
- printf("[ %s ] has spawned", playername);
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- return 1;
- }
- 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;
- }
- // Okay, because in the public we can have multiple dialogs, we want to switch dialogid
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch( dialogid ) // The spaces aren't needed, but it looks neater
- {
- case DIALOG_REGISTER: // Now we're sayin, if the dialogid is dialog_register, do this:
- {
- if(!response) return Kick(playerid);
- // ! basically means the opposite, so if there is no response, we kick the player for taking too long
- if(response) // If they do respond by moving the mouse or typing something
- {
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Registering...","Type your password below to register a new account.","Register","Quit");
- // Basically, if the length of the password is too short, we send them the dialog again
- new
- INI:File = INI_Open(UserPath(playerid));
- // We are opening a new file for the player who registers, so they are registered
- INI_SetTag(File, "Information"); // Title inside the file, rename this to whatever
- INI_WriteInt(File,"Password",udb_hash(inputtext)); // Adding the HASHED password
- INI_WriteInt(File,"Admin",0); // Setting their admin to 0
- INI_WriteInt(File,"Level",0); // Setting their level 0
- INI_WriteInt(File,"Skin",0); // Setting their skin to 0
- INI_WriteInt(File,"Money",0); // Setting their money to 0
- INI_WriteInt(File,"Experience",0); // Setting their EXP to 0
- //Okay, so now we want to spawn the player ignore this will explain later
- SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 296.15, 0, 0, 0, 0, 0, 0);
- SpawnPlayer(playerid);
- // Okay, now the player is registered and he is on the server all fine
- }
- }
- case DIALOG_LOGIN:
- {
- // SAme process
- if(!response) return Kick(playerid); // Get rid of the idle player
- if(response)
- {
- if(udb_hash(inputtext) == PlayerInfo[playerid][pPass]) // If the password enters matches pass
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- // Opening and loading the data for the player
- GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
- // Giving him his cash which is in his file
- SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
- // Giving him the skin
- ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX, "Success!", "You have logged in!", "Ok", "");
- // Telling him he is successful and giving him ONE button
- }
- else //If the password does not match in the file, tell him to login again
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "You have entered a bad password", "Login", "Quit");
- }
- return 1;
- }
- }
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
Add Comment
Please, Sign In to add comment