Advertisement
Guest User

Untitled

a guest
Nov 4th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. //Baza de date
  2.  
  3. #define mysql_host "localhost"
  4. #define mysql_db "gamemode"
  5. #define mysql_user "root"
  6. #define mysql_pass ""
  7.  
  8. //Include
  9.  
  10. #include <a_samp>
  11. #include <a_actor>
  12. #include <a_mysql>
  13. #include <zcmd>
  14.  
  15. //Define
  16.  
  17. #define SCM SendClientMessage
  18.  
  19. //Define Culori
  20.  
  21. #define COLOR_WHITE 0xFFFFFF
  22. #define COLOR_RED 0xFC1F1FFF
  23. #define COLOR_YELLOW 0xF3F930FF
  24. #define COLOR_ORANGE 0xFBAB09FF
  25. #define COLOR_BLUE 0x2F3CFAFF
  26. #define COLOR_PINK 0xF92AB0FF
  27. #define COLOR_GREEN 0x5EF73FFF
  28.  
  29. //Variabile
  30.  
  31. new ActorBonus;
  32. new handle;
  33.  
  34. //Enum
  35.  
  36. enum pInfo
  37. {
  38. pID,
  39. pPassword,
  40. pSex,
  41. pAge,
  42. pEmail,
  43. pLevel,
  44. pRP,
  45. pAdmin,
  46. pHelper
  47. }
  48.  
  49. //Enum Dialog
  50. new P_Data[MAX_PLAYERS][pInfo];
  51.  
  52. enum
  53. {
  54. DIALOG_REGISTER,
  55. DIALOG_LOGIN,
  56. DIALOG_SEX,
  57. DIALOG_AGE,
  58. DIALOG_EMAIL,
  59. DIALOG_WELCOME
  60. }
  61.  
  62. //Define Dialog
  63.  
  64. #define DIALOG_REIGSTER 1
  65. #define DIALOG_LOGIN 2
  66.  
  67. main()
  68. {
  69. print("\n----------------------------------");
  70. print("Nu dau teapa, eu zic ca merge ca trebuie :)");
  71. print("----------------------------------\n");
  72. }
  73.  
  74. public OnGameModeInit()
  75. {
  76. MySQLConnect();
  77. EnableStuntBonusForAll(0);
  78. DisableInteriorEnterExits();
  79. UsePlayerPedAnims();
  80. ActorBonus = CreateActor(250, 1828.9287,-1875.0154,13.5600,88.8360);
  81. SetActorInvulnerable(ActorBonus , true);
  82. ApplyActorAnimation(ActorBonus , "COP_AMBIENT", "Coplook_loop", 4.0, 0, 1, 1, 1, -1);
  83. Create3DTextLabel("Salut, vino aici si ia bonusul de venit.\nFoloseste comanda [/bonus] pentru a-l lua!", COLOR_WHITE, 1828.9287,-1875.0154,13.5600, 30.0, 0, 0);
  84. SetGameModeText("RPG V0.1");
  85. AddPlayerClass(292,1814.5961,-1897.8883,13.5775,322.1244, 0, 0, 0, 0, 0,0);
  86. return 1;
  87. }
  88.  
  89. public OnGameModeExit()
  90. {
  91. mysql_close(handle);
  92. return 1;
  93. }
  94.  
  95. public OnPlayerRequestClass(playerid, classid)
  96. {
  97. return 1;
  98. }
  99.  
  100. public OnPlayerConnect(playerid)
  101. {
  102. new query[100];
  103. mysql_format(handle, query, sizeof(query), "SELECT * FROM conturi WHERE Name = '%s'", GetName(playerid));
  104. mysql_tquery(handle, query, "OnPlayerLogin", "i", playerid);
  105. return 1;
  106. }
  107.  
  108. public OnPlayerDisconnect(playerid, reason)
  109. {
  110. return 1;
  111. }
  112.  
  113. public OnPlayerSpawn(playerid)
  114. {
  115. return 1;
  116. }
  117.  
  118. public OnPlayerDeath(playerid, killerid, reason)
  119. {
  120. return 1;
  121. }
  122.  
  123. public OnVehicleSpawn(vehicleid)
  124. {
  125. return 1;
  126. }
  127.  
  128. public OnVehicleDeath(vehicleid, killerid)
  129. {
  130. return 1;
  131. }
  132.  
  133. public OnPlayerText(playerid, text[])
  134. {
  135. return 1;
  136. }
  137.  
  138. public OnPlayerCommandText(playerid, cmdtext[])
  139. {
  140. return 1;
  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. new query[128], ip[25];// se creaza interogarea si ip.
  271. switch(dialogid)// se va folosi switch pentru a selecta dialogul
  272. {
  273. case DIALOG_REGISTER:// daca se va selecta dialogul register
  274. {
  275. if(!response)
  276. return Kick(playerid);// daca se va apasa pe butonul Exit ii va da kick
  277. if(response)// daca se apasa pe Butonul inregistrare se vor face urmatoarele verificari
  278. {
  279. if(!strlen(inputtext))// daca nu e scris nimic la parola
  280. return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Introdu-ti o parola pentru a te inregistra pe server! n", "Inregistreaza", "Exit");// ii va da din nou dialogul register cu mesajul specific
  281.  
  282. GetPlayerIp(playerid, ip, sizeof(ip));// definim ip-ul de mai sus
  283. mysql_format(handle, query, sizeof(query), "INSERT INTO conturi (Name, Password, IP) VALUES ('%s', '%e', '%s')", GetName(playerid), inputtext, ip);// se insereaza in tabelul cu conturi numele playerului, parola pe care a scris-o si ip pe care il are
  284. mysql_query(handle, query);// se va trimite setarile si se va interoga callback-ul OnRegistration
  285. SpawnPlayer(playerid); // ii da spawn
  286. }
  287. return 1;
  288. }
  289. case DIALOG_LOGIN:// daca se va selecta dialogul de login
  290. {
  291. if(!response) return Kick(playerid);// si se va apasa pe butonul exit ii va da kick
  292. if(response)//daca se apasa pe butonul LOGARE se va face urmatoarele verificari
  293. {
  294. if(!strlen(inputtext))// daca nu a scris nimic la parola
  295. return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Exit");// ii va da dialogul cu login cu mesajul specific
  296. mysql_format(handle, query, sizeof(query), "SELECT * FROM `users` WHERE `Name`='%e' AND `Password` = '%e'", GetName(playerid),inputtext);// va fi selectata parola de la tabelul cu conturi
  297. mysql_tquery(handle, query, "OnLogin", "i", playerid);// se va face apel la baza si se va interoga CallBackUl OnLogin (Tquery = take query sau ia interogare in romana)
  298. }
  299. return 1;
  300. }
  301. }
  302. return 1;
  303. }
  304.  
  305. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  306. {
  307. return 1;
  308. }
  309.  
  310. forward OnPlayerLogin(playerid);// se creaza callbac-ul
  311. public OnPlayerLogin(playerid)//Se creaza publicul
  312. {
  313. new rows, fields;// definim rows(randurile)si fields(domeniile)
  314. cache_get_data(rows, fields);//cache_get_data interogheaza date din baza de date. acele date sunt rows si fields
  315. if(rows)// atunci cand playerul se inregistreaza i se va crea niste randuri. Daca i se gasesc atunci cand se va conecta ii va da:
  316. {
  317. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "Te rog sa-ti introduci parola contuului mai jos!", "Logare", "Exit");// dialogul register
  318. }
  319. else// daca nu i se gasesc randuri, adica daca contul nu exista, atunci i se va da urmatorul dialog
  320. {
  321. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Inregistrare", "Trebuie sa iti creezi un cont ca sa joci pe server.\nTasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Exit");// dialogul register
  322. }
  323. return 1;
  324. }
  325.  
  326. forward OnLogin(playerid);// definim callback ul
  327. public OnLogin(playerid)// facem publicul
  328. {
  329. new rows, fields,temporar[200];
  330. cache_get_data(rows, fields);
  331. if(rows)
  332. {
  333. //deci daca are randuri
  334. cache_get_field_content(0, "Password",temporar), format(P_Data[playerid][pPassword], 25, temporar);// i se vaextrage parola si i se verifica daca coincide cu numele. Se foloseste new-ul temporar pentru extragerea parolei, ea retinandu-se temporar(pana cand se deconecteaza jucatorul)
  335. P_Data[playerid][pID] = cache_get_field_content_int(0, "ID");
  336. SpawnPlayer(playerid);// si se va da spawn
  337. }
  338. else
  339. {
  340. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Exit");// ii va da dialogul cu mesajul specific.
  341. }
  342. return 1;
  343. }
  344.  
  345. forward MySQLConnect();
  346. public MySQLConnect()
  347. {
  348. handle = mysql_connect("localhost", "root", "gamemode", "");
  349. if(mysql_errno() != 0)
  350. {
  351. printf("Conexiunea la baza de date %s a esuat ---> Server Inchis ~~~", mysql_db);
  352. SendRconCommand("exit");
  353. }
  354. else
  355. {
  356. printf("Conexiunea la baza de date '%s' cu user-ul '%s' a reusit!!!", mysql_db, mysql_user);
  357. }
  358. return 1;
  359. }
  360.  
  361. stock GetName(playerid)
  362. {
  363. new Name[MAX_PLAYER_NAME + 1];
  364. GetPlayerName(playerid, Name, sizeof(Name));
  365. return Name;
  366. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement