HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4. #include <xs>
  5.  
  6. #define VERSION "0.0.1"
  7. #define PLUGIN "Animated Spray"
  8.  
  9. //#define m_nCustomSprayFrames 485
  10. #define m_flNextDecalTime 486
  11. #define GetCustomDecalFrames(%0) 6 // get_pdata_int(%0,m_nCustomSprayFrames)
  12. // #define SetCustomDecalFrames(%0,%1) set_pdata_int(%0,m_nCustomSprayFrames,%1)
  13.  
  14. #define MAX_PLAYERS 32
  15.  
  16. #define UTIL_MakeVectors(%0) engfunc(EngFunc_MakeVectors,%0)
  17. #define TRACE_LINE(%0,%1,%2,%3,%4) engfunc(EngFunc_TraceLine,%0,%1,%2,%3,%4)
  18. #define ALLOC_STRING(%0) engfunc(EngFunc_AllocString, %0)
  19. #define CREATE_NAMED_ENTITY(%0) engfunc(EngFunc_CreateNamedEntity, %0)
  20. #define REMOVE_ENTITY(%0) engfunc(EngFunc_RemoveEntity, %0)
  21. #define WRITE_COORD(%0) engfunc(EngFunc_WriteCoord,%0)
  22.  
  23. new const SPRAY_SOUND[] = "player/sprayer.wav"
  24. new const INFO_TARGET[] = "info_target"
  25. new g_iFirstDecalIndex
  26. new decalfrequency
  27. new g_iMaxPlayers
  28. new g_iPlayerSprayCan[MAX_PLAYERS+1]
  29.  
  30. public plugin_init()
  31. {
  32. register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
  33. decalfrequency = get_cvar_pointer("decalfrequency")
  34. RegisterHam(Ham_Player_ImpulseCommands, "player", "CBasePlayer_ImpulseCommands")
  35. RegisterHam(Ham_Think, INFO_TARGET, "CSprayCan_Think")
  36. g_iFirstDecalIndex = engfunc(EngFunc_DecalIndex, "{lambda01")
  37. g_iMaxPlayers = get_maxplayers()
  38. }
  39.  
  40. public plugin_precache()
  41. {
  42. precache_sound(SPRAY_SOUND)
  43. }
  44.  
  45. public CBasePlayer_ImpulseCommands( id )
  46. {
  47. if( pev(id, pev_impulse) == 201 )
  48. {
  49. static Float:flGameTime ; flGameTime = get_gametime()
  50. if( flGameTime >= get_pdata_float(id, m_flNextDecalTime) )
  51. {
  52. new Float:start[3], Float:end[3], Float:origin[3], Float:v_angle[3]
  53. pev(id, pev_v_angle, v_angle)
  54. UTIL_MakeVectors(v_angle)
  55. pev(id, pev_origin, origin)
  56. pev(id, pev_view_ofs, end)
  57. xs_vec_add(origin, end, start)
  58. global_get(glb_v_forward, end)
  59. xs_vec_mul_scalar(end, 128.0, end)
  60. xs_vec_add(start, end, end)
  61.  
  62. UTIL_TraceLine ( start, end, IGNORE_MONSTERS, id)
  63.  
  64. new Float:flFraction
  65. get_tr2(0, TR_flFraction, flFraction)
  66.  
  67. if ( flFraction != 1.0 )
  68. {
  69. set_pdata_float(id, m_flNextDecalTime, flGameTime + get_pcvar_float(decalfrequency))
  70. static info_target
  71. if( !info_target )
  72. {
  73. info_target = ALLOC_STRING( INFO_TARGET )
  74. }
  75. new ent = CREATE_NAMED_ENTITY( info_target )
  76. origin[2] += 32.0
  77. set_pev(ent, pev_origin, origin)
  78. set_pev(ent, pev_angles, v_angle)
  79.  
  80. g_iPlayerSprayCan[id] = ent
  81. set_pev(ent, pev_frame, 0.0)
  82.  
  83. set_pev(ent, pev_nextthink, flGameTime + 0.1)
  84. emit_sound(ent, CHAN_VOICE, SPRAY_SOUND, 1.0, ATTN_NORM, 0, PITCH_NORM)
  85. }
  86. }
  87. set_pev(id, pev_impulse, 0)
  88. }
  89. }
  90.  
  91. public CSprayCan_Think( ent )
  92. {
  93. new id
  94. for(id = g_iMaxPlayers; id>=0; id--)
  95. {
  96. if( g_iPlayerSprayCan[id] == ent )
  97. {
  98. break
  99. }
  100. }
  101. if( id <= 0 )
  102. {
  103. return
  104. }
  105.  
  106. new nFrames = GetCustomDecalFrames( id )
  107.  
  108. new Float:start[3], Float:end[3]
  109. pev(ent, pev_angles, start)
  110. UTIL_MakeVectors( start )
  111.  
  112. pev(ent, pev_origin, start)
  113. global_get(glb_v_forward, end)
  114. xs_vec_mul_scalar(end, 128.0, end)
  115. xs_vec_add(end, start, end)
  116.  
  117. UTIL_TraceLine (start, end, IGNORE_MONSTERS, id)
  118.  
  119. new Float:frame
  120. pev(ent, pev_frame, frame)
  121. UTIL_DecalTrace(0, g_iFirstDecalIndex - floatround(frame))
  122.  
  123. if ( ++frame >= nFrames)
  124. {
  125. REMOVE_ENTITY(ent)
  126. g_iPlayerSprayCan[id] = 0
  127. return
  128. }
  129. set_pev(ent, pev_frame, frame)
  130. set_pev(ent, pev_nextthink, get_gametime() + 0.1)
  131. }
  132.  
  133. UTIL_DecalTrace( pTrace, index )
  134. {
  135. static entityIndex, pHit,
  136. message, Float:vecEndPos[3]
  137.  
  138. pHit = get_tr2(pTrace, TR_pHit)
  139.  
  140. if ( pev_valid(pHit) )
  141. {
  142. if ( !ExecuteHam(Ham_IsBSPModel, pHit) )
  143. return;
  144. entityIndex = pHit
  145. }
  146. else
  147. entityIndex = 0
  148.  
  149. message = TE_DECAL;
  150. if ( entityIndex != 0 )
  151. {
  152. if ( index > 255 )
  153. {
  154. message = TE_DECALHIGH;
  155. index -= 256
  156. }
  157. }
  158. else
  159. {
  160. message = TE_WORLDDECAL;
  161. if ( index > 255 )
  162. {
  163. message = TE_WORLDDECALHIGH;
  164. index -= 256
  165. }
  166. }
  167.  
  168. get_tr2(pTrace, TR_vecEndPos, vecEndPos)
  169.  
  170. message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
  171. {
  172. write_byte( message )
  173. WRITE_COORD( vecEndPos[0] )
  174. WRITE_COORD( vecEndPos[1] )
  175. WRITE_COORD( vecEndPos[2] )
  176. write_byte( index )
  177. if ( entityIndex )
  178. {
  179. write_short( entityIndex )
  180. }
  181. }
  182. message_end()
  183. }
  184.  
  185. UTIL_TraceLine( Float:vecStart[3], Float:vecEnd[3], igmon, pentIgnore, ptr=0 )
  186. {
  187. TRACE_LINE( vecStart, vecEnd, igmon == IGNORE_MONSTERS, pentIgnore, ptr )
  188. }