Guest User

Untitled

a guest
Jul 29th, 2016
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <a_mysql>
  7.  
  8.  
  9. main()
  10. {
  11. print("\n----------------------------------");
  12. print(" Blank Gamemode by your name here");
  13. print("----------------------------------\n");
  14. }
  15.  
  16. #define MYSQL_HOST "localhost"
  17. #define MYSQL_USER "root"
  18. #define MYSQL_DATABASE "samp_dynamic"
  19. #define MYSQL_PASSWORD ""
  20.  
  21. #define SPAWN_X 10.0
  22. #define SPAWN_Y 10.0
  23. #define SPAWN_Z 14.0
  24. #define SPAWN_A 0.0
  25. enum
  26. {
  27. LoginDialog,
  28. RegisterDialog
  29. };
  30. new
  31. mysql;
  32.  
  33. native WP_Hash(buffer[], len, const str[]);
  34.  
  35. enum PlayerData
  36. {
  37. ID,
  38. Name[MAX_PLAYER_NAME],
  39. Password[129],
  40. IP[16],
  41. Admin,
  42. VIP,
  43. Money,
  44. Float:posX,
  45. Float:posY,
  46. Float:posZ,
  47. Float:posA
  48. };
  49. new Player[MAX_PLAYERS][PlayerData];
  50.  
  51. public OnGameModeInit()
  52. {
  53. mysql_log(LOG_ALL);
  54. mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
  55. if(mysql_errno() != 0)
  56. {
  57. printf("[MySQL] The connection has failed.");
  58. }
  59. else
  60. {
  61. printf("[MySQL] The connection was successful.");
  62. }
  63. return true;
  64. }
  65.  
  66. public OnGameModeExit()
  67. {
  68. return 1;
  69. }
  70.  
  71. public OnPlayerRequestClass(playerid, classid)
  72. {
  73. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  74. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  75. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  76. return 1;
  77. }
  78.  
  79. public OnPlayerConnect(playerid)
  80. {
  81.  
  82. TogglePlayerSpectating(playerid, true);
  83. new
  84. query[128],
  85. playername[MAX_PLAYER_NAME];
  86.  
  87. GetPlayerName(playerid, playername, sizeof(playername));
  88. mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
  89. mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
  90. return true;
  91. }
  92. forward OnAccountCheck(playerid);
  93. public OnAccountCheck(playerid)
  94. {
  95. new
  96. rows,
  97. fields;
  98. cache_get_data(rows, fields, mysql);
  99.  
  100. if(rows)
  101. {
  102. cache_get_field_content(0, "Password", Player[playerid][Password], mysql, 129);
  103. Player[playerid][ID] = cache_get_field_content_int(0, "ID");
  104. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
  105. }
  106. else
  107. {
  108. ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
  109. }
  110. return true;
  111. }
  112.  
  113.  
  114. public OnPlayerDisconnect(playerid, reason)
  115. {
  116. new
  117. query[128],
  118. Float:pos[4];
  119.  
  120. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  121. GetPlayerFacingAngle(playerid, pos[3]);
  122.  
  123. mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
  124. GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
  125. mysql_tquery(mysql, query, "", "");
  126.  
  127. return true;
  128. }
  129. public OnPlayerSpawn(playerid)
  130. {
  131. return true;
  132. }
  133. public OnPlayerDeath(playerid, killerid, reason)
  134. {
  135. return 1;
  136. }
  137.  
  138. public OnVehicleSpawn(vehicleid)
  139. {
  140. return 1;
  141. }
  142.  
  143. public OnVehicleDeath(vehicleid, killerid)
  144. {
  145. return 1;
  146. }
  147.  
  148. public OnPlayerText(playerid, text[])
  149. {
  150. return 1;
  151. }
  152.  
  153. public OnPlayerCommandText(playerid, cmdtext[])
  154. {
  155. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  156. {
  157. // Do something here
  158. return 1;
  159. }
  160. return 0;
  161. }
  162.  
  163. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  164. {
  165. return 1;
  166. }
  167.  
  168. public OnPlayerExitVehicle(playerid, vehicleid)
  169. {
  170. return 1;
  171. }
  172.  
  173. public OnPlayerStateChange(playerid, newstate, oldstate)
  174. {
  175. return 1;
  176. }
  177.  
  178. public OnPlayerEnterCheckpoint(playerid)
  179. {
  180. return 1;
  181. }
  182.  
  183. public OnPlayerLeaveCheckpoint(playerid)
  184. {
  185. return 1;
  186. }
  187.  
  188. public OnPlayerEnterRaceCheckpoint(playerid)
  189. {
  190. return 1;
  191. }
  192.  
  193. public OnPlayerLeaveRaceCheckpoint(playerid)
  194. {
  195. return 1;
  196. }
  197.  
  198. public OnRconCommand(cmd[])
  199. {
  200. return 1;
  201. }
  202.  
  203. public OnPlayerRequestSpawn(playerid)
  204. {
  205. return 1;
  206. }
  207.  
  208. public OnObjectMoved(objectid)
  209. {
  210. return 1;
  211. }
  212.  
  213. public OnPlayerObjectMoved(playerid, objectid)
  214. {
  215. return 1;
  216. }
  217.  
  218. public OnPlayerPickUpPickup(playerid, pickupid)
  219. {
  220. return 1;
  221. }
  222.  
  223. public OnVehicleMod(playerid, vehicleid, componentid)
  224. {
  225. return 1;
  226. }
  227.  
  228. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  229. {
  230. return 1;
  231. }
  232.  
  233. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  234. {
  235. return 1;
  236. }
  237.  
  238. public OnPlayerSelectedMenuRow(playerid, row)
  239. {
  240. return 1;
  241. }
  242.  
  243. public OnPlayerExitedMenu(playerid)
  244. {
  245. return 1;
  246. }
  247.  
  248. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  249. {
  250. return 1;
  251. }
  252.  
  253. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  254. {
  255. return 1;
  256. }
  257.  
  258. public OnRconLoginAttempt(ip[], password[], success)
  259. {
  260. return 1;
  261. }
  262.  
  263. public OnPlayerUpdate(playerid)
  264. {
  265. return 1;
  266. }
  267.  
  268. public OnPlayerStreamIn(playerid, forplayerid)
  269. {
  270. return 1;
  271. }
  272.  
  273. public OnPlayerStreamOut(playerid, forplayerid)
  274. {
  275. return 1;
  276. }
  277.  
  278. public OnVehicleStreamIn(vehicleid, forplayerid)
  279. {
  280. return 1;
  281. }
  282.  
  283. public OnVehicleStreamOut(vehicleid, forplayerid)
  284. {
  285. return 1;
  286. }
  287.  
  288. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  289. {
  290. switch(dialogid)
  291. {
  292. case LoginDialog:
  293. {
  294. if(!response) Kick(playerid);
  295.  
  296. new
  297. hashpass[129],
  298. query[100],
  299. playername[MAX_PLAYER_NAME];
  300.  
  301. GetPlayerName(playerid, playername, sizeof(playername));
  302. WP_Hash(hashpass, sizeof(hashpass), inputtext);
  303. if(!strcmp(hashpass, Player[playerid][Password]))
  304. {
  305. mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
  306. mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
  307. }
  308. else
  309. {
  310. SendClientMessage(playerid, -1, "You have specified an incorrect password!");
  311. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
  312. }
  313. }
  314. case RegisterDialog:
  315. {
  316. if(!response) return Kick(playerid);
  317. if(strlen(inputtext) < 5)
  318. {
  319. SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");
  320. return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
  321. }
  322. new
  323. query[512],
  324. playername[MAX_PLAYER_NAME],
  325. playerip[16];
  326.  
  327.  
  328. GetPlayerName(playerid, playername, sizeof(playername));
  329. GetPlayerIp(playerid, playerip, sizeof(playerip));
  330. WP_Hash(Player[playerid][Password], 129, inputtext);
  331. mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f)", playername, Player[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A);
  332. mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
  333. }
  334. }
  335. return false; // For filterscripts..
  336. }
  337.  
  338. forward OnAccountLoad(playerid);
  339. public OnAccountLoad(playerid)
  340. {
  341. Player[playerid][Admin] = cache_get_field_content_int(0, "Admin");
  342. Player[playerid][VIP] = cache_get_field_content_int(0, "VIP");
  343. Player[playerid][Money] = cache_get_field_content_int(0, "Money");
  344. Player[playerid][posX] = cache_get_field_content_float(0, "PosX");
  345. Player[playerid][posY] = cache_get_field_content_float(0, "PosY");
  346. Player[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
  347. Player[playerid][posA] = cache_get_field_content_float(0, "PosA");
  348.  
  349. TogglePlayerSpectating(playerid, false);
  350.  
  351. GivePlayerMoney(playerid, Player[playerid][Money]);
  352.  
  353. SetSpawnInfo(playerid, 0, 23, Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
  354. SpawnPlayer(playerid);
  355.  
  356. SendClientMessage(playerid, -1, "You have successfully logged in.");
  357. return true;
  358. }
  359.  
  360. forward OnAccountRegister(playerid);
  361. public OnAccountRegister(playerid)
  362. {
  363. Player[playerid][ID] = cache_insert_id();
  364. printf("[Registration] New account registered. Database ID: [%d]", Player[playerid][ID]);
  365.  
  366. TogglePlayerSpectating(playerid, false);
  367.  
  368. SetSpawnInfo(playerid, 0, 23, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0, 0, 0, 0, 0, 0);
  369. SpawnPlayer(playerid);
  370. return true;
  371. }
  372.  
  373. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  374. {
  375. return 1;
  376. }
RAW Paste Data