HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. v0.1 - [11.10.2011] First release
  3. v0.1a - [25.01.2012] Optimizations
  4. v0.2 - [30.01.2012] Fixed bug (brush water blocked beam)
  5. v0.2a - [31.01.2012] Optimization added
  6.  
  7. http://aghl.ru/forum/ - Russian Half-Life and Adrenaline Gamer Community
  8.  
  9. special thanks to unnamed :)
  10. */
  11.  
  12. #include <amxmodx>
  13. #include <fakemeta>
  14. #include <xs>
  15.  
  16. /* <<< OPTIONS >>> */
  17.  
  18. #define Half_Life // remove comment for Half-Life (Äëÿ Õàëô-ëàéô óäàëèòå êîììåíòàðèé)
  19.  
  20. #define BEAM_NOISE 0 // noise
  21. #define BEAM_BRIGHTNESS 256.0 // brightness
  22. #define BEAM_WIDTH 7.5 // width
  23.  
  24. #define COLOR_I {255.0, 0.0, 0.0} // team = terrorists, or weapon = crossbow
  25. #define COLOR_II {0.0, 0.0, 255.0} // team = counter-terrorists, or weapon = python
  26.  
  27. /* <<< END >>> */
  28.  
  29. #define SNIPER_WEAPON_CS(%1) %1 & (1 << CSW_SCOUT | 1 << CSW_AWP | 1 << CSW_G3SG1 | 1 << CSW_SG550)
  30. #define SNIPER_WEAPON_HL(%1) %1 & (1 << HLW_PYTHON | 1 << HLW_CROSSBOW)
  31.  
  32. #define None 0
  33.  
  34. enum _:Beam_Rendering_Mode
  35. {
  36. beam_Hide,
  37. beam_Show
  38. }
  39.  
  40. enum _:CStrike_Teams(<<= 1)
  41. {
  42. team_Terrorists = 2,
  43. team_CTerrorists
  44. }
  45.  
  46. enum _:Plugin_Data
  47. {
  48. bit_In_Zoom,
  49. _client_beam[32],
  50. _Sprite_Index
  51. }
  52.  
  53. new g_plugin_data[Plugin_Data]
  54.  
  55. #define PLUGIN "hl_laser_beam"
  56. #define VERSION "0.2a"
  57. #define AUTHOR "KORD_12.7" // & Turanga_Leela
  58.  
  59. Beam_Create(const endIndex)
  60. {
  61. static iEnt_Class
  62. new beam
  63.  
  64. if(iEnt_Class || (iEnt_Class = engfunc(EngFunc_AllocString, "beam")))
  65. {
  66. beam = engfunc(EngFunc_CreateNamedEntity, iEnt_Class)
  67. }
  68.  
  69. if(pev_valid(beam))
  70. {
  71. set_pev(beam, pev_body, BEAM_NOISE)
  72. set_pev(beam, pev_renderamt, BEAM_BRIGHTNESS)
  73. set_pev(beam, pev_flags, pev(beam, pev_flags) | FL_CUSTOMENTITY)
  74. set_pev(beam, pev_model, "sprites/laserbeam.spr")
  75. set_pev(beam, pev_modelindex, g_plugin_data[_Sprite_Index])
  76. set_pev(beam, pev_scale, BEAM_WIDTH)
  77.  
  78. set_pev(beam, pev_skin, endIndex)
  79. //set_pev(beam, pev_skin, (endIndex | ((pev(beam, pev_skin) & (0x10000 - 0x2000)) << 0xd)))
  80. set_pev(beam, pev_rendermode, (pev(beam, pev_rendermode) & 0xF0) | 1 & 0x0F)
  81. set_pev(beam, pev_sequence, (pev(beam, pev_sequence) & 0x0FFF) | ((0 & 0xF) << 12))
  82. set_pev(beam, pev_aiment, endIndex)
  83. set_pev(beam, pev_framerate, 1.0)
  84.  
  85. return beam
  86. }
  87.  
  88. return None
  89. }
  90.  
  91. public client_putinserver(id)
  92. {
  93. if(!g_plugin_data[id])
  94. {
  95. g_plugin_data[id] = Beam_Create(id | 0x2000)
  96. change_visibility(g_plugin_data[id], beam_Hide)
  97. }
  98. }
  99.  
  100. public id_post_think(id)
  101. {
  102. if(g_plugin_data[bit_In_Zoom] & 1 << (id - 1))
  103. {
  104. static
  105.  
  106. Float:flStartPos[3],
  107. Float:aim_start[3],
  108. Float:aim_view_ofs[3],
  109. Float:aim_dest[3],
  110. Float:flOrigin[3],
  111. Float:flEndPos[3],
  112. Float:flMins[3],
  113. Float:flMaxs[3],
  114. iEntity,
  115. iBeamEntity
  116.  
  117. iBeamEntity = g_plugin_data[id]
  118.  
  119. if(pev_valid(iBeamEntity))
  120. {
  121. iEntity = pev(iBeamEntity, pev_skin) & 0xFFF
  122.  
  123. switch(pev_valid(iEntity))
  124. {
  125. case None:
  126. {
  127. return
  128. }
  129.  
  130. default:
  131. {
  132. pev(iEntity, pev_origin, flEndPos)
  133. }
  134. }
  135.  
  136. pev(id, pev_origin, aim_start)
  137. pev(id, pev_view_ofs, aim_view_ofs)
  138.  
  139. xs_vec_add(aim_start, aim_view_ofs, aim_start)
  140.  
  141. pev(id, pev_v_angle, aim_dest)
  142. engfunc(EngFunc_MakeVectors, aim_dest)
  143.  
  144. global_get(glb_v_forward, aim_dest)
  145.  
  146. xs_vec_mul_scalar(aim_dest, 9999.0, aim_dest)
  147. xs_vec_add(aim_start, aim_dest, aim_dest)
  148.  
  149. engfunc(EngFunc_TraceLine, aim_start, aim_dest, 0, id, 0)
  150. get_tr2(0, TR_vecEndPos, flStartPos)
  151.  
  152. pev(iBeamEntity, pev_origin, flOrigin)
  153.  
  154. flMins[0] = floatmin(flStartPos[0], flEndPos[0])
  155. flMins[1] = floatmin(flStartPos[1], flEndPos[1])
  156. flMins[2] = floatmin(flStartPos[2], flEndPos[2])
  157.  
  158. flMaxs[0] = floatmax(flStartPos[0], flEndPos[0])
  159. flMaxs[1] = floatmax(flStartPos[1], flEndPos[1])
  160. flMaxs[2] = floatmax(flStartPos[2], flEndPos[2])
  161.  
  162. xs_vec_sub(flMins, flOrigin, flMins)
  163. xs_vec_sub(flMaxs, flOrigin, flMaxs)
  164.  
  165. set_pev(iBeamEntity, pev_mins, flMins)
  166. set_pev(iBeamEntity, pev_maxs, flMaxs)
  167.  
  168. xs_vec_sub(flMaxs, flMins, flMaxs)
  169.  
  170. set_pev(iBeamEntity, pev_size, flMaxs)
  171. engfunc(EngFunc_SetOrigin, iBeamEntity, flStartPos)
  172. }
  173. }
  174. }
  175.  
  176. public plugin_precache()
  177. {
  178. g_plugin_data[_Sprite_Index] = precache_model("sprites/laserbeam.spr")
  179. }
  180.  
  181. public client_disconnect(id)
  182. {
  183. if(pev_valid(g_plugin_data[id]))
  184. {
  185. engfunc(EngFunc_RemoveEntity, g_plugin_data[id])
  186. }
  187.  
  188. g_plugin_data[id] = None
  189. g_plugin_data[bit_In_Zoom] &= ~(1 << (id - 1))
  190. }
  191.  
  192. change_visibility(beam, mode)
  193. {
  194. if(pev_valid(beam))
  195. {
  196. new effects = pev(beam, pev_effects)
  197.  
  198. switch(mode)
  199. {
  200. case beam_Hide:
  201. {
  202. effects |= EF_NODRAW
  203. }
  204.  
  205. case beam_Show:
  206. {
  207. effects &= ~EF_NODRAW
  208. }
  209. }
  210.  
  211. set_pev(beam, pev_effects, effects)
  212. }
  213. }
  214.  
  215. public client_dead()
  216. {
  217. new id = read_data(2)
  218.  
  219. g_plugin_data[bit_In_Zoom] &= ~(1 << (id - 1))
  220. change_visibility(g_plugin_data[id], beam_Hide)
  221. }
  222.  
  223. public zoom_event(id)
  224. {
  225. new
  226.  
  227. beam = g_plugin_data[id],
  228. weapon = 1 << read_data(2)
  229.  
  230. #if !defined Half_Life
  231. if(SNIPER_WEAPON_CS(weapon) && pev(id, pev_fov) <= 40)
  232. #else
  233. if(SNIPER_WEAPON_HL(weapon) && pev(id, pev_fov) >= 20)
  234. #endif
  235. {
  236. if(pev_valid(beam))
  237. {
  238. g_plugin_data[bit_In_Zoom] |= 1 << (id - 1)
  239. #if !defined Half_Life
  240. set_pev(beam, pev_rendercolor, (1 << _:get_user_team(id)) & team_Terrorists ? COLOR_I : COLOR_II)
  241. #else
  242. set_pev(beam, pev_rendercolor, weapon & 1 << HLW_CROSSBOW ? COLOR_I : COLOR_II)
  243. #endif
  244. }
  245.  
  246. change_visibility(beam, beam_Show)
  247. }
  248.  
  249. else
  250. {
  251. g_plugin_data[bit_In_Zoom] &= ~(1 << (id - 1))
  252. change_visibility(beam, beam_Hide)
  253. }
  254. }
  255.  
  256. public plugin_init()
  257. {
  258. register_plugin(PLUGIN, VERSION, AUTHOR);
  259.  
  260. register_event("DeathMsg", "client_dead", "a")
  261. register_event("CurWeapon", "zoom_event", "be", "1=1")
  262.  
  263. register_forward(FM_AddToFullPack, "hide_beam", 1)
  264. register_forward(FM_PlayerPostThink, "id_post_think", 1)
  265. }
  266.  
  267. public hide_beam(entState, e, ent, host, iHostFlags, iPlayer, pSet)
  268. {
  269. if(g_plugin_data[bit_In_Zoom] & 1 << (host - 1))
  270. {
  271. if(ent ^ g_plugin_data[host]) return
  272.  
  273. set_es(entState, ES_RenderAmt, beam_Hide)
  274. }
  275. }
  276.