Advertisement
Guest User

GX:RP

a guest
Aug 2nd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <a_mysql>
  4. #include <zcmd>
  5. #include <sscanf2>
  6.  
  7. /* MySQL Connection */
  8.  
  9. #define MySQL_Hostname "localhost" //This will be your mysql host. Default for xampp is localhost
  10. #define MySQL_Username "root" //This will be your mysql username. Default for xampp is root
  11. #define MySQL_Database "genx" //This is your database name. Remember we have created a database called server before.
  12. #define MySQL_Password "" //This is your mysql password. In xampp, the password didn't set. So leave it empty.
  13.  
  14. /* Dialog Definition */
  15.  
  16. #define DIALOG_REGISTER 1
  17. #define DIALOG_LOGIN 2
  18.  
  19. /* Colour Definition */
  20.  
  21. #define COLOR_WHITE 0xFFFFFFAA
  22. #define WHITE "{FFFFAA}"
  23. #define COLOR_GREY 0xAFAFAFAA
  24. #define GREY "{AFAFAA}"
  25. #define COLOR_LIGHTBLUE 0x33CCFFAA
  26. #define LIGHTBLUE "{CCFFAA}"
  27. #define COLOR_RED 0xAA3333AA
  28. #define RED "{FF0000}"
  29.  
  30. /* Starter Accounts */
  31.  
  32. #define starterCash 400
  33.  
  34. /* End of Definitions */
  35.  
  36. static dbHandle;
  37.  
  38. native WP_Hash(buffer[], len, const str[]); //Whirlpool
  39.  
  40. enum PlayerData
  41. {
  42. ID,
  43. Name,
  44. Password,
  45. Cash
  46. }
  47. new PlayerInfo[MAX_PLAYERS][PlayerData];
  48.  
  49. main()
  50. {
  51. }
  52.  
  53. public OnGameModeInit()
  54. {
  55. // Don't use these lines if it's a filterscript
  56. SetGameModeText("GenX:RP");
  57. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  58.  
  59. mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
  60. dbHandle = mysql_connect(MySQL_Hostname, MySQL_Username, MySQL_Database, MySQL_Password);
  61. if(mysql_errno(dbHandle) != 0)
  62. {
  63. printf("[-- Could not establish a MySQL connection! --]");
  64. }
  65. else
  66. {
  67. printf("[-- Established a successful MySQL connection! --]");
  68. }
  69. return 1;
  70. }
  71.  
  72. public OnGameModeExit()
  73. {
  74. mysql_close(dbHandle);
  75. return 1;
  76. }
  77.  
  78. public OnPlayerRequestClass(playerid, classid)
  79. {
  80. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  81. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  82. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  83. return 1;
  84. }
  85.  
  86. public OnPlayerConnect(playerid)
  87. {
  88. if(dbHandle)
  89. {
  90. new query[128], playerName[MAX_PLAYER_NAME];
  91. GetPlayerName(playerid, playerName, sizeof(playerName));
  92. mysql_format(dbHandle, query, sizeof(query), "SELECT `ID`, `Name` FROM `players` WHERE `Name` = '%s' LIMIT 1", playerName);
  93. mysql_tquery(dbHandle, query, "CheckAccount", "i", playerid);
  94. }
  95. else
  96. {
  97. SendClientMessage(playerid, COLOR_RED, "Error"WHITE": Could not establish a connection to our server.");
  98. Kick(playerid);
  99. }
  100. return 1;
  101. }
  102.  
  103. public OnPlayerDisconnect(playerid, reason)
  104. {
  105. return 1;
  106. }
  107.  
  108. public OnPlayerSpawn(playerid)
  109. {
  110. return 1;
  111. }
  112.  
  113. public OnPlayerDeath(playerid, killerid, reason)
  114. {
  115. return 1;
  116. }
  117.  
  118. public OnVehicleSpawn(vehicleid)
  119. {
  120. return 1;
  121. }
  122.  
  123. public OnVehicleDeath(vehicleid, killerid)
  124. {
  125. return 1;
  126. }
  127.  
  128. public OnPlayerText(playerid, text[])
  129. {
  130. return 1;
  131. }
  132.  
  133. public OnPlayerCommandText(playerid, cmdtext[])
  134. {
  135. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  136. {
  137. // Do something here
  138. return 1;
  139. }
  140. return 0;
  141. }
  142.  
  143. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  144. {
  145. return 1;
  146. }
  147.  
  148. public OnPlayerExitVehicle(playerid, vehicleid)
  149. {
  150. return 1;
  151. }
  152.  
  153. public OnPlayerStateChange(playerid, newstate, oldstate)
  154. {
  155. return 1;
  156. }
  157.  
  158. public OnPlayerEnterCheckpoint(playerid)
  159. {
  160. return 1;
  161. }
  162.  
  163. public OnPlayerLeaveCheckpoint(playerid)
  164. {
  165. return 1;
  166. }
  167.  
  168. public OnPlayerEnterRaceCheckpoint(playerid)
  169. {
  170. return 1;
  171. }
  172.  
  173. public OnPlayerLeaveRaceCheckpoint(playerid)
  174. {
  175. return 1;
  176. }
  177.  
  178. public OnRconCommand(cmd[])
  179. {
  180. return 1;
  181. }
  182.  
  183. public OnPlayerRequestSpawn(playerid)
  184. {
  185. return 1;
  186. }
  187.  
  188. public OnObjectMoved(objectid)
  189. {
  190. return 1;
  191. }
  192.  
  193. public OnPlayerObjectMoved(playerid, objectid)
  194. {
  195. return 1;
  196. }
  197.  
  198. public OnPlayerPickUpPickup(playerid, pickupid)
  199. {
  200. return 1;
  201. }
  202.  
  203. public OnVehicleMod(playerid, vehicleid, componentid)
  204. {
  205. return 1;
  206. }
  207.  
  208. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  209. {
  210. return 1;
  211. }
  212.  
  213. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  214. {
  215. return 1;
  216. }
  217.  
  218. public OnPlayerSelectedMenuRow(playerid, row)
  219. {
  220. return 1;
  221. }
  222.  
  223. public OnPlayerExitedMenu(playerid)
  224. {
  225. return 1;
  226. }
  227.  
  228. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  229. {
  230. return 1;
  231. }
  232.  
  233. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  234. {
  235. return 1;
  236. }
  237.  
  238. public OnRconLoginAttempt(ip[], password[], success)
  239. {
  240. return 1;
  241. }
  242.  
  243. public OnPlayerUpdate(playerid)
  244. {
  245. return 1;
  246. }
  247.  
  248. public OnPlayerStreamIn(playerid, forplayerid)
  249. {
  250. return 1;
  251. }
  252.  
  253. public OnPlayerStreamOut(playerid, forplayerid)
  254. {
  255. return 1;
  256. }
  257.  
  258. public OnVehicleStreamIn(vehicleid, forplayerid)
  259. {
  260. return 1;
  261. }
  262.  
  263. public OnVehicleStreamOut(vehicleid, forplayerid)
  264. {
  265. return 1;
  266. }
  267.  
  268. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  269. {
  270. if (dialogid == DIALOG_REGISTER)
  271. {
  272. if (response)
  273. {
  274. if(strlen(inputtext) < 11 || strlen(inputtext) > 29 )
  275. {
  276. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", ""RED"Your password must be between 11 and 29 characters long.\n"WHITE"Choose and enter a password:", "Register", "Quit");
  277. }
  278. else
  279. {
  280. new query[300];
  281. new playerName[MAX_PLAYER_NAME];
  282. GetPlayerName(playerid, playerName, sizeof(playerName));
  283. WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
  284.  
  285. mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `players` (`Name`, `Password`, `Cash`) VALUES ('%s', '%s', %d)", playerName, PlayerInfo[playerid][Password], starterCash);
  286. mysql_tquery(dbHandle, query, "RegisterAccount", "i", playerid);
  287.  
  288. mysql_format(dbHandle, query, sizeof(query), "SELECT `ID`, `Name`, `Password`, `Cash` FROM `players` WHERE `Name` = '%s'", playerName);
  289. mysql_tquery(dbHandle, query, "RegisterAccount", "i", playerid);
  290. }
  291. }
  292. else
  293. {
  294. Kick(playerid);
  295. }
  296. }
  297. return 1;
  298. }
  299.  
  300. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  301. {
  302. return 1;
  303. }
  304.  
  305. forward CheckAccount(playerid);
  306. public CheckAccount(playerid)
  307. {
  308. new rows, fields;
  309. cache_get_data(rows, fields, dbHandle);
  310.  
  311. if(rows)
  312. {
  313. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome back!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
  314. }
  315. else
  316. {
  317. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered. Choose and enter a password:", "Register", "Quit");
  318. }
  319. return 1;
  320. }
  321.  
  322. forward RegisterAccount(playerid);
  323. public RegisterAccount(playerid)
  324. {
  325. new string[128];
  326.  
  327. PlayerInfo[playerid][ID] = cache_get_field_content_int(1, "ID");
  328. cache_get_field_content(2, "Name", PlayerInfo[playerid][Name], dbHandle, 129);
  329. cache_get_field_content(3, "Password", PlayerInfo[playerid][Password], dbHandle, 129);
  330. PlayerInfo[playerid][Cash] = cache_get_field_content_int(4, "Cash");
  331.  
  332. format(string, sizeof(string), "ID: %d, Name: '%s', Password: '%s', Cash: %d", PlayerInfo[playerid][ID], PlayerInfo[playerid][Name], PlayerInfo[playerid][Password], PlayerInfo[playerid][Cash]);
  333. SendClientMessage(playerid, -1, string);
  334. return 1;
  335. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement