HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Copyleft 2015 @ HamletEagle
  3. Topic: https://forums.alliedmods.net/showthread.php?t=245803&page=1
  4.  
  5. Weapons Menu Creator is free software;
  6. you can redistribute it and/or modify it under the terms of the
  7. GNU General Public License as published by the Free Software Foundation.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with Weapons Menu Creator; if not, write to the
  16. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #include <amxmodx>
  21. #include <amxmisc>
  22. #include <hamsandwich>
  23. #include <cstrike>
  24. #include <fun>
  25. #include <fakemeta>
  26.  
  27. #if defined _stripweapons_included
  28. #endinput
  29. #endif
  30. #define _stripweapons_included
  31.  
  32. enum /* Weapon types */
  33. {
  34. Primary = 1
  35. , Secondary
  36. , Knife
  37. , Grenades
  38. , C4
  39. };
  40.  
  41. stock StripWeapons(id, Type, bool: bSwitchIfActive = true)
  42. {
  43. new iReturn;
  44.  
  45. if(is_user_alive(id))
  46. {
  47. new iEntity, iWeapon;
  48. while((iWeapon = GetWeaponFromSlot(id, Type, iEntity)) > 0)
  49. iReturn = ham_strip_user_weapon(id, iWeapon, Type, bSwitchIfActive);
  50. }
  51.  
  52. return iReturn;
  53. }
  54.  
  55. stock GetWeaponFromSlot( id , iSlot , &iEntity )
  56. {
  57. if ( !( 1 <= iSlot <= 5 ) )
  58. return 0;
  59.  
  60. iEntity = 0;
  61. const m_rgpPlayerItems_Slot0 = 367;
  62. const m_iId = 43;
  63. const EXTRAOFFSET_WEAPONS = 4;
  64.  
  65. iEntity = get_pdata_cbase( id , m_rgpPlayerItems_Slot0 + iSlot , EXTRAOFFSET_WEAPONS );
  66.  
  67. return ( iEntity > 0 ) ? get_pdata_int( iEntity , m_iId , EXTRAOFFSET_WEAPONS ) : 0;
  68. }
  69.  
  70. stock ham_strip_user_weapon(id, iCswId, iSlot = 0, bool:bSwitchIfActive = true)
  71. {
  72. new iWeapon
  73. if( !iSlot )
  74. {
  75. static const iWeaponsSlots[] = {
  76. -1,
  77. 2, //CSW_P228
  78. -1,
  79. 1, //CSW_SCOUT
  80. 4, //CSW_HEGRENADE
  81. 1, //CSW_XM1014
  82. 5, //CSW_C4
  83. 1, //CSW_MAC10
  84. 1, //CSW_AUG
  85. 4, //CSW_SMOKEGRENADE
  86. 2, //CSW_ELITE
  87. 2, //CSW_FIVESEVEN
  88. 1, //CSW_UMP45
  89. 1, //CSW_SG550
  90. 1, //CSW_GALIL
  91. 1, //CSW_FAMAS
  92. 2, //CSW_USP
  93. 2, //CSW_GLOCK18
  94. 1, //CSW_AWP
  95. 1, //CSW_MP5NAVY
  96. 1, //CSW_M249
  97. 1, //CSW_M3
  98. 1, //CSW_M4A1
  99. 1, //CSW_TMP
  100. 1, //CSW_G3SG1
  101. 4, //CSW_FLASHBANG
  102. 2, //CSW_DEAGLE
  103. 1, //CSW_SG552
  104. 1, //CSW_AK47
  105. 3, //CSW_KNIFE
  106. 1 //CSW_P90
  107. }
  108. iSlot = iWeaponsSlots[iCswId]
  109. }
  110.  
  111. const XTRA_OFS_PLAYER = 5
  112. const m_rgpPlayerItems_Slot0 = 367
  113.  
  114. iWeapon = get_pdata_cbase(id, m_rgpPlayerItems_Slot0 + iSlot, XTRA_OFS_PLAYER)
  115.  
  116. const XTRA_OFS_WEAPON = 4
  117. const m_pNext = 42
  118. const m_iId = 43
  119.  
  120. while( iWeapon > 0 )
  121. {
  122. if( get_pdata_int(iWeapon, m_iId, XTRA_OFS_WEAPON) == iCswId )
  123. {
  124. break
  125. }
  126. iWeapon = get_pdata_cbase(iWeapon, m_pNext, XTRA_OFS_WEAPON)
  127. }
  128.  
  129. if( iWeapon > 0 )
  130. {
  131. const m_pActiveItem = 373
  132. if( bSwitchIfActive && get_pdata_cbase(id, m_pActiveItem, XTRA_OFS_PLAYER) == iWeapon )
  133. {
  134. ExecuteHamB(Ham_Weapon_RetireWeapon, iWeapon)
  135. }
  136.  
  137. if( ExecuteHamB(Ham_RemovePlayerItem, id, iWeapon) )
  138. {
  139. user_has_weapon(id, iCswId, 0)
  140. ExecuteHamB(Ham_Item_Kill, iWeapon)
  141. return 1
  142. }
  143. }
  144.  
  145. return 0
  146. }
  147.  
  148. #define PluginName "Weapons Menu Creator"
  149. #define PluginVersion "1.0"
  150. #define PluginAuthor "HamletEagle"
  151.  
  152. enum
  153. {
  154. PrimaryWeapons,
  155. SecondaryWeapons,
  156. PrimaryMenu,
  157. SecondaryMenu
  158. }
  159.  
  160. enum _:WeaponInfo
  161. {
  162. WeaponName [64],
  163. WeaponAcces[64],
  164. WeaponBullets,
  165. WeaponPrice
  166. }
  167.  
  168. enum
  169. {
  170. PrimarySection = 1,
  171. SecondarySection
  172. }
  173.  
  174. const m_iAccount = 115
  175. const XO_PLAYER = 5
  176.  
  177. new const ConfigFileName[] = "weapons_menu_creator.ini"
  178.  
  179. new HandleConfigFile[256]
  180. new HandlePrimaryMenu
  181. new HandleSecondaryMenu
  182. new CvarControlTeamAcces
  183. new AdminDefault
  184. new Array:ArrayPrimaryWeapons
  185. new Array:ArraySecondaryWeapons
  186. new bool:ChoosedWeapons[2][33]
  187.  
  188. public plugin_init()
  189. {
  190. register_plugin(PluginName,PluginVersion,PluginAuthor)
  191.  
  192. ArrayPrimaryWeapons = ArrayCreate(WeaponInfo)
  193. ArraySecondaryWeapons = ArrayCreate(WeaponInfo)
  194.  
  195. register_clcmd("say /fegyverek" , "ClientCommand_Weapons")
  196. register_clcmd("say_team /fegyverek", "ClientCommand_Weapons")
  197.  
  198. RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn", true)
  199. register_event("TeamInfo", "OnTeamInfo_Event", "a")
  200.  
  201. CvarControlTeamAcces = register_cvar( "team_acces", "0" )
  202. CreateWeaponsFile()
  203. }
  204.  
  205. public ClientCommand_Weapons(id)
  206. {
  207. new TeamAcces = get_pcvar_num(CvarControlTeamAcces)
  208. if(!is_user_alive(id))
  209. {
  210. client_print(id, print_chat, "Nem nyithatod meg a menut mert halott vagy!")
  211. }
  212.  
  213. else if(TeamAcces !=0 && get_user_team(id) != TeamAcces)
  214. {
  215. client_print(id, print_chat, "Nincs elerhetoseged ehez a parancshoz!")
  216. }
  217.  
  218. else
  219. {
  220. ChooseBestMenu(id, 1)
  221. }
  222. }
  223.  
  224. CreateWeaponsFile()
  225. {
  226. new HandleConfigsDir[128]
  227. get_configsdir(HandleConfigsDir, charsmax(HandleConfigsDir))
  228. formatex(HandleConfigFile, charsmax(HandleConfigFile), "%s/%s", HandleConfigsDir, ConfigFileName)
  229.  
  230. if(!file_exists(HandleConfigFile))
  231. {
  232. new FilePointer = fopen(HandleConfigFile, "w"), i
  233. if(FilePointer)
  234. {
  235. new const Weapons[][] =
  236. {
  237. "Scout", "XM1014", "MAC10",
  238. "Aug", "UMP45", "SG550",
  239. "Galil", "Famas", "Awp",
  240. "MP5NAVY", "M249", "M3",
  241. "M4A1", "TMP", "G3SG1",
  242. "SG552", "AK47", "P90",
  243. "P228", "Elite", "Fiveseven", //pistols starts from here. line 18
  244. "USP", "GLOCK18", "Deagle" //line 23
  245. };
  246.  
  247. fputs(FilePointer, ";Fegyver Menu Keszito^n")
  248. fputs(FilePointer, "^n")
  249. fputs(FilePointer, ";Itt van egy lista az ElsodlegesFegyverek+MasodlagosFegyverek-rol^n")
  250. fputs(FilePointer, ";Valassz annyit amennyit szeretnel^n")
  251. fputs(FilePointer, ";Hiba lehet: [FUN] Targy ^"fegyver_nev^" sikertelen keszites^n")
  252. fputs(FilePointer, ";A fegyver neveben kell a hibakat keresni^n")
  253. fputs(FilePointer, "^n")
  254. fputs(FilePointer, ";Pelda:^n")
  255. fputs(FilePointer, ";(FegyverNev) (Tolteny) (Kihasznalhatja) (A'ra)^n")
  256. fputs(FilePointer, ";AK47 120 ALL 0^n")
  257. fputs(FilePointer, "^n")
  258. fputs(FilePointer, ";A fegyver nevet kell hasznalni:^n")
  259. fputs(FilePointer, "^n")
  260. fputs(FilePointer, ";1.Fegyver Nevek:^n")
  261.  
  262. //add PrimaryWeapons weapons to file
  263. for(i = 0; i < sizeof Weapons - 6; i++)
  264. {
  265. fprintf(FilePointer, ";%s^n", Weapons[i])
  266. }
  267. fputs(FilePointer, "^n")
  268. fputs(FilePointer, ";2.Pisztoly Nevek^n")
  269.  
  270. //add SecondaryWeapons weapons to file
  271. for(i = sizeof Weapons - 5 ; i < sizeof Weapons; i++)
  272. {
  273. fprintf(FilePointer, ";%s^n", Weapons[i])
  274. }
  275. fputs(FilePointer, "^n")
  276. fputs(FilePointer, ";Admin Beallitasok a fegyvereknek:^n")
  277. fputs(FilePointer, ";ALL - osszes jatekos hasznalhatja^n")
  278. fputs(FilePointer, ";NOONE - Korlatozott mindenkinek. A targy nem latszik a menuben!^n")
  279. fputs(FilePointer, ";ADMIN - Csak azok hasznalhatjak akiknek van ^"AdminAcces^" jogosultsaga^n")
  280. fputs(FilePointer, "AdminAcces: d betu^n")
  281. fputs(FilePointer, "^n")
  282. fputs(FilePointer, ";Menu keszites inditasa:^n")
  283. fputs(FilePointer, "^n")
  284. fputs(FilePointer, "[ElsodlegesFegyverek]^n")
  285. fputs(FilePointer, "^n")
  286. fputs(FilePointer, "[MasodlagosFegyverek]^n")
  287. }
  288. fclose(FilePointer)
  289. }
  290.  
  291. ReadWeaponsFile()
  292. }
  293.  
  294. ReadWeaponsFile()
  295. {
  296. new FilePointer = fopen(HandleConfigFile , "rt")
  297. if(!FilePointer)
  298. {
  299. return
  300. }
  301.  
  302. new FileData[90], FileSection, Name[64], Bullets[8], Access[24], Price[8]
  303. new Data[WeaponInfo]
  304.  
  305. while(!feof(FilePointer))
  306. {
  307. fgets(FilePointer, FileData, charsmax(FileData))
  308. trim(FileData)
  309.  
  310. if(!FileData[0] || FileData[0] == ';' || FileData[0] == '#' || FileData[0] == '/')
  311. {
  312. continue
  313. }
  314.  
  315. if(FileData[0] == '[')
  316. {
  317. FileSection++
  318. continue
  319. }
  320.  
  321. if(equal(FileData, "AdminAcces", 10))
  322. {
  323. parse
  324. (
  325. FileData,
  326. Name, charsmax(Name),
  327. Access, charsmax(Access)
  328. )
  329. AdminDefault = read_flags(Access)
  330. }
  331. else
  332. {
  333. parse
  334. (
  335. FileData,
  336. Name , charsmax(Name),
  337. Bullets , charsmax(Bullets),
  338. Access , charsmax(Access),
  339. Price , charsmax(Price)
  340. )
  341.  
  342. if(equal(Access, "NOONE"))
  343. {
  344. continue
  345. }
  346.  
  347. else
  348. {
  349. copy(Data[WeaponName], charsmax(Data[WeaponName] ), Name)
  350. copy(Data[WeaponAcces], charsmax(Data[WeaponAcces] ), Access)
  351.  
  352. Data[WeaponBullets] = str_to_num(Bullets)
  353. Data[WeaponPrice] = str_to_num(Price)
  354.  
  355. switch(FileSection)
  356. {
  357. case PrimarySection:
  358. {
  359. ArrayPushArray(ArrayPrimaryWeapons, Data)
  360. }
  361.  
  362. case SecondarySection:
  363. {
  364. ArrayPushArray(ArraySecondaryWeapons,Data)
  365. }
  366. }
  367. }
  368. }
  369. }
  370.  
  371. fclose(FilePointer)
  372. BuildMenu()
  373. }
  374.  
  375. BuildMenu()
  376. {
  377. HandlePrimaryMenu = menu_create("Elsodleges Fegyverek", "PrimaryWeapMenuHandle")
  378. HandleSecondaryMenu = menu_create("Masodlagos Fegyverek", "SecondaruWeapMenuHandle")
  379.  
  380. new Data[WeaponInfo]
  381.  
  382. new Size = ArraySize(ArrayPrimaryWeapons), i
  383. for(i = 0; i < Size; i++ )
  384. {
  385. ArrayGetArray(ArrayPrimaryWeapons, i, Data)
  386. AddItemToMenu(HandlePrimaryMenu, Data)
  387. }
  388.  
  389. Size = ArraySize(ArraySecondaryWeapons)
  390. for(i = 0; i < Size; i++)
  391. {
  392. ArrayGetArray(ArraySecondaryWeapons, i, Data)
  393. AddItemToMenu(HandleSecondaryMenu, Data)
  394. }
  395. }
  396.  
  397. public PrimaryWeapMenuHandle(id, HandlePrimaryMenu, item)
  398. {
  399. if(item == MENU_EXIT && is_user_connected(id))
  400. {
  401. menu_cancel(id)
  402. return
  403. }
  404. ChoosedWeapons[PrimaryWeapons][id] = true
  405. HandleBothMenus(id,item, 1)
  406. }
  407.  
  408. public SecondaruWeapMenuHandle(id, HandleSecondaryMenu, item)
  409. {
  410. if(item == MENU_EXIT && is_user_connected(id))
  411. {
  412. menu_cancel(id)
  413. return
  414. }
  415. ChoosedWeapons[SecondaryWeapons][id] = true
  416. HandleBothMenus(id,item, 2)
  417. }
  418.  
  419. public CBasePlayer_Spawn(id)
  420. {
  421. if(!is_user_alive(id))
  422. {
  423. return
  424. }
  425.  
  426. ChoosedWeapons[PrimaryWeapons ][id] = false
  427. ChoosedWeapons[SecondaryWeapons][id] = false
  428.  
  429. new TeamAcces = get_pcvar_num(CvarControlTeamAcces)
  430. if(TeamAcces !=0 && get_user_team(id) != TeamAcces)
  431. {
  432. return
  433. }
  434.  
  435. ChooseBestMenu(id, 0)
  436. }
  437.  
  438. ChooseBestMenu(id, Message)
  439. {
  440. if(!ChoosedWeapons[PrimaryWeapons][id])
  441. {
  442. if(ArraySize(ArrayPrimaryWeapons))
  443. {
  444. DisplayMenu(id, PrimaryMenu)
  445. }
  446. else if(!ChoosedWeapons[SecondaryWeapons][id])
  447. {
  448. DisplayMenu(id, SecondaryMenu)
  449. ChoosedWeapons[PrimaryWeapons][id] = true
  450. }
  451. }
  452. else if(!ChoosedWeapons[SecondaryWeapons][id])
  453. {
  454. if(ArraySize(ArraySecondaryWeapons))
  455. {
  456. DisplayMenu(id, SecondaryMenu)
  457. }
  458. else if(!ChoosedWeapons[PrimaryWeapons][id])
  459. {
  460. DisplayMenu(id, PrimaryMenu)
  461. ChoosedWeapons[SecondaryWeapons][id] = true
  462. }
  463. }
  464. else if(Message)
  465. {
  466. client_print(id, print_chat, "Mar kivalasztottad a fegyvered!")
  467. }
  468. }
  469.  
  470. public OnTeamInfo_Event()
  471. {
  472. show_menu(read_data(1), 0, "^n", 1)
  473. }
  474.  
  475. public plugin_end()
  476. {
  477. ArrayDestroy(ArrayPrimaryWeapons)
  478. ArrayDestroy(ArraySecondaryWeapons)
  479.  
  480. menu_destroy(HandlePrimaryMenu)
  481. menu_destroy(HandleSecondaryMenu)
  482. }
  483.  
  484. AddItemToMenu(Menu, Data[WeaponInfo])
  485. {
  486. new MenuText[64]
  487.  
  488. if(equal(Data[WeaponAcces], "ALL"))
  489. {
  490. formatex(MenuText, charsmax(MenuText),"%s\R\w%i", Data[WeaponName], Data[WeaponPrice])
  491. menu_additem(Menu, MenuText, "", 0)
  492. }
  493. else
  494. {
  495. if(equal(Data[WeaponAcces], "ADMIN"))
  496. {
  497. formatex(MenuText, charsmax(MenuText), "%s\R\w%i", Data[WeaponName], Data[WeaponPrice])
  498. menu_additem(Menu, MenuText, "", AdminDefault)
  499. }
  500. }
  501. }
  502.  
  503. HandleBothMenus(id, item, Type)
  504. {
  505. if(!is_user_alive(id))
  506. {
  507. return
  508. }
  509.  
  510. new Data[WeaponInfo], Money = get_pdata_int(id, m_iAccount, XO_PLAYER), FinalWeaponName[64]
  511.  
  512. switch(Type)
  513. {
  514. case 1:
  515. {
  516. ArrayGetArray(ArrayPrimaryWeapons, item, Data)
  517. menu_cancel(id)
  518.  
  519.  
  520. if(ArraySize(ArraySecondaryWeapons) != 0)
  521. {
  522. menu_display(id, HandleSecondaryMenu, 0)
  523. }
  524. }
  525.  
  526. case 2:
  527. {
  528. ArrayGetArray(ArraySecondaryWeapons, item, Data)
  529. menu_cancel(id)
  530. }
  531. }
  532.  
  533. //not enough money to buy
  534. if(Money < Data[WeaponPrice])
  535. {
  536. client_print(id, print_chat, "Sajnos nincs eleg penzed!")
  537. menu_display(id, HandlePrimaryMenu, 0)
  538. }
  539.  
  540. else if(Data[WeaponPrice] != 0)
  541. {
  542. cs_set_user_money(id, Money - Data[WeaponPrice], 1)
  543. }
  544.  
  545. for(new i; i < sizeof Data[WeaponName]; i++)
  546. {
  547. FinalWeaponName[i] = tolower(Data[WeaponName][i])
  548. }
  549.  
  550. format(FinalWeaponName, charsmax(FinalWeaponName), "weapon_%s", FinalWeaponName)
  551.  
  552. give_item(id, FinalWeaponName)
  553. StripWeapons(id, Type)
  554. cs_set_user_bpammo(id, get_weaponid(FinalWeaponName), Data[WeaponBullets])
  555. }
  556.  
  557. DisplayMenu(id, MenuType)
  558. {
  559. switch(MenuType)
  560. {
  561. case PrimaryMenu:
  562. {
  563. if(ArraySize(ArrayPrimaryWeapons))
  564. {
  565. menu_display(id, HandlePrimaryMenu, 0)
  566. }
  567. }
  568. case SecondaryMenu:
  569. {
  570. if(ArraySize(ArraySecondaryWeapons))
  571. {
  572. menu_display(id, HandleSecondaryMenu, 0)
  573. }
  574. }
  575. }
  576. }
  577.