HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*================================================================================
  2.  
  3. -------------------------------------------
  4. -*- [ZP] Extra Item: Unlimited Clip 1.0 -*-
  5. -------------------------------------------
  6.  
  7. ~~~~~~~~~~~~~~~
  8. - Description -
  9. ~~~~~~~~~~~~~~~
  10.  
  11. This item/upgrade gives players unlimited clip ammo for a single round.
  12.  
  13. ================================================================================*/
  14.  
  15. #include <amxmodx>
  16. #include <fakemeta>
  17. #include <zombieplague>
  18.  
  19. /*================================================================================
  20.  [Plugin Customization]
  21. =================================================================================*/
  22.  
  23. new const g_item_name[] = { "Orok tolteny (Egyszeri kor)" }
  24. const g_item_cost = 10
  25.  
  26. /*============================================================================*/
  27.  
  28. // CS Offsets
  29. #if cellbits == 32
  30. const OFFSET_CLIPAMMO = 51
  31. #else
  32. const OFFSET_CLIPAMMO = 65
  33. #endif
  34. const OFFSET_LINUX_WEAPONS = 4
  35.  
  36. // Max Clip for weapons
  37. new const MAXCLIP[] = { -1, 13, -1, 10, 1, 7, -1, 30, 30, 1, 30, 20, 25, 30, 35, 25, 12, 20,
  38. 10, 30, 100, 8, 30, 30, 20, 2, 7, 30, 30, -1, 50 }
  39.  
  40. new g_itemid_infammo, g_has_unlimited_clip[33]
  41.  
  42. public plugin_init()
  43. {
  44. register_plugin("[ZP] Extra: Unlimited Clip", "1.0", "MeRcyLeZZ")
  45.  
  46. g_itemid_infammo = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_HUMAN)
  47.  
  48. register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
  49. register_message(get_user_msgid("CurWeapon"), "message_cur_weapon")
  50. }
  51.  
  52. // Player buys our upgrade, set the unlimited ammo flag
  53. public zp_extra_item_selected(player, itemid)
  54. {
  55. if (itemid == g_itemid_infammo)
  56. g_has_unlimited_clip[player] = true
  57. }
  58.  
  59. // Reset flags for all players on newround
  60. public event_round_start()
  61. {
  62. for (new id; id <= 32; id++) g_has_unlimited_clip[id] = false;
  63. }
  64.  
  65. // Unlimited clip code
  66. public message_cur_weapon(msg_id, msg_dest, msg_entity)
  67. {
  68. // Player doesn't have the unlimited clip upgrade
  69. if (!g_has_unlimited_clip[msg_entity])
  70. return;
  71.  
  72. // Player not alive or not an active weapon
  73. if (!is_user_alive(msg_entity) || get_msg_arg_int(1) != 1)
  74. return;
  75.  
  76. static weapon, clip
  77. weapon = get_msg_arg_int(2) // get weapon ID
  78. clip = get_msg_arg_int(3) // get weapon clip
  79.  
  80. // Unlimited Clip Ammo
  81. if (MAXCLIP[weapon] > 2) // skip grenades
  82. {
  83. set_msg_arg_int(3, get_msg_argtype(3), MAXCLIP[weapon]) // HUD should show full clip all the time
  84.  
  85. if (clip < 2) // refill when clip is nearly empty
  86. {
  87. // Get the weapon entity
  88. static wname[32], weapon_ent
  89. get_weaponname(weapon, wname, sizeof wname - 1)
  90. weapon_ent = fm_find_ent_by_owner(-1, wname, msg_entity)
  91.  
  92. // Set max clip on weapon
  93. fm_set_weapon_ammo(weapon_ent, MAXCLIP[weapon])
  94. }
  95. }
  96. }
  97.  
  98. // Find entity by its owner (from fakemeta_util)
  99. stock fm_find_ent_by_owner(entity, const classname[], owner)
  100. {
  101. while ((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", classname)) && pev(entity, pev_owner) != owner) {}
  102.  
  103. return entity;
  104. }
  105.  
  106. // Set Weapon Clip Ammo
  107. stock fm_set_weapon_ammo(entity, amount)
  108. {
  109. set_pdata_int(entity, OFFSET_CLIPAMMO, amount, OFFSET_LINUX_WEAPONS);
  110. }
  111. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  112. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3082\\ f0\\ fs16 \n\\ par }
  113. */
  114.