HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.   Fordította: BBk
  3. */
  4.  
  5. /*
  6. ********************************************************************************
  7. * AMX Mod X script.
  8. *
  9. * Weapon Icon Display (weapon_icon.sma)
  10. * Copyright (C) 2008-2009 by zenix and fixed by hoboman313
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * when you downloaded AMX Mod X; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. *
  26. * In addition, as a special exception, the author gives permission to
  27. * link the code of this program with the Half-Life Game Engine ("HL
  28. * Engine") and Modified Game Libraries ("MODs") developed by Valve,
  29. * L.L.C ("Valve"). You must obey the GNU General Public License in all
  30. * respects for all of the code used other than the HL Engine and MODs
  31. * from Valve. If you modify this file, you may extend this exception
  32. * to your version of the file, but you are not obligated to do so. If
  33. * you do not wish to do so, delete this exception statement from your
  34. * version.
  35. *
  36. *********************************************************************************
  37. */
  38.  
  39. /*
  40. * For a full plugin description read: http://forums.alliedmods.net/showthread.php?t=69664
  41. */
  42.  
  43. #include <amxmodx>
  44.  
  45. #define PLUGIN "Weapon Icon"
  46. #define VERSION "1.2"
  47. #define AUTHOR "hoboman313/Zenix"
  48.  
  49. #define MAX_PLAYERS 32
  50.  
  51. new iconstatus, pcv_iloc
  52. new user_icons[MAX_PLAYERS+1][16]
  53.  
  54.  
  55. public plugin_init()
  56. {
  57. register_plugin(PLUGIN, VERSION, AUTHOR)
  58.  
  59. register_event("CurWeapon", "update_icon", "be", "1=1")
  60. register_event("AmmoX", "draw_icon", "be")
  61. register_event("DeathMsg", "event_death", "a")
  62.  
  63. pcv_iloc = register_cvar("amx_weapon_location", "1")
  64.  
  65. check_icon_loc()
  66. }
  67.  
  68. public update_icon(id)
  69. {
  70. remove_weapon_icon(id)
  71.  
  72. check_icon_loc()
  73.  
  74. if( get_pcvar_num(pcv_iloc) == 0 || is_user_bot(id) )
  75. return
  76.  
  77. static sprite[16], iwpn, clip, ammo
  78.  
  79. iwpn = get_user_weapon(id, clip, ammo)
  80.  
  81. switch(iwpn)
  82. {
  83. case CSW_P228:
  84. sprite = "d_p228"
  85. case CSW_SCOUT:
  86. sprite = "d_scout"
  87. case CSW_HEGRENADE:
  88. sprite = "d_grenade"
  89. case CSW_XM1014:
  90. sprite = "d_xm1014"
  91. case CSW_MAC10:
  92. sprite = "d_mac10"
  93. case CSW_AUG:
  94. sprite = "d_aug"
  95. case CSW_SMOKEGRENADE:
  96. sprite = "d_flashbang"
  97. case CSW_ELITE:
  98. sprite = "d_elite"
  99. case CSW_FIVESEVEN:
  100. sprite = "d_fiveseven"
  101. case CSW_UMP45:
  102. sprite = "d_ump45"
  103. case CSW_SG550:
  104. sprite = "d_sg550"
  105. case CSW_GALIL:
  106. sprite = "d_galil"
  107. case CSW_FAMAS:
  108. sprite = "d_famas"
  109. case CSW_USP:
  110. sprite = "d_usp"
  111. case CSW_MP5NAVY:
  112. sprite = "d_mp5navy"
  113. case CSW_M249:
  114. sprite = "d_m249"
  115. case CSW_M3:
  116. sprite = "d_m3"
  117. case CSW_M4A1:
  118. sprite = "d_m4a1"
  119. case CSW_TMP:
  120. sprite = "d_tmp"
  121. case CSW_G3SG1:
  122. sprite = "d_g3sg1"
  123. case CSW_FLASHBANG:
  124. sprite = "d_flashbang"
  125. case CSW_DEAGLE:
  126. sprite = "d_deagle"
  127. case CSW_SG552:
  128. sprite = "d_sg552"
  129. case CSW_AK47:
  130. sprite = "d_ak47"
  131. case CSW_KNIFE:
  132. sprite = "d_knife"
  133. case CSW_P90:
  134. sprite = "d_p90"
  135. case CSW_GLOCK18:
  136. sprite = "d_glock18"
  137. case CSW_AWP:
  138. sprite = "d_awp"
  139. default:
  140. return
  141. }
  142. user_icons[id] = sprite
  143.  
  144. draw_icon(id)
  145.  
  146. return
  147. }
  148.  
  149.  
  150. public draw_icon(id)
  151. {
  152. static iwpn, clip, ammo, icon_color[3]
  153.  
  154. iwpn = get_user_weapon(id, clip, ammo)
  155.  
  156. // ammo check, this is for the color of the icon
  157. if ((ammo == 0 && clip == 0))
  158. icon_color = {255, 0, 0} // outta ammo!
  159. else if ( ammo==0 && iwpn!=CSW_KNIFE)
  160. icon_color = {255, 160, 0} // last clip!
  161. else
  162. icon_color = {0, 160, 0}//green icon...decent ammo
  163.  
  164.  
  165. // draw the sprite itself
  166. message_begin(MSG_ONE,iconstatus,{0,0,0},id)
  167. write_byte(1) // status (0=hide, 1=show, 2=flash)
  168. write_string(user_icons[id]) // sprite name
  169. write_byte(icon_color[0]) // red
  170. write_byte(icon_color[1]) // green
  171. write_byte(icon_color[2]) // blue
  172. message_end()
  173. }
  174.  
  175.  
  176. public remove_weapon_icon(id)
  177. {
  178. message_begin(MSG_ONE,iconstatus,{0,0,0},id)
  179. write_byte(0)
  180. write_string(user_icons[id])
  181. message_end()
  182. }
  183.  
  184.  
  185. public event_death()
  186. {
  187. new id = read_data(2) // the dead player's ID (1-32)
  188.  
  189. if (!is_user_bot(id))
  190. remove_weapon_icon(id)
  191. }
  192.  
  193.  
  194. public check_icon_loc()
  195. {
  196. new value = get_pcvar_num(pcv_iloc)
  197.  
  198. if (value == 1)
  199. iconstatus = get_user_msgid("StatusIcon")
  200. else if (value == 2)
  201. iconstatus = get_user_msgid("Scenario")
  202. else
  203. iconstatus = 0
  204.  
  205. return PLUGIN_CONTINUE
  206. }
  207.  
  208.  
  209.