HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* Copyright © 2009, ConnorMcLeod
  2.  
  3. Awp CrossHair is free software;
  4. you can redistribute it and/or modify it under the terms of the
  5. GNU General Public License as published by the Free Software Foundation.
  6.  
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11.  
  12. You should have received a copy of the GNU General Public License
  13. along with Awp CrossHair; if not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17.  
  18. #include <amxmodx>
  19. #include <amxmisc>
  20.  
  21. #define PLUGIN "Snipers Crosshairs"
  22. #define AUTHOR "ConnorMcLeod"
  23. #define VERSION "0.0.3"
  24.  
  25. #define MAX_PLAYERS 32
  26.  
  27. #define HasSniperCrosshair(%1) ( g_iFlags & (1<<%1) )
  28.  
  29. const WEAPONS_9MM = (1<<CSW_ELITE)|(1<<CSW_GLOCK18)|(1<<CSW_MP5NAVY)|(1<<CSW_TMP)
  30.  
  31. new g_iCurWeapon[MAX_PLAYERS+1]
  32. new g_bInZoom[MAX_PLAYERS+1]
  33. new g_bFake[MAX_PLAYERS+1]
  34.  
  35. new g_338magnum[MAX_PLAYERS+1]
  36. new g_9mm[MAX_PLAYERS+1]
  37.  
  38. new gmsgCurWeapon, gmsgAmmoX
  39.  
  40. new g_iFlags
  41.  
  42. public plugin_init()
  43. {
  44. register_plugin(PLUGIN, VERSION, AUTHOR)
  45.  
  46. register_concmd("amx_snipers_crosshair", "AdminCommand_Crosshair", ADMIN_CFG, "amx_snipers_crosshair <flags>")
  47.  
  48. register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
  49. register_event("AmmoX", "Event_AmmoX", "be", "1=1", "1=10")
  50. register_event("SetFOV", "Event_SetFOV", "be")
  51.  
  52. gmsgCurWeapon = get_user_msgid("CurWeapon")
  53. gmsgAmmoX = get_user_msgid("AmmoX")
  54. }
  55.  
  56. public AdminCommand_Crosshair(id, level, cid)
  57. {
  58. if( !cmd_access(id, level, cid, 2) )
  59. {
  60. return PLUGIN_HANDLED
  61. }
  62.  
  63. new szFlags[5]
  64. read_argv(1, szFlags, charsmax(szFlags))
  65.  
  66. static const iSnipersIds[] = {CSW_SCOUT, CSW_SG550, CSW_AWP, CSW_G3SG1}
  67. new i, cLetter, iVal
  68. g_iFlags = 0
  69.  
  70. while( (cLetter = szFlags[i++]) )
  71. {
  72. iVal = cLetter - 'a'
  73. if( 0 <= iVal < sizeof(iSnipersIds) )
  74. {
  75. g_iFlags |= (1<<iSnipersIds[iVal])
  76. }
  77. }
  78.  
  79. new iPlayers[MAX_PLAYERS], iNum, iPlayer
  80. new iClip, iBpAmmo, iWeaponId
  81.  
  82. get_players(iPlayers, iNum, "a")
  83.  
  84. for(new i; i<iNum; i++)
  85. {
  86. iPlayer = iPlayers[i]
  87. if( g_bInZoom[iPlayer] )
  88. {
  89. continue
  90. }
  91. iWeaponId = get_user_weapon(iPlayer, iClip, iBpAmmo)
  92. if( HasSniperCrosshair(iWeaponId) )
  93. {
  94. emessage_begin(MSG_ONE_UNRELIABLE, gmsgCurWeapon, _, iPlayer)
  95. ewrite_byte(1)
  96. ewrite_byte(iWeaponId)
  97. ewrite_byte(iClip)
  98. emessage_end()
  99. }
  100. }
  101.  
  102. return PLUGIN_HANDLED
  103. }
  104.  
  105. public Event_SetFOV( id )
  106. {
  107. g_bInZoom[id] = ( 0 < read_data(1) < 55 )
  108. }
  109.  
  110. public Event_CurWeapon(id)
  111. {
  112. new iCurWeapon = read_data(2)
  113.  
  114. if( iCurWeapon == g_iCurWeapon[id] )
  115. {
  116. if( HasSniperCrosshair(iCurWeapon) )
  117. {
  118. if( g_bInZoom[id] )
  119. {
  120. return
  121. }
  122. }
  123. else
  124. {
  125. return
  126. }
  127. }
  128. else
  129. {
  130. g_iCurWeapon[id] = iCurWeapon
  131.  
  132. if( !HasSniperCrosshair(iCurWeapon) )
  133. {
  134. if( WEAPONS_9MM & (1<<iCurWeapon) && g_bFake[id] )
  135. {
  136. Send_AmmoX(id, 0)
  137. }
  138. return
  139. }
  140.  
  141. if( g_bInZoom[id] )
  142. {
  143. return
  144. }
  145. }
  146.  
  147. new iWeapon
  148. switch( iCurWeapon )
  149. {
  150. case CSW_SG550:iWeapon = CSW_GALIL
  151. case CSW_AWP:iWeapon = CSW_ELITE
  152. default:iWeapon = CSW_AK47
  153. }
  154.  
  155. message_begin(MSG_ONE_UNRELIABLE, gmsgCurWeapon, _, id)
  156. write_byte(1)
  157. write_byte(iWeapon)
  158. write_byte(read_data(3))
  159. message_end()
  160.  
  161. if( iWeapon == CSW_ELITE && !g_bFake[id] )
  162. {
  163. Send_AmmoX(id, 1)
  164. }
  165. }
  166.  
  167. public Event_AmmoX(id)
  168. {
  169. if( read_data(1) == 1)
  170. {
  171. g_338magnum[id] = read_data(2)
  172. }
  173. else
  174. {
  175. g_9mm[id] = read_data(2)
  176. }
  177.  
  178. if( g_iCurWeapon[id] == CSW_AWP && !g_bInZoom[id] )
  179. {
  180. Send_AmmoX(id, 1)
  181. }
  182. }
  183.  
  184. Send_AmmoX(id, fake)
  185. {
  186. g_bFake[id] = fake
  187.  
  188. message_begin(MSG_ONE_UNRELIABLE, gmsgAmmoX, _, id)
  189. write_byte(10)
  190. write_byte(fake ? g_338magnum[id] : g_9mm[id])
  191. message_end()
  192. }