HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include < amxmodx >
  2. #include < cstrike >
  3. #include < fakemeta >
  4. #include < hamsandwich >
  5.  
  6. #define VERSION "1.0"
  7. #define HEALTH_BAR_MODEL "sprites/health.spr"
  8. #define is_player(%1) ( 1 <= %1 <= g_maxPlayers )
  9. #define is_alive(%1) ( g_playerStatus[ %1 ] == ALIVE )
  10. #define same_team(%1,%2) ( g_playerTeam[ %1 ] == g_playerTeam[ %2 ] )
  11.  
  12. enum _: g_enum_playerStatus
  13. {
  14. DISCONNECTED = 0,
  15. DEAD,
  16. ALIVE
  17. }
  18.  
  19. const ENTITIES_USER = 85768484848
  20.  
  21. new g_playerBar[ 33 ], g_playerStatus[ 33 ], CsTeams: g_playerTeam[ 33 ], g_playerBot[ 33 ], g_playerMaxHealth[ 33 ]
  22. new pcvarBotSupport, pcvarShowMode, pcvarSpec, cvarSpec, cvarShowMode, cvarBotSupport
  23. new g_maxPlayers, fwShowMode, botRegistered
  24.  
  25. public plugin_init( )
  26. {
  27. register_plugin( "Health Bar", VERSION, "Bboy Grun" )
  28.  
  29. register_cvar( "Health_Bars", VERSION, FCVAR_SERVER | FCVAR_SPONLY )
  30. set_cvar_string( "Health_Bars", VERSION )
  31.  
  32. RegisterHam( Ham_Spawn, "player", "fwHamSpawn", 1 )
  33.  
  34. register_event( "HLTV", "evRoundStart", "a", "1=0", "2=0" )
  35. register_event( "DeathMsg", "evDeathMsg", "a" )
  36. register_event( "Health", "evHealth", "be" )
  37.  
  38. pcvarShowMode = register_cvar( "health_ShowMode", "1" )
  39. pcvarBotSupport = register_cvar( "health_BotSupport", "1" )
  40. pcvarSpec = register_cvar( "health_ShowToSpectators", "1" )
  41.  
  42. g_maxPlayers = get_maxplayers( )
  43.  
  44. createHealthHuds( )
  45. evRoundStart( )
  46. }
  47.  
  48. public plugin_init_bots( id )
  49. {
  50. RegisterHamFromEntity( Ham_Spawn, id, "fwHamSpawn", 1 )
  51.  
  52. fwHamSpawn( id )
  53. }
  54.  
  55. public plugin_precache( )
  56. {
  57. precache_model( HEALTH_BAR_MODEL )
  58. }
  59.  
  60. public client_putinserver( id )
  61. {
  62. g_playerStatus[ id ] = DEAD
  63. g_playerTeam[ id ] = CS_TEAM_SPECTATOR
  64. g_playerBot[ id ] = is_user_bot( id )
  65. g_playerMaxHealth[ id ] = 0
  66.  
  67. if( cvarBotSupport && !botRegistered && g_playerBot[ id ] && get_cvar_num( "bot_quota" ) > 0 )
  68. {
  69. set_task( 0.4, "plugin_init_bots", id )
  70. botRegistered = 1
  71. }
  72. }
  73.  
  74. public client_disconnect( id )
  75. {
  76. g_playerStatus[ id ] = DISCONNECTED
  77. g_playerTeam[ id ] = CS_TEAM_UNASSIGNED
  78. g_playerBot[ id ] = 0
  79. g_playerMaxHealth[ id ] = 0
  80. }
  81.  
  82. public fwAddToFullPack( es, e, ent, host, host_flags, player, p_set )
  83. {
  84. if( is_player( host ) && !is_player( ent ) && !g_playerBot[ host ] && host != ent )
  85. {
  86. if( ( is_alive( host ) && !cvarSpec ) || cvarSpec )
  87. {
  88. if( pev_valid( ent ) && pev( ent, pev_iuser1 ) == ENTITIES_USER )
  89. {
  90. new player = pev( ent, pev_iuser2 )
  91.  
  92. if( player != host && is_alive( player ) )
  93. {
  94. if( ( !cvarBotSupport && !g_playerBot[ player ] ) || cvarBotSupport )
  95. {
  96. if( cvarShowMode == 2 || ( cvarShowMode == 1 && same_team( host, player ) ) )
  97. {
  98. new Float: playerOrigin[ 3 ]
  99. pev( player, pev_origin, playerOrigin )
  100.  
  101. playerOrigin[ 2 ] += 30.0
  102.  
  103. engfunc( EngFunc_SetOrigin, ent, playerOrigin )
  104. set_es( es, ES_RenderMode, kRenderNormal )
  105. set_es( es, ES_RenderAmt, 220 )
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113.  
  114. public fwHamSpawn( id )
  115. {
  116. if( is_user_alive( id ) )
  117. {
  118. g_playerStatus[ id ] = ALIVE
  119. g_playerTeam[ id ] = cs_get_user_team( id )
  120.  
  121. checkHealth( id )
  122. }
  123. }
  124.  
  125. public evDeathMsg( )
  126. {
  127. new id = read_data( 2 )
  128.  
  129. g_playerStatus[ id ] = DEAD
  130. g_playerTeam[ id ] = cs_get_user_team( id )
  131. g_playerMaxHealth[ id ] = 0
  132.  
  133. engfunc( EngFunc_SetOrigin, g_playerBar[ id ], Float: { -9999.0, -9999.0, -9999.0 } )
  134. }
  135.  
  136. public evHealth( id )
  137. {
  138. checkHealth( id )
  139. }
  140.  
  141. public evRoundStart( )
  142. {
  143. cvarShowMode = get_pcvar_num( pcvarShowMode )
  144. cvarSpec = get_pcvar_num( pcvarSpec )
  145. new valueBotSupport = get_pcvar_num( pcvarBotSupport )
  146.  
  147. for( new id = 1; id <= g_maxPlayers; id ++ )
  148. {
  149. engfunc( EngFunc_SetOrigin, g_playerBar[ id ], Float: { -9999.0, -9999.0, -9999.0 } )
  150. }
  151.  
  152. if( cvarShowMode > 0 )
  153. {
  154. if( !fwShowMode )
  155. {
  156. fwShowMode = register_forward( FM_AddToFullPack, "fwAddToFullPack", 1 )
  157. }
  158. }
  159. else
  160. {
  161. if( fwShowMode )
  162. {
  163. unregister_forward( FM_AddToFullPack, fwShowMode, 1 )
  164. fwShowMode = 0
  165. }
  166. }
  167.  
  168. if( valueBotSupport && !botRegistered )
  169. {
  170. for( new id = 1; id <= g_maxPlayers; id ++ )
  171. {
  172. if( g_playerBot[ id ] )
  173. {
  174. plugin_init_bots( id )
  175. botRegistered = 1
  176. break;
  177. }
  178. }
  179. }
  180.  
  181. cvarBotSupport = valueBotSupport
  182. }
  183.  
  184. stock checkHealth( id )
  185. {
  186. new hp = get_user_health( id )
  187.  
  188. if( g_playerMaxHealth[ id ] < hp )
  189. {
  190. g_playerMaxHealth[ id ] = hp
  191. ent_setFrame( id, 0 )
  192. }
  193. else
  194. {
  195. ent_setFrame( id, 1, hp )
  196. }
  197. }
  198.  
  199. stock ent_setFrame( id, check = 1, health = 0 )
  200. {
  201. set_pev( g_playerBar[ id ], pev_frame, check == 0 ? ( 99.0 ) : ( 0.0 + ( ( ( health - 1 ) * 100 ) / g_playerMaxHealth[ id ] ) ) )
  202. }
  203.  
  204. createHealthHuds( )
  205. {
  206. new allocString = engfunc( EngFunc_AllocString, "env_sprite" )
  207.  
  208. for( new id = 1; id <= g_maxPlayers; id ++ )
  209. {
  210. g_playerBar[ id ] = engfunc( EngFunc_CreateNamedEntity, allocString )
  211.  
  212. if( pev_valid( g_playerBar[ id ] ) )
  213. {
  214. set_pev( g_playerBar[ id ], pev_solid, SOLID_NOT )
  215. set_pev( g_playerBar[ id ], pev_iuser2, id )
  216. set_pev( g_playerBar[ id ], pev_iuser1, ENTITIES_USER )
  217. set_pev( g_playerBar[ id ], pev_scale, 0.1 )
  218. engfunc( EngFunc_SetModel, g_playerBar[ id ], HEALTH_BAR_MODEL )
  219. set_pev( g_playerBar[ id ], pev_renderfx, kRenderTransAlpha )
  220. set_pev( g_playerBar[ id ], pev_renderamt, 0.0 )
  221. }
  222. }
  223. }
  224.