Advertisement
Felipe_Alves

Weapon Reload 2.0

Jun 1st, 2019
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.70 KB | None | 0 0
  1. #if defined _include_weapon_reload
  2. #endinput
  3. #endif
  4. #define _include_weapon_reload
  5.  
  6. // ========================== INCLUDES ================================
  7. // --------------------------------------------------------------------
  8. #tryinclude <a_samp>
  9. #tryinclude <sscanf2>
  10. #tryinclude <Pawn.CMD>
  11. // ------------------------------------------------------------------
  12. // ========================== MACROS ================================
  13. // ------------------------------------------------------------------
  14. #define PRESSED(%0) (((newkeys&(%0))==(%0))&&((oldkeys&(%0))!=(%0)))
  15. #define PRESSING(%0,%1) (%0&(%1))
  16. #define KEY_AIM KEY_HANDBRAKE
  17. // ------------------------------------------------------------------
  18. // ========================== OUTROS ================================
  19. #define NAME_PROJECT "Weapon - Reload"
  20. #define CREATOR_PROJECT "Felipe_Alves"
  21. #define VERSION_PROJECT "2.0a"
  22. // ========================== VARIÁVEIS ================================
  23. // ---------------------------------------------------------------------
  24. enum Weapon_DATA{
  25. w_Weapon[13],
  26. w_Ammo[13],
  27. bool:w_TdShow,
  28. }
  29. static // Mude para 'new' para poder usar externamente
  30. w_Info[MAX_PLAYERS][Weapon_DATA],
  31. w_x_weapon[MAX_PLAYERS][13],
  32. w_x_ammo[MAX_PLAYERS][13],
  33. w_Timer_Player[MAX_PLAYERS][2],
  34. PlayerText:Weapon_InfosTD[MAX_PLAYERS][5]
  35. ;
  36. // ---------------------------------------------------------------------
  37.  
  38. public OnGameModeInit()
  39. {
  40. print("\n--------------------------------------");
  41. print(" Carregado");
  42. printf("\n Nome: %s", NAME_PROJECT);
  43. printf(" By: %s", CREATOR_PROJECT);
  44. printf(" Versão: %s\n", VERSION_PROJECT);
  45. print("--------------------------------------\n");
  46. #if defined hook_OnGameModeInit
  47. return hook_OnGameModeInit();
  48. #else
  49. return 1;
  50. #endif
  51. }
  52. #if defined _ALS_OnGameModeInit
  53. #undef OnGameModeInit
  54. #else
  55. #define _ALS_OnGameModeInit
  56. #endif
  57.  
  58. #define OnGameModeInit hook_OnGameModeInit
  59. #if defined hook_OnGameModeInit
  60. forward hook_OnGameModeInit();
  61. #endif
  62.  
  63. public OnGameModeExit(){
  64. print("\n--------------------------------------");
  65. print(" Encerrado");
  66. printf("\n Nome: %s", NAME_PROJECT);
  67. print("--------------------------------------\n");
  68. #if defined hook_OnGameModeExit
  69. return hook_OnGameModeExit();
  70. #else
  71. return 1;
  72. #endif
  73. }
  74. #if defined _ALS_OnGameModeExit
  75. #undef OnGameModeExit
  76. #else
  77. #define _ALS_OnGameModeExit
  78. #endif
  79.  
  80. #define OnGameModeExit hook_OnGameModeExit
  81. #if defined hook_OnGameModeExit
  82. forward hook_OnGameModeExit();
  83. #endif
  84.  
  85. public OnPlayerConnect(playerid){
  86. w_Timer_Player[playerid][0] = SetTimerEx("Timer_Weapon_Check", 50, 1, "d", playerid);
  87. w_Timer_Player[playerid][1] = SetTimerEx("Timer_Weapon_Ammo", 50, 1, "d", playerid);
  88.  
  89. Weapon_InfosTD[playerid][0] = CreatePlayerTextDraw(playerid, 505.599945, 96.915557, "Reserva");
  90. PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][0], 0.400000, 1.600000);
  91. PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][0], 1);
  92. PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][0], -50331393);
  93. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][0], 0);
  94. PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][0], 0);
  95. PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][0], 255);
  96. PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][0], 2);
  97. PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][0], 1);
  98. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][0], 0);
  99.  
  100. Weapon_InfosTD[playerid][1] = CreatePlayerTextDraw(playerid, 550.800292, 114.337753, "000/000");
  101. PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][1], 0.400000, 1.600000);
  102. PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][1], 2);
  103. PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][1], -1);
  104. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][1], 0);
  105. PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][1], 0);
  106. PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][1], 255);
  107. PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][1], 3);
  108. PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][1], 1);
  109. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][1], 0);
  110.  
  111. Weapon_InfosTD[playerid][2] = CreatePlayerTextDraw(playerid, 507.200134, 115.333351, "box");
  112. PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][2], 0.000000, 1.608999);
  113. PlayerTextDrawTextSize(playerid, Weapon_InfosTD[playerid][2], 594.450439, 0.000000);
  114. PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][2], 1);
  115. PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][2], -1);
  116. PlayerTextDrawUseBox(playerid, Weapon_InfosTD[playerid][2], 1);
  117. PlayerTextDrawBoxColor(playerid, Weapon_InfosTD[playerid][2], 113);
  118. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][2], 0);
  119. PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][2], 0);
  120. PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][2], 255);
  121. PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][2], 1);
  122. PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][2], 1);
  123. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][2], 0);
  124.  
  125. Weapon_InfosTD[playerid][3] = CreatePlayerTextDraw(playerid, 506.800079, 60.720031, "box");
  126. PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][3], 0.000000, 1.560000);
  127. PlayerTextDrawTextSize(playerid, Weapon_InfosTD[playerid][3], 535.000000, 0.000000);
  128. PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][3], 1);
  129. PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][3], -1);
  130. PlayerTextDrawUseBox(playerid, Weapon_InfosTD[playerid][3], 1);
  131. PlayerTextDrawBoxColor(playerid, Weapon_InfosTD[playerid][3], 185);
  132. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][3], 0);
  133. PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][3], 0);
  134. PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][3], 255);
  135. PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][3], 1);
  136. PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][3], 1);
  137. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][3], 0);
  138.  
  139. Weapon_InfosTD[playerid][4] = CreatePlayerTextDraw(playerid, 520.598999, 60.422233, "0");
  140. PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][4], 0.400000, 1.600000);
  141. PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][4], 2);
  142. PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][4], -1);
  143. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][4], 0);
  144. PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][4], 0);
  145. PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][4], 255);
  146. PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][4], 1);
  147. PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][4], 1);
  148. PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][4], 0);
  149.  
  150. for(new i = 0; i < 13; ++i){
  151. w_Info[playerid][w_Ammo][i] = 0;
  152. w_Info[playerid][w_Weapon][i] = 0;
  153. }
  154.  
  155. #if defined hook_OnPlayerConnect
  156. return hook_OnPlayerConnect(playerid);
  157. #else
  158. return 1;
  159. #endif
  160. }
  161. #if defined _ALS_OnPlayerConnect
  162. #undef OnPlayerConnect
  163. #else
  164. #define _ALS_OnPlayerConnect
  165. #endif
  166.  
  167. #define OnPlayerConnect hook_OnPlayerConnect
  168. #if defined hook_OnPlayerConnect
  169. forward hook_OnPlayerConnect(playerid);
  170. #endif
  171.  
  172. public OnPlayerDisconnect(playerid, reason){
  173. KillTimer(w_Timer_Player[playerid][0]);
  174. KillTimer(w_Timer_Player[playerid][1]);
  175. w_Info[playerid][w_TdShow] = false;
  176. for(new x = 0; x < sizeof(Weapon_InfosTD[]); ++x){
  177. PlayerTextDrawHide(playerid, Weapon_InfosTD[playerid][x]);
  178. PlayerTextDrawDestroy(playerid, Weapon_InfosTD[playerid][x]);
  179. }
  180. #if defined hook_OnPlayerDisconnect
  181. return hook_OnPlayerDisconnect(playerid, reason);
  182. #else
  183. return 1;
  184. #endif
  185. }
  186. #if defined _ALS_OnPlayerDisconnect
  187. #undef OnPlayerDisconnect
  188. #else
  189. #define _ALS_OnPlayerDisconnect
  190. #endif
  191.  
  192. #define OnPlayerDisconnect hook_OnPlayerDisconnect
  193. #if defined hook_OnPlayerDisconnect
  194. forward hook_OnPlayerDisconnect(playerid, reason);
  195. #endif
  196.  
  197. forward Timer_Weapon_Ammo(playerid);
  198. public Timer_Weapon_Ammo(playerid){
  199. if(!IsPlayerConnected(playerid)) return 1;
  200. for(new i = 0; i < 13; ++i){
  201. GetPlayerWeaponData(playerid, i, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
  202. if(w_x_weapon[playerid][i] != 0 && w_x_ammo[playerid][i] == 0){
  203. SetPlayerAmmo(playerid, w_x_weapon[playerid][i], 1);
  204. continue;
  205. }
  206. }
  207. return 1;
  208. }
  209. forward Timer_Weapon_Check(playerid);
  210. public Timer_Weapon_Check(playerid){
  211. if(!IsPlayerConnected(playerid)) return 1;
  212. new weaponid = GetPlayerWeapon(playerid);
  213.  
  214. if(weaponid >= 0 && weaponid <= 15 || weaponid == 44 && weaponid == 45 && weaponid == 46){
  215. if(w_Info[playerid][w_TdShow]){
  216. Esconder_wTD(playerid);
  217. }
  218. }else if(weaponid != 0){ // Verifica se ele está com uma arma na mão.
  219. if(!w_Info[playerid][w_TdShow])
  220. Mostrar_wTD(playerid);
  221. // ---------------------------
  222. new Text_w[14];
  223. new slot = SlotsWeapons(GetPlayerWeapon(playerid));
  224. format(Text_w, sizeof(Text_w), "%d", w_Info[playerid][w_Ammo][slot]);
  225. PlayerTextDrawSetString(playerid, Weapon_InfosTD[playerid][1], Text_w);
  226. if(w_x_ammo[playerid][slot] > 1){
  227. format(Text_w, sizeof(Text_w), "%d", w_x_ammo[playerid][slot]);
  228. }else if(w_x_ammo[playerid][slot] <= 0 && w_Info[playerid][w_Ammo][slot] >= 1){
  229. Text_w = "0";
  230. }else if(w_x_ammo[playerid][slot] == 1 && w_Info[playerid][w_Ammo][slot] >= 1){
  231. Text_w = "~r~Y";
  232. }
  233. PlayerTextDrawSetString(playerid, Weapon_InfosTD[playerid][4], Text_w);
  234. }else{
  235. Esconder_wTD(playerid);
  236. }
  237. return 1;
  238. }
  239.  
  240. public OnPlayerUpdate(playerid){
  241. if(IsPlayerConnected(playerid)){
  242. new newkeys, x, y, oldkeys;
  243. GetPlayerKeys(playerid,newkeys,x,y);
  244. if(Closed_Weapon(playerid) && (PRESSING(newkeys, KEY_AIM | KEY_FIRE) || PRESSING(newkeys, KEY_FIRE) || PRESSED(KEY_FIRE))){
  245. SetPlayerArmedWeapon(playerid, 0);
  246. ClearAnimations(playerid);
  247. }
  248. }
  249. #if defined hook_OnPlayerUpdate
  250. return hook_OnPlayerUpdate(playerid);
  251. #else
  252. return 1;
  253. #endif
  254. }
  255. #if defined _ALS_OnPlayerUpdate
  256. #undef OnPlayerUpdate
  257. #else
  258. #define _ALS_OnPlayerUpdate
  259. #endif
  260.  
  261. #define OnPlayerUpdate hook_OnPlayerUpdate
  262. #if defined hook_OnPlayerUpdate
  263. forward hook_OnPlayerUpdate(playerid);
  264. #endif
  265.  
  266. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ){
  267. if(weaponid != 0){
  268. if(Closed_Weapon(playerid)){
  269. SetPlayerArmedWeapon(playerid, 0);
  270. ClearAnimations(playerid);
  271. }
  272. }
  273. #if defined hook_OnPlayerWeaponShot
  274. return hook_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  275. #else
  276. return 1;
  277. #endif
  278. }
  279. #if defined _ALS_OnPlayerWeaponShot
  280. #undef OnPlayerWeaponShot
  281. #else
  282. #define _ALS_OnPlayerWeaponShot
  283. #endif
  284.  
  285. #define OnPlayerWeaponShot hook_OnPlayerWeaponShot
  286. #if defined hook_OnPlayerWeaponShot
  287. forward hook_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  288. #endif
  289.  
  290. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
  291. if(PRESSED(KEY_YES)){
  292. new weaponid = GetPlayerWeapon(playerid);
  293. if(weaponid != 0){
  294. new slot = SlotsWeapons(weaponid);
  295. new sammo = w_x_ammo[playerid][slot];
  296. new lammo = Weapon_Ammo_Limit(weaponid);
  297. if(weaponid == 1 || weaponid >= 1 && weaponid <= 15 || weaponid == 44 || weaponid == 45 || weaponid == 46) return true;
  298. if(sammo >= 1 && sammo < lammo){
  299. if(!(w_Info[playerid][w_Ammo][slot] >= 1)){
  300. w_Info[playerid][w_Ammo][slot] = 0;
  301. return SendClientMessage(playerid, 0xC1C1C1FF, "Você não possui bala reserva para recarregar.");
  302. }
  303. new r_weapon = w_Info[playerid][w_Ammo][slot];
  304. new calc = lammo - sammo;
  305.  
  306. if(r_weapon >= calc){
  307. w_Info[playerid][w_Ammo][slot] -= calc;
  308. }else{
  309. w_Info[playerid][w_Ammo][slot] = 0;
  310. calc = r_weapon;
  311. }
  312. GivePlayerWeapon(playerid, weaponid, calc);
  313. }else{
  314. SendClientMessage(playerid, 0xC1C1C1FF, "Sua arma já está com o pente cheio.");
  315. }
  316. }
  317. }
  318. #if defined hook_OnPlayerKeyStateChange
  319. return hook_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  320. #else
  321. return 1;
  322. #endif
  323. }
  324. #if defined _ALS_OnPlayerKeyStateChange
  325. #undef OnPlayerKeyStateChange
  326. #else
  327. #define _ALS_OnPlayerKeyStateChange
  328. #endif
  329.  
  330. #define OnPlayerKeyStateChange hook_OnPlayerKeyStateChange
  331. #if defined hook_OnPlayerKeyStateChange
  332. forward hook_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  333. #endif
  334.  
  335. stock Closed_Weapon(playerid){
  336. new weaponid = GetPlayerWeapon(playerid);
  337. new slot = SlotsWeapons(weaponid);
  338. if(weaponid == 1 || weaponid >= 1 && weaponid <= 15 || weaponid == 44 || weaponid == 45 || weaponid == 46) return false;
  339. if(weaponid != 0 && GetPlayerWeapon(playerid) == w_x_weapon[playerid][slot]){
  340. if(w_x_ammo[playerid][slot] == 1)
  341. return true;
  342. }
  343. return false;
  344. }
  345. stock GivePlayerWeaponEx(playerid, weaponid, ammo){
  346. new slot = SlotsWeapons(weaponid);
  347. new sammo = w_x_ammo[playerid][slot];
  348. new lammo = Weapon_Ammo_Limit(weaponid);
  349. if(w_x_weapon[playerid][slot] != weaponid){
  350. RemovePlayerWeaponSlot(playerid, slot);
  351. }
  352. PlayerGetWeapons(playerid, slot);
  353. if(weaponid == 1 || weaponid >= 1 && weaponid <= 15 || weaponid == 44 || weaponid == 45 || weaponid == 46){
  354. w_Info[playerid][w_Ammo][slot] = 0;
  355. GivePlayerWeapon(playerid, weaponid, 1);
  356. return 1;
  357. }
  358. if(sammo > 0 && lammo >= 1){
  359. w_Info[playerid][w_Ammo][slot] += ammo;
  360. return 1;
  361. }else if(ammo > lammo){
  362. w_Info[playerid][w_Ammo][slot] += ammo - lammo;
  363. GivePlayerWeapon(playerid, weaponid, lammo);
  364. return 1;
  365. }
  366. GivePlayerWeapon(playerid, weaponid, ammo);
  367. return 1;
  368. }
  369. stock PlayerGetWeapons(playerid, slot){
  370. for(new i = 0; i < 13; ++i){
  371. GetPlayerWeaponData(playerid, i, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
  372. if(w_x_weapon[playerid][i] != 0 && w_x_ammo[playerid][i] == 0){
  373. RemovePlayerWeaponSlot(playerid, slot);
  374. return true;
  375. }
  376. if(w_x_weapon[playerid][i] != 0 && w_x_ammo[playerid][i] != 0){
  377. return false;
  378. }
  379. }
  380. return false;
  381. }
  382. stock RemovePlayerWeaponSlot(playerid, slot){
  383. for(new i = 0; i < 13; ++i){
  384. GetPlayerWeaponData(playerid, i, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
  385. }
  386. ResetPlayerWeapons(playerid);
  387. for(new i = 0; i < 13; ++i){
  388. if(slot == i) continue;
  389. GivePlayerWeapon(playerid, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
  390. }
  391. return 1;
  392. }
  393. stock SlotsWeapons(armaid){
  394. new slot;
  395. switch(armaid){
  396. case 0..1: slot = 0; // FIST
  397. case 2..9: slot = 1; // ARMA BRANCA
  398. case 10..15: slot = 10; // ARMAS SLAOQ
  399. case 16..18, 39: slot = 8; // EXPLOSIVOS
  400. case 22..24: slot = 2; // PISTOLAS
  401. case 25..27: slot = 3; // DOZES
  402. case 28..29, 32: slot = 4; // SUBS
  403. case 30..31: slot = 5; // FUZIS
  404. case 33..34: slot = 6; // SNIPERS
  405. case 35..38: slot = 7; // BAZUCAS
  406. case 40: slot = 12; // DETONADOR
  407. case 41..43: slot = 9; // SLAS
  408. case 44..46: slot = 11; // VISÃO
  409. }
  410. return slot;
  411. }
  412. stock Weapon_Ammo_Limit(weaponid){
  413. new limit = 0;
  414. switch(weaponid){
  415. case 16..18, 28, 32, 29..30, 35..37, 39, 40..43: limit = 30;
  416. case 22: limit = 15;
  417. case 23: limit = 17;
  418. case 25: limit = 5;
  419. case 24, 27: limit = 7;
  420. case 26: limit = 4;
  421. case 31: limit = 50;
  422. case 33, 34: limit = 10;
  423. case 38: limit = 500;
  424. default: limit = 1;
  425. }
  426. return limit;
  427. }
  428. stock Mostrar_wTD(playerid){
  429. w_Info[playerid][w_TdShow] = true;
  430. for(new i = 0; i < sizeof(Weapon_InfosTD[]); ++i){
  431. PlayerTextDrawHide(playerid, Weapon_InfosTD[playerid][i]);
  432. PlayerTextDrawShow(playerid, Weapon_InfosTD[playerid][i]);
  433. }
  434. return 1;
  435. }
  436. stock Esconder_wTD(playerid){
  437. w_Info[playerid][w_TdShow] = false;
  438. for(new i = 0; i < sizeof(Weapon_InfosTD[]); ++i){
  439. PlayerTextDrawHide(playerid, Weapon_InfosTD[playerid][i]);
  440. }
  441. return 1;
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement