Guest User

Untitled

a guest
Jan 29th, 2019
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.72 KB | None | 0 0
  1. #include <a_samp>
  2. // change MAX_PLAYERS to the amount of players (slots) you want
  3. // It is by default 1000 (as of 0.3.7 version)
  4. #undef MAX_PLAYERS
  5. #define MAX_PLAYERS 50
  6. //----------
  7. // INCLUDE
  8. #include <a_mysql>
  9. #include <zcmd>
  10. #include <sscanf2>
  11.  
  12.  
  13. // Define
  14. // stili dialogo
  15. #define d_input DIALOG_STYLE_INPUT
  16. #define d_list DIALOG_STYLE_LIST
  17.  
  18. // Configurazione MySQL
  19. #define MYSQL_HOST "127.0.0.1"
  20. #define MYSQL_USER "root"
  21. #define MYSQL_PASSWORD "Pass123!"
  22. #define MYSQL_DATABASE "dbrp"
  23.  
  24. //-------------
  25. // info server
  26. #define emailserver "asd@gmail.com"
  27. #define nomeserver "server bello"
  28.  
  29. //-----------------------
  30.  
  31. // Textdraw
  32. new Text:AdminInDuty;
  33.  
  34. // domande di sicurezza
  35. // per modificare la password con il comando /cambia -> password
  36. #define MAX_SECURITY_QUESTION_SIZE 128
  37.  
  38.  
  39. // colori
  40. // system color
  41. #define COLOR_SYSTEM_ERROR 0xAA3333AA
  42. #define COLOR_SYSTEM_TITLE 0xFFFFFFAA
  43. #define COLOR_SYSTEM_TEXT 0xFFFFFFAA
  44. #define COLOR_SYSTEM_SUCCESS 0x33AA33AA
  45. #define COLOR_SYSTEM_INFO 0xAFAFAFAA
  46. #define COLOR_SYSTEM_ADMIN 0xFFFF00AA
  47.  
  48. #define COL_STRING_ERROR "{FF0000}"
  49. #define COL_STRING_SUCCESS "{00FF00}"
  50. #define COLOR_RED 0xFF0000
  51. #define COLOR_INFO 0xAFAFAF
  52. #define COLOR_WHITE (0xFFFFFFFF)
  53. #define COL_WHITE "{FFFFFF}"
  54. #define COLOR_TOMATO (0xFF6347FF)
  55. #define COL_TOMATO "{FF6347}"
  56. #define COLOR_YELLOW (0xFFDD00FF)
  57. #define COL_YELLOW "{FFDD00}"
  58. #define COLOR_GREEN (0x00FF00FF)
  59. #define COL_GREEN "{00FF00}"
  60. #define COLOR_DEFAULT (0xA9C4E4FF)
  61. #define COL_DEFAULT "{A9C4E4}"
  62.  
  63. // how many seconds until it kicks the player for taking too long to login
  64. #define SECONDS_TO_LOGIN 30
  65. #define NAME_CHECKER1 30
  66.  
  67. // Spawn default dopo la registrazione
  68. #define DEFAULT_POS_X -1965.3541
  69. #define DEFAULT_POS_Y 158.4787
  70. #define DEFAULT_POS_Z 27.6940
  71. #define DEFAULT_POS_A 90.0000
  72. #define DEFAULT_POS_INTERIOR 0
  73. /* Es: Las Venturas
  74. #define DEFAULT_POS_X 1958.3783
  75. #define DEFAULT_POS_Y 1343.1572
  76. #define DEFAULT_POS_Z 15.3746
  77. #define DEFAULT_POS_A 270.1425
  78. #define DEFAULT_POS_INTERIOR 0
  79. */
  80. // MySQL connection handle
  81. new MySQL: g_SQL;
  82.  
  83. // player data
  84. enum E_PLAYERS
  85. {
  86. ID,
  87. Name[MAX_PLAYER_NAME],
  88. Password[65], // the output of SHA256_PassHash function (which was added in 0.3.7 R1 version) is always 256 bytes in length, or the equivalent of 64 Pawn cells
  89. Salt[17],
  90. Kills,
  91. Admin,
  92. Age,
  93. ADuty,
  94. Sex,
  95. Soldi,
  96. PatenteA[64],
  97. PatenteB[64],
  98. PatenteC[64],
  99. PatenteD[64],
  100. PortoDarmi[64],
  101. Deaths,
  102. Float:Vita,
  103. Float:Armatura,
  104. e_USER_SECURITY_QUESTION[MAX_SECURITY_QUESTION_SIZE],
  105. e_USER_SECURITY_ANSWER[64],
  106. PlayerEmail[64],
  107. Float: X_Pos,
  108. Float: Y_Pos,
  109. Float: Z_Pos,
  110. Float: A_Pos,
  111. Interior,
  112.  
  113. Cache: Cache_ID,
  114. bool: IsLoggedIn,
  115. LoginAttempts,
  116. LoginTimer
  117. };
  118. new Player[MAX_PLAYERS][E_PLAYERS];
  119.  
  120. new g_MysqlRaceCheck[MAX_PLAYERS];
  121.  
  122. // dialog data
  123. enum
  124. {
  125. DIALOG_UNUSED,
  126. DIALOG_LOGIN,
  127. DIALOG_REGISTER,
  128. DIALOG_REGISTER_AGE,
  129. DIALOG_REGISTER_SEX,
  130. DIALOG_REGISTER_EMAIL,
  131. DIALOG_REGISTER_DOMANDASEC,
  132. DIALOG_REGISTER_RISPOSTASEC,
  133. DIALOG_PROVA
  134. };
  135.  
  136. // protocollo controllo nome RP
  137. stock RPnamecheck(playerid)
  138. {
  139. new pname[MAX_PLAYER_NAME],underline=0;
  140. GetPlayerName(playerid, pname, sizeof(pname));
  141. if(strfind(pname,"[",true) != (-1)) return 0;
  142. else if(strfind(pname,"]",true) != (-1)) return 0;
  143. else if(strfind(pname,"$",true) != (-1)) return 0;
  144. else if(strfind(pname,"(",true) != (-1)) return 0;
  145. else if(strfind(pname,")",true) != (-1)) return 0;
  146. else if(strfind(pname,"=",true) != (-1)) return 0;
  147. else if(strfind(pname,"@",true) != (-1)) return 0;
  148. else if(strfind(pname,"1",true) != (-1)) return 0;
  149. else if(strfind(pname,"2",true) != (-1)) return 0;
  150. else if(strfind(pname,"3",true) != (-1)) return 0;
  151. else if(strfind(pname,"4",true) != (-1)) return 0;
  152. else if(strfind(pname,"5",true) != (-1)) return 0;
  153. else if(strfind(pname,"6",true) != (-1)) return 0;
  154. else if(strfind(pname,"7",true) != (-1)) return 0;
  155. else if(strfind(pname,"8",true) != (-1)) return 0;
  156. else if(strfind(pname,"9",true) != (-1)) return 0;
  157. else if(strfind(pname,"fuck",true) != (-1)) return 0;
  158. else if(strfind(pname,"FUCK",true) != (-1)) return 0;
  159. else if(strfind(pname,"Boobies",true) != (-1)) return 0;
  160. else if(strfind(pname,"Tupac_Shakur",true) != (-1)) return 0;
  161. else if(strfind(pname,"Pussy",true) != (-1)) return 0;
  162. else if(strfind(pname,"Rape",true) != (-1)) return 0;
  163. else if(strfind(pname,"kill",true) != (-1)) return 0;
  164. else if(strfind(pname,"shit",true) != (-1)) return 0;
  165. else if(strfind(pname,"ass",true) != (-1)) return 0;
  166. else if(strfind(pname,"Jack_Black",true) != (-1)) return 0;
  167. else if(strfind(pname,"Max_Kenton",true) != (-1)) return 0;
  168. else if(strfind(pname,"Will_Smith",true) != (-1)) return 0;
  169. else if(strfind(pname,"Jaden_Smith",true) != (-1)) return 0;
  170. else if(strfind(pname,"Megan_Fox",true) != (-1)) return 0;
  171. else if(strfind(pname,"Charlie_Kenton",true) != (-1)) return 0;
  172. else if(strfind(pname,"Hugh_Hefner",true) != (-1)) return 0;
  173. else if(strfind(pname,"Paris_Hilton",true) != (-1)) return 0;
  174. else if(strfind(pname,"Marshall_Mathers",true) != (-1)) return 0;
  175. else if(strfind(pname,"Sheldon_Cooper",true) != (-1)) return 0;
  176. else if(strfind(pname,"Jet_Lee",true) != (-1)) return 0;
  177. else if(strfind(pname,"Jackie_Chan",true) != (-1)) return 0;
  178. else if(strfind(pname,"Chuck_Norris",true) != (-1)) return 0;
  179. else if(strfind(pname,"Peter_Parker",true) != (-1)) return 0;
  180. else if(strfind(pname,"Spider_Man",true) != (-1)) return 0;
  181. else if(strfind(pname,"Bat_Man",true) != (-1)) return 0;
  182. else if(strfind(pname,"Emma_Stone",true) != (-1)) return 0;
  183. else if(strfind(pname,"whore",true) != (-1)) return 0;
  184. else if(strfind(pname,"Hugh_Jackman",true) != (-1)) return 0;
  185. else if(strfind(pname,"Charles_Kenton",true) != (-1)) return 0;
  186. else if(strfind(pname,"Harry_Potter",true) != (-1)) return 0;
  187. else if(strfind(pname,"Chris_Hemsworth",true) != (-1)) return 0;
  188. else if(strfind(pname,"Penis",true) != (-1)) return 0;
  189. else if(strfind(pname,"_Dick",true) != (-1)) return 0;
  190. else if(strfind(pname,"Vagina",true) != (-1)) return 0;
  191. else if(strfind(pname,"Cock",true) != (-1)) return 0;
  192. else if(strfind(pname,"Rectum",true) != (-1)) return 0;
  193. else if(strfind(pname,"Sperm",true) != (-1)) return 0;
  194. else if(strfind(pname,"Rektum",true) != (-1)) return 0;
  195. else if(strfind(pname,"Pistol",true) != (-1)) return 0;
  196. else if(strfind(pname,"AK47",true) != (-1)) return 0;
  197. else if(strfind(pname,"Shotgun",true) != (-1)) return 0;
  198. else if(strfind(pname,"Cum",true) != (-1)) return 0;
  199. else if(strfind(pname,"Hitler",true) != (-1)) return 0;
  200. else if(strfind(pname,"Jesus",true) != (-1)) return 0;
  201. else if(strfind(pname,"God",true) != (-1)) return 0;
  202. else if(strfind(pname,"Shotgun",true) != (-1)) return 0;
  203. else if(strfind(pname,"Desert_Eagle",true) != (-1)) return 0;
  204. else if(strfind(pname,"fucker",true) != (-1)) return 0;
  205. else if(strfind(pname,"Retard",true) != (-1)) return 0;
  206. else if(strfind(pname,"Tarded",true) != (-1)) return 0;
  207. else if(strfind(pname,"fanny",true) != (-1)) return 0;
  208. else if(strfind(pname,"Daniel_Hardy",true) != (-1)) return 0;
  209. else if(strfind(pname,"abcdefghijklmnopqrstuvwxyz",true) != (-1)) return 0;
  210. new maxname = strlen(pname);
  211. for(new i=0; i<maxname; i++)
  212. {
  213. if(pname[i] == '_') underline ++;
  214. }
  215. if(underline != 1) return 0;
  216. pname[0] = toupper(pname[0]);
  217. for(new x=1; x<maxname; x++)
  218. {
  219. if(pname[x] == '_') pname[x+1] = toupper(pname[x+1]);
  220. else if(pname[x] != '_' && pname[x-1] != '_') pname[x] = tolower(pname[x]);
  221. }
  222. SetPlayerName(playerid, "New_Name");
  223. SetPlayerName(playerid, pname);
  224. return 1;
  225. }
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. main() {}
  233.  
  234.  
  235. public OnGameModeInit()
  236. {
  237. new MySQLOpt: option_id = mysql_init_options();
  238.  
  239. mysql_set_option(option_id, AUTO_RECONNECT, true); // it automatically reconnects when loosing connection to mysql server
  240.  
  241. g_SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, option_id); // AUTO_RECONNECT is enabled for this connection handle only
  242. if (g_SQL == MYSQL_INVALID_HANDLE || mysql_errno(g_SQL) != 0)
  243. {
  244. print("MySQL connection failed. Server is shutting down.");
  245. SendRconCommand("exit"); // close the server if there is no connection
  246. return 1;
  247. }
  248. new infomysql[128];
  249.  
  250. print("[MySQL] - Connessione con successo al MySQL.");
  251. format(infomysql, sizeof(infomysql), "[MySQL] - MySQL connesso all'host '%s'", MYSQL_HOST);
  252. print(infomysql);
  253.  
  254. format(infomysql, sizeof(infomysql), "[MySQL] - Utente collegato '%s'", MYSQL_USER);
  255. print(infomysql);
  256.  
  257. format(infomysql, sizeof(infomysql), "[MySQL] - Password utilizzata '%s'", MYSQL_PASSWORD);
  258. print(infomysql);
  259.  
  260. format(infomysql, sizeof(infomysql), "[MySQL] - Connesso al database '%s' con successo", MYSQL_DATABASE);
  261. print(infomysql);
  262.  
  263.  
  264. // TextDraws
  265. AdminInDuty = TextDrawCreate(102.606338, 313.833496, "ADMIN ON");
  266. TextDrawLetterSize(AdminInDuty, 0.506222, 1.518333);
  267. TextDrawAlignment(AdminInDuty, 3);
  268. TextDrawColor(AdminInDuty, -1);
  269. TextDrawUseBox(AdminInDuty, true);
  270. TextDrawBoxColor(AdminInDuty, 255);
  271. TextDrawSetShadow(AdminInDuty, 0);
  272. TextDrawSetOutline(AdminInDuty, 0);
  273. TextDrawBackgroundColor(AdminInDuty, 41215);
  274. TextDrawFont(AdminInDuty, 1);
  275. TextDrawSetProportional(AdminInDuty, 1);
  276.  
  277.  
  278.  
  279.  
  280. // if the table has been created, the "SetupPlayerTable" function does not have any purpose so you may remove it completely
  281. SetupPlayerTable();
  282. return 1;
  283. }
  284.  
  285. public OnGameModeExit()
  286. {
  287. // save all player data before closing connection
  288. for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // GetPlayerPoolSize function was added in 0.3.7 version and gets the highest playerid currently in use on the server
  289. {
  290. if (IsPlayerConnected(i))
  291. {
  292. // reason is set to 1 for normal 'Quit'
  293. OnPlayerDisconnect(i, 1);
  294. }
  295. }
  296.  
  297. mysql_close(g_SQL);
  298. return 1;
  299. }
  300.  
  301. // quando l'utente si connette al server
  302. public OnPlayerConnect(playerid)
  303. {
  304. if(!RPnamecheck(playerid))
  305. {
  306. SetTimerEx("KickTimerNameRP", 3000, 0, "d", playerid);
  307. SetPlayerPos(playerid, 982.1890, -1624.2583, 14.9526);
  308. SetPlayerFacingAngle(playerid, 90);
  309. new string[128], pname[MAX_PLAYER_NAME];
  310. GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
  311. format(string, sizeof(string), "{FF0000}[INFO] Devi inserire un nome {00FF00}RP per entrare nel server");
  312. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, string);
  313. format(string, sizeof(string), "{AFAFAF}Il nome {FF0000}%s non è valido.{AFAFAF} (devi usare tipo {00FF00}Nome_Cognome{AFAFAF})", Player[playerid][Name]);
  314. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, string);
  315. }
  316. else if(RPnamecheck(playerid))
  317. {
  318. g_MysqlRaceCheck[playerid]++;
  319. // reset player data
  320. static const empty_player[E_PLAYERS];
  321. Player[playerid] = empty_player;
  322.  
  323. GetPlayerName(playerid, Player[playerid][Name], MAX_PLAYER_NAME);
  324.  
  325. // send a query to recieve all the stored player data from the table
  326. new query[103];
  327. mysql_format(g_SQL, query, sizeof query, "SELECT * FROM `players` WHERE `username` = '%e' LIMIT 1", Player[playerid][Name]);
  328. mysql_tquery(g_SQL, query, "OnPlayerDataLoaded", "dd", playerid, g_MysqlRaceCheck[playerid]);
  329. }
  330. return 1;
  331. }
  332.  
  333. public OnPlayerDisconnect(playerid, reason)
  334. {
  335. g_MysqlRaceCheck[playerid]++;
  336.  
  337. UpdatePlayerData(playerid, reason);
  338. UpdatePlayerWeapons(playerid);
  339.  
  340. // if the player was kicked (either wrong password or taking too long) during the login part, remove the data from the memory
  341. if (cache_is_valid(Player[playerid][Cache_ID]))
  342. {
  343. cache_delete(Player[playerid][Cache_ID]);
  344. Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
  345. }
  346.  
  347. // if the player was kicked before the time expires (30 seconds), kill the timer
  348. if (Player[playerid][LoginTimer])
  349. {
  350. KillTimer(Player[playerid][LoginTimer]);
  351. Player[playerid][LoginTimer] = 0;
  352. }
  353.  
  354. // sets "IsLoggedIn" to false when the player disconnects, it prevents from saving the player data twice when "gmx" is used
  355. Player[playerid][IsLoggedIn] = false;
  356. return 1;
  357. }
  358.  
  359. public OnPlayerSpawn(playerid)
  360. {
  361. // spawn the player to their last saved position
  362. SetPlayerInterior(playerid, Player[playerid][Interior]);
  363. SetPlayerPos(playerid, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos]);
  364. SetPlayerFacingAngle(playerid, Player[playerid][A_Pos]);
  365.  
  366. SetCameraBehindPlayer(playerid);
  367. return 1;
  368. }
  369.  
  370. public OnPlayerDeath(playerid, killerid, reason)
  371. {
  372. UpdatePlayerDeaths(playerid);
  373. UpdatePlayerKills(killerid);
  374. return 1;
  375. }
  376.  
  377.  
  378. //-------------------------------------------
  379. // dialoghi
  380. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  381. {
  382.  
  383. new const SECURITY_QUESTIONS[][MAX_SECURITY_QUESTION_SIZE] =
  384. {
  385. "What was your childhood nickname?",
  386. "What is the name of your favorite childhood friend?",
  387. "In what city or town did your mother and father meet?",
  388. "What is the middle name of your oldest child?",
  389. "What is your favorite team?",
  390. "What is your favorite movie?",
  391. "What is the first name of the boy or girl that you first kissed?",
  392. "What was the make and model of your first car?",
  393. "What was the name of the hospital where you were born?",
  394. "Who is your childhood sports hero?",
  395. "In what town was your first job?",
  396. "What was the name of the company where you had your first job?",
  397. "What school did you attend for sixth grade?",
  398. "What was the last name of your third grade teacher?"
  399. };
  400.  
  401. switch (dialogid)
  402. {
  403. case DIALOG_UNUSED: return 1; // Useful for dialogs that contain only information and we do nothing depending on whether they responded or not
  404.  
  405. case DIALOG_LOGIN:
  406. {
  407. if (!response)
  408. {
  409. Kick(playerid);
  410. return 1;
  411. }
  412.  
  413. new hashed_pass[65];
  414. SHA256_PassHash(inputtext, Player[playerid][Salt], hashed_pass, 65);
  415.  
  416. if (strcmp(hashed_pass, Player[playerid][Password]) == 0)
  417. {
  418. //correct password, spawn the player
  419. ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "Login con successo.", "Okay", "");
  420. // sets the specified cache as the active cache so we can retrieve the rest player data
  421. cache_set_active(Player[playerid][Cache_ID]);
  422. AssignPlayerData(playerid);
  423. // remove the active cache from memory and unsets the active cache as well
  424. cache_delete(Player[playerid][Cache_ID]);
  425. Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
  426.  
  427. KillTimer(Player[playerid][LoginTimer]);
  428. Player[playerid][LoginTimer] = 0;
  429. Player[playerid][IsLoggedIn] = true;
  430.  
  431. // spawn the player to their last saved position after login
  432. SetSpawnInfo(playerid, NO_TEAM, 0, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], 0, 0, 0, 0, 0, 0);
  433. SpawnPlayer(playerid);
  434. }
  435. else
  436. {
  437. Player[playerid][LoginAttempts]++;
  438.  
  439. if (Player[playerid][LoginAttempts] >= 3)
  440. {
  441. ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "Hai superato i tentativi di accesso (3 tentativi).", "Okay", "");
  442. DelayedKick(playerid);
  443. }
  444. else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "{FF0000}Password errata!\n{AFAFAF}Inserisci la password per entrare:", "Login", "Annulla");
  445. }
  446. }
  447. // Dialog - registrazione 1/6 password
  448. case DIALOG_REGISTER:
  449. {
  450. if (!response)
  451. {
  452. Kick(playerid);
  453. return 1;
  454. }
  455.  
  456. if (strlen(inputtext) <= 5) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione... [Step: 1/6]", "{FF0000}[ERRORE:]Hai inserito una password troppo corta, usa almeno 5 caratteri!\n{AFAFAF}Inserisci una password per registrarti:", "Continua", "Annulla");
  457.  
  458. // 16 random characters from 33 to 126 (in ASCII) for the salt
  459. for (new i = 0; i < 16; i++) Player[playerid][Salt][i] = random(94) + 33;
  460. SHA256_PassHash(inputtext, Player[playerid][Salt], Player[playerid][Password], 65);
  461. new query[221];
  462. mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`) VALUES ('%e', '%s', '%e')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt]);
  463. // mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
  464. new string[128];
  465. format(string, sizeof(string), "{AFAFAF}[INFO:] Ricorda la tua password è: {f4b642}'%s'", inputtext);
  466. SendClientMessage(playerid, COLOR_SYSTEM_INFO, string);
  467. format(string, sizeof(string), "{AFAFAF}[INFO:] Puoi cambiarla in game con il comando {ff0000}/cambia -> PASSWORD");
  468. SendClientMessage(playerid, COLOR_SYSTEM_INFO, string);
  469. ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... [Step: 2/6]", "Inserisci l'età che vuoi avere nel server\nNon influenzerà il gioco", "Continua", "Annulla");
  470. }
  471. // Dialog - registrazione 2/6 età
  472. case DIALOG_REGISTER_AGE:
  473. {
  474. if (!response)
  475. {
  476. Kick(playerid);
  477. return 1;
  478. }
  479.  
  480. if (!strlen(inputtext))
  481. {
  482. ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... età [Step: 2/6]", "{FF0000}[ERRORE:]Devi inserire l'età per continuare!\n{AFAFAF}Non influenzerà il gioco:", "Continua", "Annulla");
  483. return 1;
  484. }
  485. else if (strlen(inputtext))
  486. {
  487. if (!IsNumeric(inputtext))
  488. {
  489. ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... età [Step: 2/6]", "{FF0000}[ERRORE:]Devi inserire un numero per l'età!\n{AFAFAF}Non influenzerà il gioco:", "Continua", "Annulla");
  490. return 1;
  491. }
  492. else if (IsNumeric(inputtext))
  493. {
  494. new eta = strval(inputtext);
  495. if(eta < 18 || eta > 75)
  496. {
  497. ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... età [Step: 2/6]", "{FF0000}[ERRORE:]Devi inserire un'età compresa tra 18 e 75!\n{AFAFAF}Non influenzerà il gioco:", "Continua", "Annulla");
  498. }
  499. else
  500. {
  501. new query[221];
  502. Player[playerid][Age] = strval(inputtext);
  503. //format(query, sizeof(query), "UPDATE `players` SET `age` = %d WHERE `id` = %d LIMIT 1", strval(inputtext), Player[playerid][ID]);
  504. mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`) VALUES ('%e', '%s', '%e', '%d', '%d')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age]);
  505. new string[128];
  506. format(string, sizeof(string), "{AFAFAF}[INFO:] Hai %d anni.", strval(inputtext));
  507. SendClientMessage(playerid, COLOR_SYSTEM_INFO, string);
  508. ShowPlayerDialog(playerid, DIALOG_REGISTER_SEX, DIALOG_STYLE_LIST, "Seleziona il sesso", "{FF6666}Donna\n{0000cc}Uomo", "Continua", "");
  509. }
  510. }
  511. }
  512. }
  513. // Dialog - registrazione 3/6 sesso
  514. case DIALOG_REGISTER_SEX:
  515. {
  516. if (!response)
  517. {
  518. Kick(playerid);
  519. return 1;
  520. }
  521. switch(listitem)// Dialog: registrazione fase 3: sesso
  522. {
  523. case 0: // Registrazione sesso: selezionato: donna
  524. {
  525. // Player[playerid][Sex] = 1; // 1 = donna
  526.  
  527. format(Player[playerid][Sex], 64, "Donna");
  528. new query[221];
  529. mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`) VALUES ('%e', '%s', '%e', '%d', '%d')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex]);
  530. // format(query, sizeof(query), "UPDATE `players` SET `sex` = %d WHERE `id` = %d LIMIT 1", Player[playerid][Sex], Player[playerid][ID]);
  531. // mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
  532. new Messaggio[256];
  533. format(Messaggio, sizeof (Messaggio), "{AFAFAF}[INFO]: %s sei {FF6666}una donna", Player[playerid][Name]);
  534. SendClientMessage(playerid, COLOR_SYSTEM_INFO, Messaggio);
  535. ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_INPUT, "Registrazione - email [4/7]", "{FFFFFF}Inserisci una mail per proteggere l'account\nServirà in caso volessi cambiare la password o la domanda di sicurezza e la risposta\n{AFAFAF}Quest'ultima verrà mostrata solo a te stesso, usa una mail a cui puoi accedere", "Continua", "Annula");
  536.  
  537. PlayerPlaySound(playerid, 1054, 0.0, 0.0, 0.0);
  538.  
  539. }
  540. case 1: // Registrazione sesso: selezionato: uomo
  541. {
  542. // Player[playerid][Sex] = 2; // 2 = uomo
  543. format(Player[playerid][Sex], 64, "Uomo");
  544. new query[221];
  545. mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`) VALUES ('%e', '%s', '%e', '%d', '%d')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex]);
  546. //format(query, sizeof(query), "UPDATE `players` SET `sex` = %d WHERE `id` = %d LIMIT 1", Player[playerid][Sex], Player[playerid][ID]);
  547. // mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
  548. new Messaggio[256];
  549. format(Messaggio, sizeof (Messaggio), "[INFO]: %s sei {0000cc}un uomo", Player[playerid][Name]);
  550. SendClientMessage(playerid, COLOR_SYSTEM_INFO, Messaggio);
  551.  
  552. ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_INPUT, "Registrazione - email [4/7]", "{FFFFFF}Inserisci una mail per proteggere l'account\nServirà in caso volessi cambiare la password o la domanda di sicurezza e la risposta\n{AFAFAF}Quest'ultima verrà mostrata solo a te stesso, usa una mail a cui puoi accedere", "Continua", "Annula");
  553. PlayerPlaySound(playerid, 1054, 0.0, 0.0, 0.0);
  554. //******
  555. }
  556. }
  557. }
  558. case DIALOG_REGISTER_EMAIL:
  559. {
  560. if (!response)
  561. {
  562. Kick(playerid);
  563. return 1;
  564. }
  565. else
  566. {
  567. if (IsEmailString(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_INPUT, "Registrazione... [Step: 4/6]", "{FF0000}[ERRORE:]Devi inserire una mail valida\n{AFAFAF}Servirà per proteggere il tuo acount e cambiare domanda e/o risposta di sicurezza:", "Continua", "Annulla");
  568. // new query[221];
  569. new StringEmail[64];
  570.  
  571. format(StringEmail, sizeof(StringEmail), "[INFO]: La tua email sarà %s", inputtext);
  572. SendClientMessage(playerid, COLOR_SYSTEM_INFO, StringEmail);
  573. SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Puoi cambiarla con il comando /cambia -> email");
  574. format(Player[playerid][PlayerEmail], 128, inputtext);
  575.  
  576. // mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `email`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], Player[playerid][PlayerEmail]);
  577. // mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
  578.  
  579. new list[2 + (sizeof(SECURITY_QUESTIONS) * MAX_SECURITY_QUESTION_SIZE)];
  580. for (new i; i < sizeof(SECURITY_QUESTIONS); i++)
  581. {
  582. strcat(list, SECURITY_QUESTIONS[i]);
  583. strcat(list, "\n");
  584. }
  585. ShowPlayerDialog(playerid, DIALOG_REGISTER_DOMANDASEC, DIALOG_STYLE_LIST, "Registrazione - Domanda di sicurezza", list, "Continua", "Annulla");
  586.  
  587. }
  588. }
  589. case DIALOG_REGISTER_DOMANDASEC:
  590. {
  591. if (!response)
  592. {
  593. Kick(playerid);
  594. return 1;
  595. }
  596. else
  597. {
  598. format(Player[playerid][e_USER_SECURITY_QUESTION], MAX_SECURITY_QUESTION_SIZE, SECURITY_QUESTIONS[listitem]);
  599. new query[1024]; //221
  600. mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `email`, `domandasec`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s', '%e')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], Player[playerid][PlayerEmail], Player[playerid][e_USER_SECURITY_QUESTION]);
  601. new string[128];
  602. format(string, sizeof(string), "{AFAFAF}Hai selezionato come domanda di sicurezza:\n%s\n{FFFFFF}Inserisci una risposta di sicurezza", Player[playerid][e_USER_SECURITY_QUESTION]);
  603. ShowPlayerDialog(playerid, DIALOG_REGISTER_RISPOSTASEC, DIALOG_STYLE_INPUT, "Registrazione - Domanda di sicurezza [6/6]", string, "Continua", "Annuila");
  604. }
  605. }
  606. case DIALOG_REGISTER_RISPOSTASEC:
  607. {
  608. if (!response)
  609. {
  610. Kick(playerid);
  611. return 1;
  612. }
  613. else
  614. {
  615. new string[128];
  616. format(string, sizeof(string), "{FF0000}Devi inserire una risposta alla domanda di sicurezza!\n{AFAFAF}Hai selezionato come domanda di sicurezza:\n%s\n{FFFFFF}Inserisci una risposta di sicurezza", Player[playerid][e_USER_SECURITY_QUESTION]);
  617.  
  618. if (strlen(inputtext) <= 2) return ShowPlayerDialog(playerid, DIALOG_REGISTER_RISPOSTASEC, DIALOG_STYLE_INPUT, "Registrazione - Domanda di sicurezza [6/6]", string, "Continua", "Annuila");
  619.  
  620. format(Player[playerid][e_USER_SECURITY_ANSWER], 128, inputtext);
  621. new query[1024];
  622. mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `email`, `domandasec`, `rispostasec`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s', '%e', '%s')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], Player[playerid][PlayerEmail], Player[playerid][e_USER_SECURITY_QUESTION], Player[playerid][e_USER_SECURITY_ANSWER]);
  623. mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
  624. }
  625. }
  626. case DIALOG_PROVA:
  627. {
  628. GivePlayerMoney(playerid, strval(inputtext));
  629. return 1;
  630. }
  631.  
  632.  
  633.  
  634. default: return 0; // dialog ID was not found, search in other scripts
  635. }
  636. return 1;
  637. }
  638.  
  639. //-----------------------------------------------------
  640.  
  641. // controllo se una string è numerica
  642. IsNumeric(const string[])
  643. {
  644. for (new i = 0, j = strlen(string); i < j; i++)
  645. {
  646. if (string[i] > '9' || string[i] < '0') return 0;
  647. }
  648. return 1;
  649. }
  650.  
  651. // controllo se una string è numerica
  652. IsEmailString(const string[])
  653. {/*
  654. for (new i = 0, j = strlen(string); i < j; i++)
  655. {
  656. if (string[i] == '@') return 0;
  657. }*/
  658. // if(strfind(pname,"[",true) != (-1)) return 0;
  659. if(strfind(string,"@",true) && strfind(string,".com",true) != (-1)) return 0;
  660. return 1;
  661. }
  662.  
  663.  
  664. forward OnPlayerDataLoaded(playerid, race_check);
  665. public OnPlayerDataLoaded(playerid, race_check)
  666. {
  667. /* race condition check:
  668. player A connects -> SELECT query is fired -> this query takes very long
  669. while the query is still processing, player A with playerid 2 disconnects
  670. player B joins now with playerid 2 -> our laggy SELECT query is finally finished, but for the wrong player
  671. what do we do against it?
  672. we create a connection count for each playerid and increase it everytime the playerid connects or disconnects
  673. we also pass the current value of the connection count to our OnPlayerDataLoaded callback
  674. then we check if current connection count is the same as connection count we passed to the callback
  675. if yes, everything is okay, if not, we just kick the player
  676. */
  677. if (race_check != g_MysqlRaceCheck[playerid]) return Kick(playerid);
  678.  
  679. new string[115];
  680. if(cache_num_rows() > 0)// Giocatore registrato sul server
  681. {
  682. cache_get_value(0, "password", Player[playerid][Password], 65);
  683. cache_get_value(0, "salt", Player[playerid][Salt], 17);
  684. Player[playerid][Cache_ID] = cache_save();
  685.  
  686. format(string, sizeof string, "%s risulta registrato sul server.\nInserisci la password per entrare:", Player[playerid][Name]);
  687. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Annulla");
  688. Player[playerid][LoginTimer] = SetTimerEx("OnLoginTimeout", SECONDS_TO_LOGIN * 1000, false, "d", playerid);
  689. }
  690. else // Giocatore non registrato sul server
  691. {
  692. format(string, sizeof string, "Benvenuto %s,\nPer iniziare a registrarti su %s, inserisci una password", Player[playerid][Name], nomeserver);
  693. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione [1/6]", string, "Continua", "Annulla");
  694. }
  695. return 1;
  696. }
  697.  
  698. forward OnLoginTimeout(playerid);
  699. public OnLoginTimeout(playerid)
  700. {
  701. // reset the variable that stores the timerid
  702. Player[playerid][LoginTimer] = 0;
  703.  
  704. ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "Sei stato kickato dal server per aver impiegato troppo tempo nel loggarti.", "Okay", "");
  705. DelayedKick(playerid);
  706. return 1;
  707. }
  708.  
  709. // prova timer
  710. forward KickTimerNameRP(playerid);
  711. public KickTimerNameRP(playerid)
  712. {
  713. Kick(playerid);
  714. }
  715.  
  716.  
  717.  
  718. //-----------------------------------------------------
  719. // stocks
  720.  
  721. // Stock per mandare un messaggio agli admin
  722. stock SendMessageToAdmins(text[])
  723. {
  724. for(new i = 0; i < MAX_PLAYERS; i++)
  725. {
  726. if(Player[i][Admin] >= 1)
  727. {
  728. SendClientMessage(i, COLOR_SYSTEM_ADMIN, text);
  729. }
  730. }
  731. }
  732. // Stock chat staff
  733. stock ChatStaffMember(text[])
  734. {
  735. for(new i = 0; i < MAX_PLAYERS; i++)
  736. {
  737. if(Player[i][Admin] >= 1)
  738. {
  739. SendClientMessage(i, COLOR_SYSTEM_ADMIN, text);
  740. }
  741. }
  742. }
  743.  
  744.  
  745.  
  746.  
  747. forward OnPlayerRegister(playerid);
  748. public OnPlayerRegister(playerid)
  749. {
  750. // retrieves the ID generated for an AUTO_INCREMENT column by the sent query
  751. Player[playerid][ID] = cache_insert_id();
  752.  
  753. ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Registration", "Account successfully registered, you have been automatically logged in.", "Okay", "");
  754.  
  755. Player[playerid][IsLoggedIn] = true;
  756.  
  757. format(Player[playerid][PatenteA], 64, "Si");
  758. format(Player[playerid][PatenteB], 64, "Si");
  759. format(Player[playerid][PatenteC], 64, "Si");
  760. format(Player[playerid][PatenteD], 64, "Si");
  761. format(Player[playerid][PortoDarmi], 64, "No");
  762.  
  763.  
  764. Player[playerid][X_Pos] = DEFAULT_POS_X;
  765. Player[playerid][Y_Pos] = DEFAULT_POS_Y;
  766. Player[playerid][Z_Pos] = DEFAULT_POS_Z;
  767. Player[playerid][A_Pos] = DEFAULT_POS_A;
  768. Player[playerid][Interior] = DEFAULT_POS_INTERIOR;
  769.  
  770. SetSpawnInfo(playerid, NO_TEAM, 0, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], 0, 0, 0, 0, 0, 0);
  771. SetPlayerInterior(playerid, DEFAULT_POS_INTERIOR);
  772. SpawnPlayer(playerid);
  773. return 1;
  774. }
  775.  
  776. forward _KickPlayerDelayed(playerid);
  777. public _KickPlayerDelayed(playerid)
  778. {
  779. Kick(playerid);
  780. return 1;
  781. }
  782.  
  783.  
  784. //-----------------------------------------------------
  785. // login player
  786. AssignPlayerData(playerid)
  787. { // quando il player effettua il login
  788. // ID
  789. cache_get_value_int(0, "id", Player[playerid][ID]);
  790. // Kill fatte
  791. cache_get_value_int(0, "kills", Player[playerid][Kills]);
  792. // Patente A
  793. cache_get_value_name(0, "patentea", Player[playerid][PatenteA], 64);
  794. // Patente B
  795. cache_get_value_name(0, "patenteb", Player[playerid][PatenteB], 64);
  796. // Patente C
  797. cache_get_value_name(0, "patentec", Player[playerid][PatenteC], 64);
  798. // Patente D
  799. cache_get_value_name(0, "patented", Player[playerid][PatenteD], 64);
  800. // Porto D'armi
  801. cache_get_value_name(0, "portodarmi", Player[playerid][PortoDarmi], 64);
  802. // Soldi
  803. cache_get_value_int(0, "soldi", Player[playerid][Soldi]);
  804. // Numero di morti
  805. cache_get_value_int(0, "deaths", Player[playerid][Deaths]);
  806. // Livello admin
  807. cache_get_value_int(0, "admin", Player[playerid][Admin]);
  808. // Se in servizio admin
  809. cache_get_value_int(0, "aduty", Player[playerid][ADuty]);
  810. // Sesso
  811. cache_get_value_name(0, "sex", Player[playerid][Sex], 64);
  812. // Età
  813. cache_get_value_int(0, "age", Player[playerid][Age]);
  814. // Ultima posizione 'X'
  815. cache_get_value_float(0, "x", Player[playerid][X_Pos]);
  816. // Ultima posizione 'Y'
  817. cache_get_value_float(0, "y", Player[playerid][Y_Pos]);
  818. // Ultima posizione 'Z'
  819. cache_get_value_float(0, "z", Player[playerid][Z_Pos]);
  820. // Ultima posizione 'Angolo visuale'
  821. cache_get_value_float(0, "angle", Player[playerid][A_Pos]);
  822. // Vita
  823. cache_get_value_float(0, "vita", Player[playerid][Vita]);
  824. // Armatura
  825. cache_get_value_float(0, "armatura", Player[playerid][Armatura]);
  826. // Ultima posizione 'Interior'
  827. cache_get_value_int(0, "interior", Player[playerid][Interior]);
  828. // Domanda di sicurezza scelta
  829. cache_get_value_name(0, "domandasec", Player[playerid][e_USER_SECURITY_QUESTION], MAX_SECURITY_QUESTION_SIZE);
  830. // Risposta alla domanda di sicurezza
  831. cache_get_value_name(0, "rispostasec", Player[playerid][e_USER_SECURITY_ANSWER], 128);
  832. // Email
  833. cache_get_value_name(0, "email", Player[playerid][PlayerEmail], 128);
  834.  
  835.  
  836. // setting statistiche
  837. GivePlayerMoney(playerid, Player[playerid][Soldi]);
  838. SetPlayerHealth(playerid, Player[playerid][Vita]);
  839. SetPlayerArmour(playerid, Player[playerid][Armatura]);
  840.  
  841.  
  842. GivePlayerSavedWeapons(playerid, weaponid, ammo);
  843.  
  844.  
  845.  
  846. return 1;
  847. }
  848.  
  849. DelayedKick(playerid, time = 500)
  850. {
  851. SetTimerEx("_KickPlayerDelayed", time, false, "d", playerid);
  852. return 1;
  853. }
  854.  
  855. SetupPlayerTable()
  856. {
  857. mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(24) NOT NULL,`password` char(64) NOT NULL,`salt` char(16) NOT NULL,`kills` mediumint(8) NOT NULL DEFAULT '0',`deaths` mediumint(8) NOT NULL DEFAULT '0',`x` float NOT NULL DEFAULT '0',`y` float NOT NULL DEFAULT '0',`z` float NOT NULL DEFAULT '0',`angle` float NOT NULL DEFAULT '0',`interior` tinyint(3) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))");
  858. return 1;
  859. }
  860.  
  861. UpdatePlayerData(playerid, reason)
  862. {
  863. if (Player[playerid][IsLoggedIn] == false) return 0;
  864.  
  865. // if the client crashed, it's not possible to get the player's position in OnPlayerDisconnect callback
  866. // so we will use the last saved position (in case of a player who registered and crashed/kicked, the position will be the default spawn point)
  867. if (reason == 1)
  868. {
  869. GetPlayerPos(playerid, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos]);
  870. GetPlayerFacingAngle(playerid, Player[playerid][A_Pos]);
  871. }
  872.  
  873. new query[145];
  874. mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `x` = %f, `y` = %f, `z` = %f, `angle` = %f, `interior` = %d WHERE `id` = %d LIMIT 1", Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], GetPlayerInterior(playerid), Player[playerid][ID]);
  875. mysql_tquery(g_SQL, query);
  876.  
  877.  
  878.  
  879. return 1;
  880. }
  881.  
  882. UpdatePlayerWeapons(playerid)
  883. {
  884. new
  885. weaponid,
  886. munizioni;
  887.  
  888. for(new i; i < 13; i++) // looping through all weapon slots (0 - 12)
  889. {
  890. GetPlayerWeaponData(playerid, i, weaponid, munizioni); // get weaponid and ammo
  891.  
  892. if(!weaponid) continue; // don't insert if there's no weapon in this slot
  893. new query[145];
  894. mysql_format(g_SQL, query, sizeof query, "INSERT INTO armi VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE munizioni = %d;", Player[playerid][ID], weaponid, munizioni, munizioni);
  895. mysql_tquery(g_SQL, query);
  896. }
  897.  
  898. return 1;
  899. }
  900.  
  901. GivePlayerSavedWeapons(playerid, weaponid, ammo)
  902. {
  903. new
  904. weaponid,
  905. ammo;
  906.  
  907. for(new i, j = cache_get_row_count(dbrp); i < j; i++) // loop through all the rows that were found
  908. {
  909. weaponid = cache_get_row_int(i, 0, dbrp);
  910. ammo = cache_get_row_int(i, 1, dbrp);
  911.  
  912. if(!(0 <= weaponid <= 46)) // check if weapon is valid (should be)
  913. {
  914. printf("[info] Warning: OnLoadPlayerWeapons - Unknown weaponid '%d'. Skipping.", weaponid);
  915. continue;
  916. }
  917.  
  918. GivePlayerWeapon(playerid, weaponid, ammo);
  919. }
  920. return 1;
  921. }
  922.  
  923.  
  924.  
  925.  
  926.  
  927. UpdatePlayerDeaths(playerid)
  928. {
  929. if (Player[playerid][IsLoggedIn] == false) return 0;
  930.  
  931. Player[playerid][Deaths]++;
  932.  
  933. new query[70];
  934. mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `deaths` = %d WHERE `id` = %d LIMIT 1", Player[playerid][Deaths], Player[playerid][ID]);
  935. mysql_tquery(g_SQL, query);
  936. return 1;
  937. }
  938.  
  939. UpdatePlayerKills(killerid)
  940. {
  941. // we must check before if the killer wasn't valid (connected) player to avoid run time error 4
  942. if (killerid == INVALID_PLAYER_ID) return 0;
  943. if (Player[killerid][IsLoggedIn] == false) return 0;
  944.  
  945. Player[killerid][Kills]++;
  946.  
  947. new query[70];
  948. mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `kills` = %d WHERE `id` = %d LIMIT 1", Player[killerid][Kills], Player[killerid][ID]);
  949. mysql_tquery(g_SQL, query);
  950. return 1;
  951. }
  952. //-----------------------------------------------------------------------
  953. // comandi - zcmd
  954.  
  955. CMD:adminchat(playerid, params[])
  956. {
  957. if(Player[playerid][Admin] >= 1)
  958. {// Se è un membro dellos taff
  959. // se int è uguale a 0 (non in servizio) cambia l'int in 1 - entra in servizio
  960. new
  961. Messaggio[128],
  962. NomeUtente[MAX_PLAYER_NAME];
  963. GetPlayerName(playerid, NomeUtente, MAX_PLAYER_NAME);
  964.  
  965. if (sscanf(params, "s[128]", Messaggio))
  966. {
  967. return SendClientMessage(playerid, COLOR_INFO, "[INFO]: /adminchat (Messaggio)");
  968. }
  969. format(Messaggio, sizeof(Messaggio), "[ADMIN CHAT] %s(%d): %s", NomeUtente, playerid, Messaggio);
  970. ChatStaffMember(Messaggio);
  971.  
  972. }
  973. else if(Player[playerid][Admin] < 1)
  974. {// se no è uno dello staff
  975. new string[128];
  976. format(string, sizeof(string), "[ERRORE]: Mi dispiace %s non sei autorizzato ad usare questo comando", Player[playerid][Name]);
  977. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, string);
  978. return 1;
  979. }
  980. return 1;
  981. }
  982.  
  983. COMMAND:admina(playerid, params[])
  984. {
  985. new
  986. option[128],
  987. item[128],
  988. amount[128],
  989. Messaggio[128];
  990. new TargetPlayerID;
  991. new GivingAmmount;
  992. new AdminName[MAX_PLAYER_NAME],
  993. TargetPlayerName[MAX_PLAYER_NAME];
  994. // Nome dell'admin
  995. GetPlayerName(playerid, AdminName, MAX_PLAYER_NAME);
  996. // Nome del giocatore selezionato
  997. GetPlayerName(TargetPlayerID, TargetPlayerName, MAX_PLAYER_NAME);
  998. //----
  999. sscanf(params, "s[128]s[128]s[128]", option, item, amount);
  1000. if (isnull(option))
  1001. {
  1002. SendClientMessage(playerid, COLOR_WHITE, "[INFO]: Uso comando /admina [Opzione]");
  1003. SendClientMessage(playerid, COLOR_WHITE, "Opzioni: Dai | Set");
  1004. return 1;
  1005. }
  1006. if (!strcmp(option, "dai") || !strcmp(option, "Dai"))
  1007. { // Comando: /admin give [opzione]
  1008. if (isnull(item))
  1009. {
  1010. SendClientMessage(playerid, COLOR_WHITE, "[INFO]: Uso comando /admin give [Opzione]");
  1011. SendClientMessage(playerid, COLOR_WHITE, "Opzioni: Soldi");
  1012. return 1;
  1013. }
  1014. if (!strcmp(item, "soldi") || strcmp(item, "Soldi"))
  1015. { // Comando: /admin give soldi [Quantità]
  1016. if(sscanf(amount,"ui", TargetPlayerID, GivingAmmount))
  1017. {
  1018. SendClientMessage(playerid, COLOR_SYSTEM_ERROR , "[INFO]: Uso comando /admina dai soldi [ID/NOME][QUANTITA']");
  1019. return 1;
  1020. }
  1021. if(!IsPlayerConnected(TargetPlayerID))
  1022. { // Messaggio d'errore se: giocatore non trovato/connesso
  1023. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, "[ERRORE:] Il giocatore selezionato non è connesso o hai sbagliato ID/nome");
  1024. return 1;
  1025. }
  1026. else
  1027. { // se il giocatore è connesso
  1028. if(GivingAmmount >= 1)
  1029. {
  1030. GivePlayerMoney(TargetPlayerID, GivingAmmount);
  1031. // MEssaggio all'utente selezionato
  1032. format(Messaggio, sizeof (Messaggio), "[ADMIN]: %s ti ha givvato %i$", AdminName, GivingAmmount );
  1033. SendClientMessage(TargetPlayerID, 0x33FF33AA, Messaggio);
  1034. // Messaggio all'ADMIN
  1035. format(Messaggio, sizeof (Messaggio), "[INFO]: Hai givvato %i$ all'utente %s", GivingAmmount, TargetPlayerName );
  1036. SendClientMessage(playerid, 0x33FF33AA, Messaggio);
  1037. return 1;
  1038. }
  1039. else if(GivingAmmount < 0)
  1040. {
  1041. new StringSoldi[64];
  1042. format(StringSoldi, sizeof(StringSoldi), "{FF0000}[ERRORE]: {AFAFAF} Non puoi givvare $i, per togliere soldi usa /admina togli soldi", GivingAmmount);
  1043. SendClientMessage(playerid, -1, StringSoldi);
  1044. return 1;
  1045. }
  1046. }
  1047. }
  1048. else if (!strcmp(item, "armatura") || (!strcmp(item, "Armatura")))
  1049. {
  1050. if(sscanf(amount,"u", TargetPlayerID))
  1051. {
  1052. SendClientMessage(playerid, COLOR_SYSTEM_ERROR , "[INFO]: Uso comando /admina set armatura [ID/NOME]");
  1053. return 1;
  1054. }
  1055. if(!IsPlayerConnected(TargetPlayerID))
  1056. { // Messaggio d'errore se: giocatore non trovato/connesso
  1057. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, "[ERRORE:] Il giocatore selezionato non è connesso o hai sbagliato ID/nome");
  1058. return 1;
  1059. }
  1060. else
  1061. { // Comando effettuato con successo
  1062. SetPlayerArmour(TargetPlayerID, 100);
  1063. // MEssaggio all'utente selezionato
  1064. format(Messaggio, sizeof (Messaggio), "[ADMIN]: %s ti ha settato l'armatura al 100%", AdminName );
  1065. SendClientMessage(TargetPlayerID, 0x33FF33AA, Messaggio);
  1066. // Messaggio all'ADMIN
  1067. format(Messaggio, sizeof (Messaggio), "[INFO]: Hai settato l'armatura all'utente %s", TargetPlayerName );
  1068. SendClientMessage(playerid, 0x33FF33AA, Messaggio);
  1069. return 1;
  1070. }
  1071. }
  1072. else if (!strcmp(item, "money"))
  1073. {
  1074. // Code for the money...
  1075. }
  1076. }
  1077. else if (!strcmp(option, "set"))
  1078. {
  1079. if (isnull(item))
  1080. {
  1081. SendClientMessage(playerid, COLOR_WHITE, "[INFO]: uso comando /admina set [Opzione]");
  1082. SendClientMessage(playerid, COLOR_WHITE, "Opzioni: Gun, Drugs, Money");
  1083. return 1;
  1084. }
  1085. if (!strcmp(item, "armatura") || (!strcmp(item, "Armatura")))
  1086. {
  1087. if(sscanf(amount,"u", TargetPlayerID))
  1088. {
  1089. SendClientMessage(playerid, COLOR_SYSTEM_ERROR , "[INFO]: Uso comando /admina set armatura [ID/NOME]");
  1090. return 1;
  1091. }
  1092. if(!IsPlayerConnected(TargetPlayerID))
  1093. { // Messaggio d'errore se: giocatore non trovato/connesso
  1094. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, "[ERRORE:] Il giocatore selezionato non è connesso o hai sbagliato ID/nome");
  1095. return 1;
  1096. }
  1097. else
  1098. { // Comando effettuato con successo
  1099. SetPlayerArmour(TargetPlayerID, 100);
  1100. // MEssaggio all'utente selezionato
  1101. format(Messaggio, sizeof (Messaggio), "[ADMIN]: %s ti ha settato l'armatura al 100%", AdminName );
  1102. SendClientMessage(TargetPlayerID, 0x33FF33AA, Messaggio);
  1103. // Messaggio all'ADMIN
  1104. format(Messaggio, sizeof (Messaggio), "[INFO]: Hai settato l'armatura all'utente %s", TargetPlayerName );
  1105. SendClientMessage(playerid, 0x33FF33AA, Messaggio);
  1106. return 1;
  1107. }
  1108. }
  1109. else if (!strcmp(item, "drugs"))
  1110. {
  1111. // Code for the drugs...
  1112. }
  1113. else if (!strcmp(item, "money"))
  1114. {
  1115. // Code for the money...
  1116. }
  1117. }
  1118. return 1;
  1119. }
  1120. // admin give fine
  1121.  
  1122.  
  1123. CMD:report(playerid, params[]) {
  1124. new id; // id player reportato
  1125. new reason[128]; // Ragione del report
  1126. if(sscanf(params, "us[128]", id, reason)) return SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[SERVER] - USAGE: /report [ID] [REASON]");
  1127. new string[150], // stringa messaggio report
  1128. sender[MAX_PLAYER_NAME], // Nome di chi manda il report
  1129. receiver[MAX_PLAYER_NAME]; // Chi riceve il report
  1130.  
  1131. GetPlayerName(playerid, sender, sizeof(sender));
  1132. GetPlayerName(id, receiver, sizeof(receiver));
  1133.  
  1134. format(string, sizeof(string), "[ADMIN]: %s(%d) ha reportato %s(%d)", sender, playerid, receiver, id);
  1135. SendMessageToAdmins(string);
  1136.  
  1137. format(string, sizeof(string), "[ADMIN]: Motivo: %s", reason);
  1138. SendMessageToAdmins(string);
  1139.  
  1140. SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, "[INFO]: Il tuo report è stato inviato.");
  1141. return 1;
  1142. }
  1143.  
  1144. CMD:stats(playerid, params[])
  1145. {
  1146.  
  1147. new StatsString[512];
  1148. new StatsLicense[1500];
  1149. format(StatsString, sizeof(StatsString), "[STATISTICHE] - Ecco le tue informazioni %s", Player[playerid][Name]);
  1150. SendClientMessage(playerid, COLOR_SYSTEM_INFO, StatsString);
  1151.  
  1152. format(StatsLicense, sizeof(StatsLicense), "[License] - Patente A: %s | Patente B: %s | Patente C: %s | Patente D: %s | Porto d'armi: %s", Player[playerid][PatenteA], Player[playerid][PatenteB], Player[playerid][PatenteC], Player[playerid][PatenteD], Player[playerid][PortoDarmi]);
  1153. SendClientMessage(playerid, COLOR_SYSTEM_INFO, StatsLicense);
  1154.  
  1155. return 1;
  1156. }
  1157.  
  1158.  
  1159. CMD:aiuto(playerid, params[])
  1160. {
  1161. new
  1162. MessaggioAiuto[128],
  1163. NomeUtente[MAX_PLAYER_NAME];
  1164. GetPlayerName(playerid, NomeUtente, MAX_PLAYER_NAME);
  1165.  
  1166. if (sscanf(params, "s[128]", MessaggioAiuto))
  1167. {
  1168. return SendClientMessage(playerid, COLOR_INFO, "[INFO]: /aiuto (Messaggio di aiuto)");
  1169. }
  1170. format(MessaggioAiuto, sizeof(MessaggioAiuto), "[AIUTO]: %s(%d): %s", Player[playerid][PatenteA], playerid, MessaggioAiuto); // NomeUtente
  1171. SendMessageToAdmins(MessaggioAiuto);
  1172. SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Il tuo messaggio è stato mandato");
  1173. return 1;
  1174. }
  1175.  
  1176. CMD:aduty(playerid, params[])
  1177. {
  1178. if(Player[playerid][Admin] >= 1)
  1179. {// Se è un membro dellos taff
  1180. // se int è uguale a 0 (non in servizio) cambia l'int in 1 - entra in servizio
  1181. if(Player[playerid][ADuty] == 0)
  1182. {// entra in servizio
  1183. TextDrawShowForPlayer(playerid,AdminInDuty);
  1184. SetPlayerArmour(playerid, 10000);
  1185. SetPlayerHealth(playerid, 10000);
  1186. new ADutyString[64];
  1187. format(ADutyString, sizeof(ADutyString), "[ADMIN]: L'admin %s è in servizio", Player[playerid][Name]);
  1188. SendClientMessageToAll(COLOR_SYSTEM_ADMIN, ADutyString);
  1189. Player[playerid][ADuty] = 1;
  1190. return 1;
  1191. }
  1192. // se int è uguale a 1 (in servizio) cambia l'int in 0 - esce dal servizio
  1193. if(Player[playerid][ADuty] == 1)
  1194. {// esce dal servizio
  1195. TextDrawHideForPlayer(playerid,AdminInDuty);
  1196. SetPlayerArmour(playerid, Player[playerid][Armatura]);
  1197. SetPlayerHealth(playerid, Player[playerid][Vita]);
  1198. new ADutyString[64];
  1199. format(ADutyString, sizeof(ADutyString), "[ADMIN]: L'admin %s non è più in servizio", Player[playerid][Name]);
  1200. SendClientMessageToAll(COLOR_SYSTEM_ADMIN, ADutyString);
  1201. Player[playerid][ADuty] = 0;
  1202. return 1;
  1203. }
  1204. }
  1205. else if(Player[playerid][Admin] < 1)
  1206. {// se no è uno dello staff
  1207. new string[128];
  1208. format(string, sizeof(string), "[ERRORE]: Mi dispiace %s non sei autorizzato ad usare questo comando", Player[playerid][Name]);
  1209. SendClientMessage(playerid, COLOR_SYSTEM_ERROR, string);
  1210. return 1;
  1211. }
  1212. return 1;
  1213. }
  1214.  
  1215. CMD:suicidio(playerid, params[])
  1216. {
  1217. SetPlayerHealth(playerid, 0);
  1218. return 1;
  1219. }
  1220.  
  1221. public OnPlayerRequestClass(playerid,classid)
  1222. { // quando un giocatore si registra/logga
  1223. // SetPlayerPos(playerid, 982.1890, -1624.2583, 14.9526); // posizione dafault las venturas
  1224. SetPlayerPos(playerid, -1965.3541, 158.4787, 27.6940);
  1225. SetPlayerFacingAngle(playerid, 90.0000);
  1226. return 1;
  1227. }
Add Comment
Please, Sign In to add comment