Advertisement
Guest User

Untitled

a guest
Jul 10th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.03 KB | None | 0 0
  1. #if defined __cstrike_weapons_inc__
  2. #endinput
  3. #endif
  4. #define __cstrike_weapons_inc__
  5.  
  6. #include "halflife.inc"
  7. #include "adt_trie.inc"
  8. #include "string.inc"
  9. #include "cstrike.inc"
  10. #include "string.inc"
  11.  
  12. static Handle hWeaponInfoTrie;
  13.  
  14. #define COUNTERTERRORISTTEAM 3
  15. #define TERRORISTTEAM 2
  16. #define BOTHTEAMS 0
  17. #define UNKNOWNTEAM -1
  18.  
  19. enum WeaponID
  20. {
  21. WEAPON_NONE = 0,
  22. WEAPON_P228,
  23. WEAPON_GLOCK,
  24. WEAPON_SCOUT,
  25. WEAPON_HEGRENADE,
  26. WEAPON_XM1014,
  27. WEAPON_C4,
  28. WEAPON_MAC10,
  29. WEAPON_AUG,
  30. WEAPON_SMOKEGRENADE,
  31. WEAPON_ELITE,
  32. WEAPON_FIVESEVEN,
  33. WEAPON_UMP45,
  34. WEAPON_SG550,
  35. WEAPON_GALIL,
  36. WEAPON_FAMAS,
  37. WEAPON_USP,
  38. WEAPON_AWP,
  39. WEAPON_MP5NAVY,
  40. WEAPON_M249,
  41. WEAPON_M3,
  42. WEAPON_M4A1,
  43. WEAPON_TMP,
  44. WEAPON_G3SG1,
  45. WEAPON_FLASHBANG,
  46. WEAPON_DEAGLE,
  47. WEAPON_SG552,
  48. WEAPON_AK47,
  49. WEAPON_KNIFE,
  50. WEAPON_P90,
  51. WEAPON_SHIELD,
  52. WEAPON_KEVLAR,
  53. WEAPON_ASSAULTSUIT,
  54. WEAPON_NIGHTVISION,
  55. WEAPON_GALILAR,
  56. WEAPON_BIZON,
  57. WEAPON_MAG7,
  58. WEAPON_NEGEV,
  59. WEAPON_SAWEDOFF,
  60. WEAPON_TEC9,
  61. WEAPON_TASER,
  62. WEAPON_HKP2000,
  63. WEAPON_MP7,
  64. WEAPON_MP9,
  65. WEAPON_NOVA,
  66. WEAPON_P250,
  67. WEAPON_SCAR17,
  68. WEAPON_SCAR20,
  69. WEAPON_SG556,
  70. WEAPON_SSG08,
  71. WEAPON_KNIFE_GG,
  72. WEAPON_MOLOTOV,
  73. WEAPON_DECOY,
  74. WEAPON_INCGRENADE,
  75. WEAPON_DEFUSER,
  76. };
  77. enum WeaponType
  78. {
  79. WeaponTypePistol,
  80. WeaponTypeSMG,
  81. WeaponTypeShotgun,
  82. WeaponTypeRifle,
  83. WeaponTypeSniper,
  84. WeaponTypeGrenade,
  85. WeaponTypeArmor,
  86. WeaponTypeMachineGun,
  87. WeaponTypeKnife,
  88. WeaponTypeOther,
  89. WeaponTypeShield,
  90. WeaponTypeNone,
  91. WeaponTypeTaser
  92. };
  93. enum WeaponSlot
  94. {
  95. SlotNone = -1,
  96. SlotPrimmary = 0,
  97. SlotPistol = 1,
  98. SlotKnife = 2,
  99. SlotGrenade = 3,
  100. SlotC4 = 4,
  101. SlotUnknown = 5
  102. };
  103. enum struct WeaponInfo
  104. {
  105. WeaponID InfoID;
  106. WeaponSlot InfoSlot;
  107. WeaponType InfoType;
  108. int InfoTeam;
  109. }
  110.  
  111. // new const String:weaponNames[view_as<int>(WeaponID)][] =
  112. char weaponNames[view_as<int>(WeaponID)][] =
  113. {
  114. "none", "p228", "glock", "scout",
  115. "hegrenade", "xm1014", "c4", "mac10",
  116. "aug", "smokegrenade", "elite", "fiveseven",
  117. "ump45", "sg550", "galil", "famas",
  118. "usp", "awp", "mp5navy", "m249",
  119. "m3", "m4a1", "tmp", "g3sg1",
  120. "flashbang", "deagle", "sg552", "ak47",
  121. "knife", "p90", "shield", "vest",
  122. "vesthelm", "nvgs", "galilar", "bizon",
  123. "mag7", "negev", "sawedoff", "tec9",
  124. "taser", "hkp2000", "mp7", "mp9",
  125. "nova", "p250", "scar17", "scar20",
  126. "sg556", "ssg08", "knifegg", "molotov",
  127. "decoy", "incgrenade", "defuser"
  128. };
  129. // new const WeaponType:weaponGroups[view_as<int>(WeaponID)] =
  130. WeaponType weaponGroups[view_as<int>(WeaponID)] =
  131. {
  132. _:WeaponTypeNone, _:WeaponTypePistol, _:WeaponTypePistol, _:WeaponTypeSniper,
  133. _:WeaponTypeGrenade, _:WeaponTypeShotgun, _:WeaponTypeOther, _:WeaponTypeSMG,
  134. _:WeaponTypeRifle, _:WeaponTypeGrenade, _:WeaponTypePistol, _:WeaponTypePistol,
  135. _:WeaponTypeSMG, _:WeaponTypeSniper, _:WeaponTypeRifle, _:WeaponTypeRifle,
  136. _:WeaponTypePistol, _:WeaponTypeSniper, _:WeaponTypeSMG, _:WeaponTypeMachineGun,
  137. _:WeaponTypeShotgun, _:WeaponTypeRifle, _:WeaponTypeSMG, _:WeaponTypeSniper,
  138. _:WeaponTypeGrenade, _:WeaponTypePistol, _:WeaponTypeRifle, _:WeaponTypeRifle,
  139. _:WeaponTypeKnife, _:WeaponTypeSMG, _:WeaponTypeShield, _:WeaponTypeArmor,
  140. _:WeaponTypeArmor, _:WeaponTypeOther, _:WeaponTypeRifle, _:WeaponTypeSMG,
  141. _:WeaponTypeShotgun, _:WeaponTypeMachineGun, _:WeaponTypeShotgun, _:WeaponTypePistol,
  142. _:WeaponTypeTaser, _:WeaponTypePistol, _:WeaponTypeSMG, _:WeaponTypeSMG,
  143. _:WeaponTypeShotgun, _:WeaponTypePistol, _:WeaponTypeRifle, _:WeaponTypeSniper,
  144. _:WeaponTypeRifle, _:WeaponTypeSniper, _:WeaponTypeKnife, _:WeaponTypeGrenade,
  145. _:WeaponTypeGrenade, _:WeaponTypeGrenade, _:WeaponTypeOther
  146. };
  147. // new const WeaponSlot:weaponSlots[view_as<int>(WeaponID)] =
  148. WeaponSlot weaponSlots[view_as<int>(WeaponID)] =
  149. {
  150. _:SlotUnknown, _:SlotPistol, _:SlotPistol, _:SlotPrimmary,
  151. _:SlotGrenade, _:SlotPrimmary, _:SlotC4, _:SlotPrimmary,
  152. _:SlotPrimmary, _:SlotGrenade, _:SlotPistol, _:SlotPistol,
  153. _:SlotPrimmary, _:SlotPrimmary, _:SlotPrimmary, _:SlotPrimmary,
  154. _:SlotPistol, _:SlotPrimmary, _:SlotPrimmary, _:SlotPrimmary,
  155. _:SlotPrimmary, _:SlotPrimmary, _:SlotPrimmary, _:SlotPrimmary,
  156. _:SlotGrenade, _:SlotPistol, _:SlotPrimmary, _:SlotPrimmary,
  157. _:SlotKnife, _:SlotPrimmary, _:SlotUnknown, _:SlotNone,
  158. _:SlotNone, _:SlotNone, _:SlotPrimmary, _:SlotPrimmary,
  159. _:SlotPrimmary, _:SlotPrimmary, _:SlotPrimmary, _:SlotPistol,
  160. _:SlotKnife, _:SlotPistol, _:SlotPrimmary, _:SlotPrimmary,
  161. _:SlotPrimmary, _:SlotPistol, _:SlotPrimmary, _:SlotPrimmary,
  162. _:SlotPrimmary, _:SlotPrimmary, _:SlotKnife, _:SlotGrenade,
  163. _:SlotGrenade, _:SlotGrenade, _:SlotNone
  164. };
  165. // new const BuyTeams[view_as<int>(WeaponID)] =
  166. BuyTeams[view_as<int>(WeaponID)] =
  167. {
  168. UNKNOWNTEAM, BOTHTEAMS, BOTHTEAMS, BOTHTEAMS,
  169. BOTHTEAMS, BOTHTEAMS, TERRORISTTEAM, TERRORISTTEAM,
  170. COUNTERTERRORISTTEAM, BOTHTEAMS, TERRORISTTEAM, COUNTERTERRORISTTEAM,
  171. BOTHTEAMS, COUNTERTERRORISTTEAM, TERRORISTTEAM, COUNTERTERRORISTTEAM,
  172. BOTHTEAMS, BOTHTEAMS, BOTHTEAMS, BOTHTEAMS,
  173. BOTHTEAMS, COUNTERTERRORISTTEAM, COUNTERTERRORISTTEAM, TERRORISTTEAM,
  174. BOTHTEAMS, BOTHTEAMS, TERRORISTTEAM, TERRORISTTEAM,
  175. BOTHTEAMS, BOTHTEAMS, UNKNOWNTEAM, BOTHTEAMS,
  176. BOTHTEAMS, BOTHTEAMS, TERRORISTTEAM, BOTHTEAMS,
  177. COUNTERTERRORISTTEAM, BOTHTEAMS, TERRORISTTEAM, TERRORISTTEAM,
  178. BOTHTEAMS, BOTHTEAMS, BOTHTEAMS, COUNTERTERRORISTTEAM,
  179. BOTHTEAMS, BOTHTEAMS, UNKNOWNTEAM, COUNTERTERRORISTTEAM,
  180. TERRORISTTEAM, BOTHTEAMS, BOTHTEAMS, TERRORISTTEAM,
  181. BOTHTEAMS, COUNTERTERRORISTTEAM, COUNTERTERRORISTTEAM
  182. };
  183. //-1 None
  184. // 1 ALL
  185. // 2 CSS
  186. // 3 CSGO
  187. // new const AllowedGame[view_as<int>(WeaponID)] =
  188. // {
  189. // -1, 2, 1, 2,
  190. // 1, 1, 1, 1,
  191. // 1, 1, 1, 1,
  192. // 1, 2, 2, 1,
  193. // 2, 1, 2, 1,
  194. // 2, 1, 2, 1,
  195. // 1, 1, 2, 1,
  196. // 1, 1, -1, 1,
  197. // 1, 1, 3, 3,
  198. // 3, 3, 3, 3,
  199. // 3, 3, 3, 3,
  200. // 3, 3, -1, 3,
  201. // 3, 3, 3, 3,
  202. // 3, 3, 1
  203. // };
  204. stock void CSWeapons_Init()
  205. {
  206. if(hWeaponInfoTrie == INVALID_HANDLE)
  207. {
  208. InitWeaponInfoTrie();
  209. }
  210. }
  211. stock void InitWeaponInfoTrie()
  212. {
  213. hWeaponInfoTrie = CreateTrie();
  214. WeaponInfo info;
  215. for(int i = 0; i < view_as<int>(WeaponID); i++)
  216. {
  217. info.InfoID = view_as<WeaponID>(i);
  218. info.InfoSlot = weaponSlots[view_as<WeaponID>(i)];
  219. info.InfoType = weaponGroups[view_as<WeaponID>(i)];
  220.  
  221. if(view_as<WeaponID>(i) == WEAPON_ELITE && GetEngineVersion() == Engine_CSGO)
  222. {
  223. info.InfoTeam = BOTHTEAMS;//CSGO elites are for both teams.
  224. }
  225. else
  226. {
  227. info.InfoTeam = BuyTeams[view_as<WeaponID>(i)];
  228. }
  229.  
  230. // SetTrieArray(hWeaponInfoTrie, weaponNames[WeaponID:i], info[0], _:WeaponInfo);
  231. SetTrieArray(hWeaponInfoTrie, weaponNames[WeaponID:i] , info[0], _:WeaponInfo);
  232. }
  233. }
  234. stock WeaponID GetWeaponID(const char[] weapon)
  235. {
  236. WeaponInfo info;
  237. if(GetWeaponInfo(weapon, info))
  238. return info.InfoID;
  239.  
  240. return WEAPON_NONE;
  241. }
  242. stock WeaponSlot GetWeaponSlot(const char[] weapon)
  243. {
  244. WeaponInfo info;
  245. if(GetWeaponInfo(weapon, info))
  246. return info.InfoSlot
  247.  
  248. return SlotUnknown;
  249. }
  250. stock WeaponType GetWeaponType(const char[] weapon)
  251. {
  252. WeaponInfo info;
  253. if(GetWeaponInfo(weapon, info))
  254. return info.InfoType
  255.  
  256. return WeaponTypeNone;
  257. }
  258. stock bool CanTeamBuyWeapon(int team, const char[] weapon)
  259. {
  260. if(team < TERRORISTTEAM || team > COUNTERTERRORISTTEAM)
  261. return true;
  262.  
  263. WeaponInfo info;
  264. if(GetWeaponInfo(weapon, info))
  265. {
  266. if(info.InfoTeam == 0 || info.InfoTeam == team)
  267. return true;
  268.  
  269. return false;
  270. }
  271. return true;
  272. }
  273. stock int GetWeaponPriceFromName(int client, const char[] weapon, bool defaultprice)
  274. {
  275. int WeaponID:id = GetWeaponID(weapon);
  276.  
  277. return GetWeaponPrice(client, id, defaultprice);
  278. }
  279. stock int GetWeaponPrice(int client, WeaponID id, bool defaultprice=false)
  280. {
  281. if(id > WEAPON_DEFUSER || id <= WEAPON_NONE)
  282. return 0;
  283. if(id == WEAPON_DEFUSER && GetEngineVersion() != Engine_CSGO) //Only assume on CSS
  284. return 200;
  285.  
  286. return CS_GetWeaponPrice(client, CSWeaponID:_:id, defaultprice);
  287. }
  288. stock WeaponSlot GetSlotFromWeaponID(WeaponID id)
  289. {
  290. return weaponSlots[_:id]
  291. }
  292. stock WeaponType GetWeaponTypeFromID(WeaponID id)
  293. {
  294. return weaponGroups[_:id]
  295. }
  296. stock bool GetWeaponInfo(const char[] weapon, WeaponInfo info)
  297. {
  298. if(hWeaponInfoTrie == INVALID_HANDLE)
  299. InitWeaponInfoTrie();
  300.  
  301. char CheckWeapon[64];
  302. strcopy(CheckWeapon, sizeof(CheckWeapon), weapon);
  303. int len = strlen(weapon);
  304. for(int i = 0; i < len; i++)
  305. {
  306. CheckWeapon[i] = CharToLower(weapon[i]);
  307. }
  308.  
  309. if(GetTrieArray(hWeaponInfoTrie, CheckWeapon, info[0], _:WeaponInfo))
  310. return true;
  311.  
  312. if(ReplaceString(CheckWeapon, sizeof(CheckWeapon), "weapon_", "", false) == 1 || ReplaceString(CheckWeapon, sizeof(CheckWeapon), "item_", "", false) == 1)
  313. {
  314. if(GetTrieArray(hWeaponInfoTrie, CheckWeapon, info[0], _:WeaponInfo))
  315. return true;
  316. }
  317.  
  318. return false;
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement