Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- #include <easydialog>
- #include <YSI\y_commands>
- native WP_Hash(buffer[], len, const str[]);
- #define HOST "localhost"
- #define USER "root"
- #define DATABASE "prp"
- #define PASS ""
- main()
- {
- print("\n----------------------------------");
- print(" Blank Gamemode by your name here");
- print("----------------------------------\n");
- }
- new g_Logged[MAX_PLAYERS];
- enum Stats
- {
- char_name[30],
- char_password[60],
- Float: char_position[4],
- char_interior,
- char_virtualworld
- };
- new PlayerInfo[MAX_PLAYERS][Stats];
- public OnGameModeInit()
- {
- mysql_connect(HOST, USER, DATABASE, PASS);
- mysql_debug(1);
- ReturnConnection();
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- if(!g_Logged[playerid])
- {
- new query[255];
- format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s'", GetName(playerid));
- mysql_query(query);
- mysql_store_result();
- TogglePlayerControllable(playerid, 0);
- TogglePlayerSpectating(playerid, true);
- InterpolateCameraLookAt(playerid, 1668.9432,-1458.1198,120.6119, 1586.5640,-1281.9943,120.6119, 15000, CAMERA_MOVE);
- if(mysql_num_rows() == 1)
- {
- ShowDialog(playerid, Show:Login, DIALOG_STYLE_PASSWORD, "Registration", "Welcome back to Persistent Roleplay\n\nThis account appears to be in the database.\nYou can login by typing in your password below.", "Continue", "Cancel");
- }
- else
- {
- return ShowDialog(playerid, Show:Register, DIALOG_STYLE_PASSWORD, "Registration", "Welcome to Persistent Roleplay\n\nWe didn't find your account in our database, please register to make an account.", "Continue", "Cancel");
- }
- }
- else
- {
- SetPlayerPos(playerid, 1975.203002, 3779.311523, -50.243506);
- SetPlayerCameraPos(playerid, 1975.203002, 3779.311523, 100.243506);
- SetPlayerCameraLookAt(playerid, 1975.203002, 3779.311523, -0.243506);
- SetSpawnInfo(playerid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- SpawnPlayer(playerid);
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SaveCharacter(playerid);
- g_Logged[playerid] = 0;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(g_Logged[playerid])
- {
- SpawnCharacter(playerid);
- }
- 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[])
- {
- 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[])
- {
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- Dialog:Login(playerid, response, listitem, inputtext[])
- {
- if (response)
- {
- new query[255], epass[129];
- WP_Hash(epass, sizeof(epass), inputtext);
- format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s' AND password = '%s'", GetName(playerid), epass);
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- LoginCharacter(playerid);
- }
- else
- {
- ShowDialog(playerid, Show:Login, DIALOG_STYLE_PASSWORD, "Login", "{FF0000}You've entered a wrong password.\n\n\nWelcome back to Persistent Roleplay\n\nThis account appears to be in the database.\nYou can login by typing in your password below.", "Continue", "Cancel");
- }
- }
- else return Kick(playerid);
- return 1;
- }
- Dialog:Register(playerid, response, listitem, inputtext[])
- {
- if (response)
- {
- RegisterCharacter(playerid, inputtext);
- }
- else return Kick(playerid);
- return 1;
- }
- stock SpawnCharacter(playerid)
- {
- TogglePlayerControllable(playerid, 1);
- TogglePlayerSpectating(playerid, false);
- /* Location & World */
- SetPlayerPos(playerid, PlayerInfo[playerid][char_position][0], PlayerInfo[playerid][char_position][1], PlayerInfo[playerid][char_position][2]);
- SetPlayerFacingAngle(playerid, PlayerInfo[playerid][char_position][3]);
- SetPlayerInterior(playerid, PlayerInfo[playerid][char_interior]);
- SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][char_virtualworld]);
- }
- stock LoginCharacter(playerid)
- {
- new query[255];
- format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s'", GetName(playerid));
- mysql_query(query);
- mysql_store_result();
- while(mysql_fetch_row_format(query, "|"))
- {
- mysql_fetch_field_row(PlayerInfo[playerid][char_name], "name");
- mysql_fetch_field_row(PlayerInfo[playerid][char_password], "password");
- mysql_fetch_field_row(query, "posx"); PlayerInfo[playerid][char_position][0] = floatstr(query);
- mysql_fetch_field_row(query, "posy"); PlayerInfo[playerid][char_position][1] = floatstr(query);
- mysql_fetch_field_row(query, "posz"); PlayerInfo[playerid][char_position][2] = floatstr(query);
- mysql_fetch_field_row(query, "posa"); PlayerInfo[playerid][char_position][3] = floatstr(query);
- mysql_fetch_field_row(query, "int"); PlayerInfo[playerid][char_interior] = strval(query);
- mysql_fetch_field_row(query, "vw"); PlayerInfo[playerid][char_virtualworld] = strval(query);
- }
- g_Logged[playerid] = 1;
- print("SpawnPlayer");
- SpawnPlayer(playerid);
- }
- stock RegisterCharacter(playerid, rpass[])
- {
- new query[255], epass[129];
- WP_Hash(epass, sizeof(epass), rpass);
- format(query, sizeof(query), "INSERT INTO accounts (name, password, posx, posy, posz, posa, int, vw) VALUES ('%s', '%s', '1529.6', '-1691.2', '13.3', '0', '0', '0')", GetName(playerid), epass);
- mysql_query(query);
- LoginCharacter(playerid);
- return 1;
- }
- stock SaveCharacter(playerid)
- {
- new query[255], Float:pos[4];
- GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
- GetPlayerFacingAngle(playerid, pos[3]);
- PlayerInfo[playerid][char_position][0] = pos[0];
- PlayerInfo[playerid][char_position][1] = pos[1];
- PlayerInfo[playerid][char_position][2] = pos[2];
- PlayerInfo[playerid][char_position][3] = pos[3];
- format(query, sizeof(query), "UPDATE accounts SET name = '%s', posx = '%f', posy = '%f', posz = '%f', posa = '%f', int = '%d', vw = '%d' WHERE name = '%s'", GetName(playerid), PlayerInfo[playerid][char_position][0], PlayerInfo[playerid][char_position][1], PlayerInfo[playerid][char_position][2], PlayerInfo[playerid][char_position][3],
- PlayerInfo[playerid][char_interior], PlayerInfo[playerid][char_virtualworld], GetName(playerid));
- mysql_query(query);
- printf("ID: %d / %s has been saved.", playerid, GetName(playerid));
- }
- stock GetName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- for(new i = 0; i < MAX_PLAYER_NAME; i++)
- {
- if(name[i] == '_') name[i] = ' ';
- }
- return name;
- }
- stock ReturnConnection()
- {
- if(mysql_ping() != -1)
- {
- printf("Connected with the MySQL server. PING: %d", mysql_ping());
- }
- else
- {
- print("Connection with the MySQL server has failed.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement