HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* http://forums.alliedmods.net/showthread.php?p=551999#post551999
  2. *
  3. * Changelog
  4. * added cvar amx_inv_dead_percent <value>
  5. *
  6. */
  7.  
  8. #include <amxmodx>
  9. #include <fakemeta>
  10.  
  11. #if AMXX_VERSION_NUM < 180
  12. #define charsmax(%1) sizeof(%1) - 1
  13. #endif
  14.  
  15. #define MAX_PLAYERS 32
  16.  
  17. #define DEAD_FLAG (1<<0)
  18.  
  19. #define OFFSET_TEAM 114
  20.  
  21. enum {
  22. CS_TEAM_UNASSIGNED,
  23. CS_TEAM_T,
  24. CS_TEAM_CT,
  25. CS_TEAM_SPECTATOR
  26. }
  27.  
  28. new bool:g_roundend
  29. new pcvar_percent
  30. new g_invisible[MAX_PLAYERS+1][2]
  31. new gmsgScoreAttrib, gmsgTeamInfo
  32.  
  33. public plugin_init() {
  34. register_plugin("Invisible Spectator", "0.2", "ConnorMcLeod")
  35.  
  36. pcvar_percent = register_cvar("amx_inv_dead_percent", "40")
  37.  
  38. register_clcmd("amx_spectate", "make_invis", ADMIN_RCON)
  39.  
  40. gmsgScoreAttrib = get_user_msgid("ScoreAttrib")
  41. gmsgTeamInfo = get_user_msgid("TeamInfo")
  42.  
  43. register_message( gmsgScoreAttrib, "msg_ScoreAttrib")
  44. register_message( gmsgTeamInfo, "msg_TeamInfo")
  45.  
  46. register_event("HLTV", "eNewRound", "a", "1=0", "2=0")
  47. register_logevent("eRoundEnd", 2, "1=Round_End")
  48. register_event("ResetHUD", "eResetHUD", "be")
  49. register_event("DeathMsg", "eDeathMsg", "a")
  50. }
  51.  
  52. public make_invis(id, level) {
  53. if( ~get_user_flags(id) & level )
  54. return PLUGIN_CONTINUE
  55.  
  56. if(g_invisible[id][0])
  57. {
  58. client_print(id, print_console, "Te nem lehetsz lathatatlan.")
  59. g_invisible[id][0] = 0
  60. return PLUGIN_HANDLED
  61. }
  62.  
  63. if( is_user_alive(id) )
  64. {
  65. client_print(id, print_console, "Elo jatekos nem lehet lathatatlan nezo!")
  66. return PLUGIN_HANDLED
  67. }
  68.  
  69. g_invisible[id][0] = 1
  70. client_print(id, print_console, "Te mar lathatatlan nezo vagy!")
  71.  
  72. new team = get_pdata_int(id, OFFSET_TEAM)
  73. if( CS_TEAM_T <= team <= CS_TEAM_CT )
  74. {
  75. g_invisible[id][1] = team
  76. set_pdata_int(id, OFFSET_TEAM, CS_TEAM_SPECTATOR)
  77. }
  78. else
  79. {
  80. new players[MAX_PLAYERS], tnum, ctnum
  81. get_players(players, tnum, "e", "TERRORIST")
  82. get_players(players, ctnum, "e", "CT")
  83. g_invisible[id][1] = ctnum > tnum ? 1 : 2
  84. }
  85.  
  86. send_ScoreAttrib(id, 0)
  87.  
  88. new teamname[12]
  89. switch( g_invisible[id][1] )
  90. {
  91. case 1:formatex(teamname, charsmax(teamname), "TERRORIST")
  92. case 2:formatex(teamname, charsmax(teamname), "CT")
  93. }
  94. send_TeamInfo(id, teamname)
  95.  
  96. return PLUGIN_HANDLED
  97. }
  98.  
  99. public eDeathMsg() {
  100. if(g_roundend)
  101. return
  102.  
  103. new players[MAX_PLAYERS], dead, inum, player, Float:percent = get_pcvar_float(pcvar_percent) / 100.0
  104. get_players(players, dead, "bh")
  105. get_players(players, inum, "h")
  106.  
  107. if( float(dead) / float(inum) < percent)
  108. return
  109.  
  110. for(new i; i < inum; i++)
  111. {
  112. player = players[i]
  113. if( g_invisible[player][0] )
  114. send_ScoreAttrib(player, DEAD_FLAG)
  115. }
  116. }
  117.  
  118. public eNewRound() {
  119. g_roundend = false
  120. new players[MAX_PLAYERS], inum, player
  121. get_players(players, inum)
  122. for(new i; i < inum; i++)
  123. {
  124. player = players[i]
  125. if( g_invisible[player][0] )
  126. send_ScoreAttrib(player, 0)
  127. }
  128. }
  129.  
  130. public eRoundEnd() {
  131. g_roundend = true
  132. new players[MAX_PLAYERS], inum, player
  133. get_players(players, inum)
  134. for(new i; i < inum; i++)
  135. {
  136. player = players[i]
  137. if( g_invisible[player][0] )
  138. send_ScoreAttrib(player, DEAD_FLAG)
  139. }
  140. }
  141.  
  142. public eResetHUD(id) {
  143. if( g_invisible[id][0] )
  144. g_invisible[id][0] = 0
  145. }
  146.  
  147. // Doesn't seem to work so set flag to 0 at NewRound event.
  148. public msg_ScoreAttrib(msg_type, msg_dest, target) {
  149. if(!g_invisible[get_msg_arg_int(1)][0])
  150. return PLUGIN_CONTINUE
  151.  
  152. new flags = get_msg_arg_int(2)
  153. if(flags & DEAD_FLAG)
  154. set_msg_arg_int(2, 0, flags & ~DEAD_FLAG)
  155.  
  156. return PLUGIN_CONTINUE
  157. }
  158.  
  159. public msg_TeamInfo(msg_type, msg_dest, target) {
  160. new id = get_msg_arg_int(1)
  161. if(!g_invisible[id][0])
  162. return PLUGIN_CONTINUE
  163.  
  164. new teamname[12]
  165. get_msg_arg_string(2, teamname, charsmax(teamname))
  166. if( g_invisible[id][1] == CS_TEAM_T && strcmp(teamname, "TERRORIST") != 0 )
  167. set_msg_arg_string(2, "TERRORIST")
  168. else if( g_invisible[id][1] == CS_TEAM_CT && strcmp(teamname, "CT") != 0 )
  169. set_msg_arg_string(2, "CT")
  170.  
  171. return PLUGIN_CONTINUE
  172. }
  173.  
  174. send_ScoreAttrib(id, flags)
  175. {
  176. message_begin(MSG_ALL, gmsgScoreAttrib, _, 0)
  177. write_byte(id)
  178. write_byte(flags)
  179. message_end()
  180. }
  181.  
  182. send_TeamInfo(id, teamname[])
  183. {
  184. message_begin(MSG_ALL, gmsgTeamInfo, _, 0)
  185. write_byte(id)
  186. write_string(teamname)
  187. message_end()
  188. }
  189. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  190. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
  191. */
  192.