Advertisement
Guest User

Name and Gender Disappear

a guest
Aug 5th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.01 KB | None | 0 0
  1. /* Generation X Roleplay - Allura */
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5. #include <zcmd>
  6. #include <sscanf2>
  7.  
  8. // Database Information
  9.  
  10. #define MYSQL_HOST "localhost"
  11. #define MYSQL_USER "root"
  12. #define MYSQL_DATABASE "genx"
  13. #define MYSQL_PASSWORD ""
  14.  
  15. // New Account Variables
  16.  
  17. #define SPAWN_X 10.0
  18. #define SPAWN_Y 10.0
  19. #define SPAWN_Z 14.0
  20. #define SPAWN_A 0.0
  21. #define starterCash 500
  22.  
  23. // Enums
  24.  
  25. enum
  26. {
  27. LoginDialog,
  28. RegisterDialog,
  29. GenderDialog,
  30. RegisterConfirm
  31. };
  32.  
  33. enum PlayerData
  34. {
  35. ID,
  36. Name[MAX_PLAYER_NAME],
  37. Password[129],
  38. Gender[8],
  39. IP[16],
  40. AdminLevel,
  41. Cash,
  42. Float:posX,
  43. Float:posY,
  44. Float:posZ,
  45. Float:posA
  46. };
  47. new Player[MAX_PLAYERS][PlayerData];
  48.  
  49. new LoggedIn[MAX_PLAYERS];
  50. new mysql;
  51.  
  52. new MaleSkins[][] =
  53. {
  54. {6}, // Emmet
  55. {29}, // Drug Dealer
  56. {48}, // hmyst
  57. };
  58.  
  59. new FemaleSkins[][] =
  60. {
  61. {40}, // Normal Ped
  62. {41}, // Normal Ped
  63. {56}, // Normal Ped
  64. };
  65.  
  66. native WP_Hash(buffer[], len, const str[]);
  67.  
  68. main()
  69. {
  70. print("\n----------------------------------");
  71. print("Generation X Roleplay Created by Allura");
  72. print("----------------------------------\n");
  73. }
  74.  
  75. public OnGameModeInit()
  76. {
  77. mysql_log(LOG_ALL);
  78. mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
  79.  
  80. if(mysql_errno() != 0)
  81. {
  82. printf("[MySQL] The connection has failed.");
  83. mysql_close(mysql);
  84. }
  85. else
  86. {
  87. printf("[MySQL] Established successful connection to the database.");
  88. }
  89.  
  90. SetTimer("AccountSaveTimer", 900000, true); // Every 15 minutes
  91. return true;
  92. }
  93.  
  94. public OnGameModeExit()
  95. {
  96. mysql_close(mysql);
  97. return 1;
  98. }
  99.  
  100. public OnPlayerRequestClass(playerid, classid)
  101. {
  102. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  103. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  104. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  105. return 1;
  106. }
  107.  
  108. public OnPlayerConnect(playerid)
  109. {
  110. new query[200], playername[MAX_PLAYER_NAME];
  111. TogglePlayerSpectating(playerid, true);
  112.  
  113. GetPlayerName(playerid, playername, sizeof(playername));
  114. mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID`, `Gender` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
  115. mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
  116. return true;
  117. }
  118.  
  119. public OnPlayerDisconnect(playerid, reason)
  120. {
  121. SaveAccount(playerid);
  122. LoggedIn[playerid] = 0;
  123. return 1;
  124. }
  125.  
  126. public OnPlayerSpawn(playerid)
  127. {
  128. return true;
  129. }
  130.  
  131. public OnPlayerDeath(playerid, killerid, reason)
  132. {
  133. return 1;
  134. }
  135.  
  136. public OnVehicleSpawn(vehicleid)
  137. {
  138. return 1;
  139. }
  140.  
  141. public OnVehicleDeath(vehicleid, killerid)
  142. {
  143. return 1;
  144. }
  145.  
  146. public OnPlayerText(playerid, text[])
  147. {
  148. return 1;
  149. }
  150.  
  151. public OnPlayerCommandText(playerid, cmdtext[])
  152. {
  153. return 0;
  154. }
  155.  
  156. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  157. {
  158. return 1;
  159. }
  160.  
  161. public OnPlayerExitVehicle(playerid, vehicleid)
  162. {
  163. return 1;
  164. }
  165.  
  166. public OnPlayerStateChange(playerid, newstate, oldstate)
  167. {
  168. return 1;
  169. }
  170.  
  171. public OnPlayerEnterCheckpoint(playerid)
  172. {
  173. return 1;
  174. }
  175.  
  176. public OnPlayerLeaveCheckpoint(playerid)
  177. {
  178. return 1;
  179. }
  180.  
  181. public OnPlayerEnterRaceCheckpoint(playerid)
  182. {
  183. return 1;
  184. }
  185.  
  186. public OnPlayerLeaveRaceCheckpoint(playerid)
  187. {
  188. return 1;
  189. }
  190.  
  191. public OnRconCommand(cmd[])
  192. {
  193. return 1;
  194. }
  195.  
  196. public OnPlayerRequestSpawn(playerid)
  197. {
  198. return 1;
  199. }
  200.  
  201. public OnObjectMoved(objectid)
  202. {
  203. return 1;
  204. }
  205.  
  206. public OnPlayerObjectMoved(playerid, objectid)
  207. {
  208. return 1;
  209. }
  210.  
  211. public OnPlayerPickUpPickup(playerid, pickupid)
  212. {
  213. return 1;
  214. }
  215.  
  216. public OnVehicleMod(playerid, vehicleid, componentid)
  217. {
  218. return 1;
  219. }
  220.  
  221. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  222. {
  223. return 1;
  224. }
  225.  
  226. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  227. {
  228. return 1;
  229. }
  230.  
  231. public OnPlayerSelectedMenuRow(playerid, row)
  232. {
  233. return 1;
  234. }
  235.  
  236. public OnPlayerExitedMenu(playerid)
  237. {
  238. return 1;
  239. }
  240.  
  241. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  242. {
  243. return 1;
  244. }
  245.  
  246. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  247. {
  248. return 1;
  249. }
  250.  
  251. public OnRconLoginAttempt(ip[], password[], success)
  252. {
  253. return 1;
  254. }
  255.  
  256. public OnPlayerUpdate(playerid)
  257. {
  258. return 1;
  259. }
  260.  
  261. public OnPlayerStreamIn(playerid, forplayerid)
  262. {
  263. return 1;
  264. }
  265.  
  266. public OnPlayerStreamOut(playerid, forplayerid)
  267. {
  268. return 1;
  269. }
  270.  
  271. public OnVehicleStreamIn(vehicleid, forplayerid)
  272. {
  273. return 1;
  274. }
  275.  
  276. public OnVehicleStreamOut(vehicleid, forplayerid)
  277. {
  278. return 1;
  279. }
  280.  
  281. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  282. {
  283. new string[250];
  284. switch(dialogid)
  285. {
  286. case LoginDialog:
  287. {
  288. if(!response) KickPlayer(playerid);
  289.  
  290. new hashpass[129], query[300], playername[MAX_PLAYER_NAME];
  291.  
  292. GetPlayerName(playerid, playername, sizeof(playername));
  293. WP_Hash(hashpass, sizeof(hashpass), inputtext);
  294. if(!strcmp(hashpass, Player[playerid][Password]))
  295. {
  296. mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
  297. mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
  298. }
  299. else
  300. {
  301. format(string, sizeof(string), "Sorry, but you've entered an invalid password!\nYour username already exists.\nPlease enter your correct password:", GetName(playerid));
  302. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "GX:RP - Citizen Login", string, "Login", "Quit");
  303. }
  304. }
  305. case RegisterDialog:
  306. {
  307. if(!response) return Kick(playerid);
  308.  
  309. if(strlen(inputtext) < 10 || strlen(inputtext) > 29)
  310. {
  311. format(string, sizeof(string), "Your password can only be between 10 and 29 characters long.\nYour username does not exist.\nPlease enter a password to create an account:", GetName(playerid));
  312. ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "GX:RP - Immigration Office", string, "Register", "Quit");
  313. }
  314. else
  315. {
  316. new query[512], playername[MAX_PLAYER_NAME], playerip[16];
  317.  
  318. GetPlayerName(playerid, playername, sizeof(playername));
  319. GetPlayerIp(playerid, playerip, sizeof(playerip));
  320. WP_Hash(Player[playerid][Password], 129, inputtext);
  321. mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Gender`, `AdminLevel`, `Cash`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 'None', 0, %d, %f, %f, %f, %f)", playername, Player[playerid][Password], playerip, starterCash, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A);
  322. mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
  323. }
  324. }
  325. case GenderDialog:
  326. {
  327. new query[300];
  328. if(!response)
  329. {
  330. mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Gender` = 'Female' WHERE `ID` = %d", Player[playerid][ID]);
  331. mysql_tquery(mysql, query, "", "");
  332. ShowPlayerDialog(playerid, RegisterConfirm, DIALOG_STYLE_MSGBOX, "GX:RP Immigration Office", "Your character is now set as Female.\nYou have successfully completed the registration process.\nWe hope you enjoy your experience here.!", "Continue", "");
  333. }
  334. else
  335. {
  336. mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Gender` = 'Male' WHERE `ID` = %d", Player[playerid][ID]);
  337. mysql_tquery(mysql, query, "", "");
  338. ShowPlayerDialog(playerid, RegisterConfirm, DIALOG_STYLE_MSGBOX, "GX:RP Immigration Office", "Your character is now set as Male.\nYou have successfully completed the registration process.\nWe hope you enjoy your experience here.", "Continue", "");
  339. }
  340. }
  341. case RegisterConfirm:
  342. {
  343. if(!response)
  344. {
  345.  
  346. }
  347. else
  348. {
  349. format(string, sizeof(string), "To confirm your information and load your account, you're required to login after registration\nYou can now continue to enter your password:", GetName(playerid));
  350. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "GX:RP - Citizen Login", string, "Login", "Quit");
  351. }
  352. }
  353. }
  354. return false; // For filterscripts..
  355. }
  356.  
  357. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  358. {
  359. return 1;
  360. }
  361.  
  362. /* Custom Functions */
  363.  
  364. forward OnAccountCheck(playerid);
  365. public OnAccountCheck(playerid)
  366. {
  367. new rows, fields, string[200];
  368. cache_get_data(rows, fields, mysql);
  369. LoggedIn[playerid] = 0;
  370.  
  371. if(rows)
  372. {
  373. cache_get_field_content(0, "Password", Player[playerid][Password], mysql, 129);
  374. Player[playerid][ID] = cache_get_field_content_int(0, "ID");
  375. cache_get_field_content(0, "Gender", Player[playerid][Gender], mysql, 8);
  376. if(strcmp(Player[playerid][Gender], "Male") || strcmp(Player[playerid][Gender], "Female"))
  377. {
  378. ShowPlayerDialog(playerid, GenderDialog, DIALOG_STYLE_MSGBOX, "GX:RP - Immigration Office", "Please choose a character gender.\nYou cannot change this!", "Male", "Female");
  379. }
  380. else
  381. {
  382. format(string, sizeof(string), "Welcome back, %s!\nYour username already exists.\nPlease enter your password:", GetName(playerid));
  383. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "GX:RP - Citizen Login", string, "Login", "Quit");
  384. }
  385. }
  386. else
  387. {
  388. format(string, sizeof(string), "Welcome, %s!\nYour username does not exist.\nPlease enter a password to create an account:", GetName(playerid));
  389. ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "GX:RP - Immigration Office", string, "Register", "Quit");
  390. }
  391. return true;
  392. }
  393.  
  394. forward OnAccountRegister(playerid);
  395. public OnAccountRegister(playerid)
  396. {
  397. Player[playerid][ID] = cache_insert_id();
  398. printf("[Registration] New account registered. Database ID: [%d]", Player[playerid][ID]);
  399.  
  400. ShowPlayerDialog(playerid, GenderDialog, DIALOG_STYLE_MSGBOX, "GX:RP - Immigration Office", "Please choose a character gender.\nYou cannot change this!", "Male", "Female");
  401. return true;
  402. }
  403.  
  404. forward OnAccountLoad(playerid);
  405. public OnAccountLoad(playerid)
  406. {
  407. cache_get_field_content(0, "Name", Player[playerid][Name], mysql, MAX_PLAYER_NAME);
  408. cache_get_field_content(0, "IP", Player[playerid][IP], mysql, 16);
  409. cache_get_field_content(0, "Gender", Player[playerid][Gender], mysql, 8);
  410. Player[playerid][AdminLevel] = cache_get_field_content_int(0, "AdminLevel");
  411. Player[playerid][Cash] = cache_get_field_content_int(0, "Cash");
  412. Player[playerid][posX] = cache_get_field_content_float(0, "PosX");
  413. Player[playerid][posY] = cache_get_field_content_float(0, "PosY");
  414. Player[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
  415. Player[playerid][posA] = cache_get_field_content_float(0, "PosA");
  416.  
  417. TogglePlayerSpectating(playerid, false);
  418.  
  419. GivePlayerMoney(playerid, Player[playerid][Cash]);
  420.  
  421. SetSpawnInfo(playerid, 0, 23, Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
  422. SpawnPlayer(playerid);
  423.  
  424. SendClientMessage(playerid, -1, "You have successfully logged in.");
  425. LoggedIn[playerid] = 1;
  426. return true;
  427. }
  428.  
  429. forward SaveAccount(playerid);
  430. public SaveAccount(playerid)
  431. {
  432. new query[512], Float:pos[4];
  433.  
  434. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  435. GetPlayerFacingAngle(playerid, pos[3]);
  436.  
  437. mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Name` = '%e', `Password` = '%e', `Gender` = '%e', `AdminLevel` = %d, `Cash` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
  438. Player[playerid][Name], Player[playerid][Password], Player[playerid][Gender], Player[playerid][AdminLevel], GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
  439. mysql_tquery(mysql, query, "", "");
  440. return true;
  441. }
  442.  
  443. /* Timers */
  444.  
  445. forward AccountSaveTimer();
  446. public AccountSaveTimer()
  447. {
  448. for(new i=0; i < MAX_PLAYERS; i++)
  449. {
  450. if(LoggedIn[i] > 0)
  451. {
  452. SaveAccount(i);
  453. }
  454. }
  455. }
  456.  
  457. /* End of Timers */
  458.  
  459. /* Commands */
  460.  
  461. CMD:stats(playerid, params[])
  462. {
  463. new string[126];
  464. SendClientMessage(playerid, -1, "[--- User Statistics ---]");
  465. format(string, sizeof(string), "[ID: %d] [Name: %s] [IP: %s] [Cash: %d] [Gender: %s]", Player[playerid][ID], Player[playerid][Name], Player[playerid][IP], Player[playerid][Cash], Player[playerid][Gender]);
  466. SendClientMessage(playerid, -1, string);
  467. return 1;
  468. }
  469.  
  470. /* End of Commands */
  471.  
  472. stock GetName(playerid)
  473. {
  474. new name[MAX_PLAYER_NAME];
  475. GetPlayerName(playerid,name,sizeof(name));
  476. for(new i = 0; i < MAX_PLAYER_NAME; i++)
  477. {
  478. if(name[i] == '_') name[i] = ' ';
  479. }
  480. return name;
  481. }
  482.  
  483. stock KickPlayer(playerid)
  484. {
  485. SaveAccount(playerid);
  486. Kick(playerid);
  487. return 1;
  488. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement