Advertisement
Guest User

Untitled

a guest
Jul 29th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.95 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <a_mysql>
  4. #include <sscanf2>
  5. #include <easydialog>
  6. #include <YSI\y_commands>
  7.  
  8. native WP_Hash(buffer[], len, const str[]);
  9.  
  10. #define HOST "localhost"
  11. #define USER "root"
  12. #define DATABASE "prp"
  13. #define PASS ""
  14.  
  15.  
  16. main()
  17. {
  18. print("\n----------------------------------");
  19. print(" Blank Gamemode by your name here");
  20. print("----------------------------------\n");
  21. }
  22.  
  23.  
  24. new g_Logged[MAX_PLAYERS];
  25.  
  26. enum Stats
  27. {
  28. char_name[30],
  29. char_password[60],
  30. Float: char_position[4],
  31. char_interior,
  32. char_virtualworld
  33. };
  34.  
  35. new PlayerInfo[MAX_PLAYERS][Stats];
  36.  
  37. public OnGameModeInit()
  38. {
  39.  
  40. mysql_connect(HOST, USER, DATABASE, PASS);
  41. mysql_debug(1);
  42.  
  43. ReturnConnection();
  44.  
  45. SetGameModeText("Blank Script");
  46. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  47. return 1;
  48. }
  49.  
  50. public OnGameModeExit()
  51. {
  52. return 1;
  53. }
  54.  
  55. public OnPlayerRequestClass(playerid, classid)
  56. {
  57. if(!g_Logged[playerid])
  58. {
  59. new query[255];
  60.  
  61. format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s'", GetName(playerid));
  62. mysql_query(query);
  63. mysql_store_result();
  64.  
  65. TogglePlayerControllable(playerid, 0);
  66. TogglePlayerSpectating(playerid, true);
  67. InterpolateCameraLookAt(playerid, 1668.9432,-1458.1198,120.6119, 1586.5640,-1281.9943,120.6119, 15000, CAMERA_MOVE);
  68.  
  69. if(mysql_num_rows() == 1)
  70. {
  71. 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");
  72. }
  73. else
  74. {
  75. 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");
  76. }
  77. }
  78. else
  79. {
  80. SetPlayerPos(playerid, 1975.203002, 3779.311523, -50.243506);
  81. SetPlayerCameraPos(playerid, 1975.203002, 3779.311523, 100.243506);
  82. SetPlayerCameraLookAt(playerid, 1975.203002, 3779.311523, -0.243506);
  83. SetSpawnInfo(playerid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  84. SpawnPlayer(playerid);
  85. }
  86. return 1;
  87. }
  88.  
  89. public OnPlayerConnect(playerid)
  90. {
  91. return 1;
  92. }
  93.  
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96. SaveCharacter(playerid);
  97. g_Logged[playerid] = 0;
  98. return 1;
  99. }
  100.  
  101. public OnPlayerSpawn(playerid)
  102. {
  103. if(g_Logged[playerid])
  104. {
  105. SpawnCharacter(playerid);
  106. }
  107. return 1;
  108. }
  109.  
  110. public OnPlayerDeath(playerid, killerid, reason)
  111. {
  112. return 1;
  113. }
  114.  
  115. public OnVehicleSpawn(vehicleid)
  116. {
  117. return 1;
  118. }
  119.  
  120. public OnVehicleDeath(vehicleid, killerid)
  121. {
  122. return 1;
  123. }
  124.  
  125. public OnPlayerText(playerid, text[])
  126. {
  127. return 1;
  128. }
  129.  
  130. public OnPlayerCommandText(playerid, cmdtext[])
  131. {
  132. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  133. {
  134. // Do something here
  135. return 1;
  136. }
  137. return 0;
  138. }
  139.  
  140. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  141. {
  142. return 1;
  143. }
  144.  
  145. public OnPlayerExitVehicle(playerid, vehicleid)
  146. {
  147. return 1;
  148. }
  149.  
  150. public OnPlayerStateChange(playerid, newstate, oldstate)
  151. {
  152. return 1;
  153. }
  154.  
  155. public OnPlayerEnterCheckpoint(playerid)
  156. {
  157. return 1;
  158. }
  159.  
  160. public OnPlayerLeaveCheckpoint(playerid)
  161. {
  162. return 1;
  163. }
  164.  
  165. public OnPlayerEnterRaceCheckpoint(playerid)
  166. {
  167. return 1;
  168. }
  169.  
  170. public OnPlayerLeaveRaceCheckpoint(playerid)
  171. {
  172. return 1;
  173. }
  174.  
  175. public OnRconCommand(cmd[])
  176. {
  177. return 1;
  178. }
  179.  
  180. public OnPlayerRequestSpawn(playerid)
  181. {
  182. return 1;
  183. }
  184.  
  185. public OnObjectMoved(objectid)
  186. {
  187. return 1;
  188. }
  189.  
  190. public OnPlayerObjectMoved(playerid, objectid)
  191. {
  192. return 1;
  193. }
  194.  
  195. public OnPlayerPickUpPickup(playerid, pickupid)
  196. {
  197. return 1;
  198. }
  199.  
  200. public OnVehicleMod(playerid, vehicleid, componentid)
  201. {
  202. return 1;
  203. }
  204.  
  205. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  206. {
  207. return 1;
  208. }
  209.  
  210. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  211. {
  212. return 1;
  213. }
  214.  
  215. public OnPlayerSelectedMenuRow(playerid, row)
  216. {
  217. return 1;
  218. }
  219.  
  220. public OnPlayerExitedMenu(playerid)
  221. {
  222. return 1;
  223. }
  224.  
  225. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  226. {
  227. return 1;
  228. }
  229.  
  230. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  231. {
  232. return 1;
  233. }
  234.  
  235. public OnRconLoginAttempt(ip[], password[], success)
  236. {
  237. return 1;
  238. }
  239.  
  240. public OnPlayerUpdate(playerid)
  241. {
  242. return 1;
  243. }
  244.  
  245. public OnPlayerStreamIn(playerid, forplayerid)
  246. {
  247. return 1;
  248. }
  249.  
  250. public OnPlayerStreamOut(playerid, forplayerid)
  251. {
  252. return 1;
  253. }
  254.  
  255. public OnVehicleStreamIn(vehicleid, forplayerid)
  256. {
  257. return 1;
  258. }
  259.  
  260. public OnVehicleStreamOut(vehicleid, forplayerid)
  261. {
  262. return 1;
  263. }
  264.  
  265. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  266. {
  267. return 1;
  268. }
  269.  
  270. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  271. {
  272. return 1;
  273. }
  274.  
  275. Dialog:Login(playerid, response, listitem, inputtext[])
  276. {
  277. if (response)
  278. {
  279. new query[255], epass[129];
  280.  
  281. WP_Hash(epass, sizeof(epass), inputtext);
  282.  
  283. format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s' AND password = '%s'", GetName(playerid), epass);
  284. mysql_query(query);
  285. mysql_store_result();
  286.  
  287. if(mysql_num_rows() == 1)
  288. {
  289. LoginCharacter(playerid);
  290. }
  291. else
  292. {
  293. 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");
  294. }
  295. }
  296. else return Kick(playerid);
  297. return 1;
  298. }
  299.  
  300. Dialog:Register(playerid, response, listitem, inputtext[])
  301. {
  302. if (response)
  303. {
  304. RegisterCharacter(playerid, inputtext);
  305. }
  306. else return Kick(playerid);
  307. return 1;
  308. }
  309.  
  310. stock SpawnCharacter(playerid)
  311. {
  312. TogglePlayerControllable(playerid, 1);
  313. TogglePlayerSpectating(playerid, false);
  314.  
  315. /* Location & World */
  316.  
  317. SetPlayerPos(playerid, PlayerInfo[playerid][char_position][0], PlayerInfo[playerid][char_position][1], PlayerInfo[playerid][char_position][2]);
  318. SetPlayerFacingAngle(playerid, PlayerInfo[playerid][char_position][3]);
  319. SetPlayerInterior(playerid, PlayerInfo[playerid][char_interior]);
  320. SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][char_virtualworld]);
  321. }
  322.  
  323. stock LoginCharacter(playerid)
  324. {
  325. new query[255];
  326.  
  327. format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s'", GetName(playerid));
  328. mysql_query(query);
  329. mysql_store_result();
  330.  
  331. while(mysql_fetch_row_format(query, "|"))
  332. {
  333. mysql_fetch_field_row(PlayerInfo[playerid][char_name], "name");
  334. mysql_fetch_field_row(PlayerInfo[playerid][char_password], "password");
  335. mysql_fetch_field_row(query, "posx"); PlayerInfo[playerid][char_position][0] = floatstr(query);
  336. mysql_fetch_field_row(query, "posy"); PlayerInfo[playerid][char_position][1] = floatstr(query);
  337. mysql_fetch_field_row(query, "posz"); PlayerInfo[playerid][char_position][2] = floatstr(query);
  338. mysql_fetch_field_row(query, "posa"); PlayerInfo[playerid][char_position][3] = floatstr(query);
  339. mysql_fetch_field_row(query, "int"); PlayerInfo[playerid][char_interior] = strval(query);
  340. mysql_fetch_field_row(query, "vw"); PlayerInfo[playerid][char_virtualworld] = strval(query);
  341. }
  342.  
  343. g_Logged[playerid] = 1;
  344. print("SpawnPlayer");
  345. SpawnPlayer(playerid);
  346. }
  347.  
  348. stock RegisterCharacter(playerid, rpass[])
  349. {
  350. new query[255], epass[129];
  351.  
  352. WP_Hash(epass, sizeof(epass), rpass);
  353.  
  354. 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);
  355. mysql_query(query);
  356.  
  357. LoginCharacter(playerid);
  358.  
  359. return 1;
  360. }
  361.  
  362. stock SaveCharacter(playerid)
  363. {
  364. new query[255], Float:pos[4];
  365.  
  366. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  367. GetPlayerFacingAngle(playerid, pos[3]);
  368. PlayerInfo[playerid][char_position][0] = pos[0];
  369. PlayerInfo[playerid][char_position][1] = pos[1];
  370. PlayerInfo[playerid][char_position][2] = pos[2];
  371. PlayerInfo[playerid][char_position][3] = pos[3];
  372.  
  373. 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],
  374. PlayerInfo[playerid][char_interior], PlayerInfo[playerid][char_virtualworld], GetName(playerid));
  375. mysql_query(query);
  376. printf("ID: %d / %s has been saved.", playerid, GetName(playerid));
  377. }
  378.  
  379. stock GetName(playerid)
  380. {
  381. new name[MAX_PLAYER_NAME];
  382. GetPlayerName(playerid,name,sizeof(name));
  383. for(new i = 0; i < MAX_PLAYER_NAME; i++)
  384. {
  385. if(name[i] == '_') name[i] = ' ';
  386. }
  387. return name;
  388. }
  389.  
  390. stock ReturnConnection()
  391. {
  392. if(mysql_ping() != -1)
  393. {
  394. printf("Connected with the MySQL server. PING: %d", mysql_ping());
  395. }
  396. else
  397. {
  398. print("Connection with the MySQL server has failed.");
  399. }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement