HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* AMX Mod X
  2. * Eye Lids
  3. *
  4. * (c) Copyright 2005 by jsauce and VEN
  5. *
  6. * This file is provided as is (no warranties)
  7. *
  8. * DESCRIPTION:
  9. * Plugin: provides an ability of closing eyes it could be used against flashbangs.
  10. * Usage: all you need to do is just bind a client command "+eyelids" to a button.
  11. * Note: if you have a troubles make sure you have no other screen fade plugins enabled.
  12. *
  13. * FEATURES:
  14. * - fade in/out effects for real close/open
  15. * - inability of closing eyes when flashed/dead
  16. * - spectators support (+ obey mp_fadetoblack 1)
  17. *
  18. * COMMANDS:
  19. * +eyelids - allows to a player close his eyes
  20. * -eyelids - allows to a player open his eyes
  21. *
  22. * THANKS:
  23. * Damaged Soul - his "Message Logging" plugin very useful as always
  24. *
  25. * CREDITS:
  26. * jsauce
  27. * - initial idea
  28. * - initial code
  29. * - spectators idea
  30. * - beta testing
  31. * - other
  32. * VEN
  33. * - rewrote initial code from scratch
  34. * - fade in/out effects for real close/open
  35. * - numerous exploit fixes
  36. * - spectators support
  37. * - beta testing
  38. * - other
  39. */
  40.  
  41. /* *************************************************** Head **************************************************** */
  42.  
  43. #define PLUGIN_NAME "Eye Lids"
  44. #define PLUGIN_VERSION "0.1"
  45. #define PLUGIN_AUTHOR "jsauce and VEN"
  46.  
  47. #include <amxmodx>
  48.  
  49. /* ********************************************** Defines/Globals ********************************************** */
  50.  
  51. // experimental redraw method
  52. // could solve some problems
  53. // engine module required
  54. // spectators not supported
  55. // uncomment to enable
  56. //#define PRETHINK_REDRAW
  57.  
  58. #define MAX_PLAYERS 32
  59.  
  60. #define DELAY_COPEN 1000 // delay in milliseconds for real close/open
  61. #define FLAGS_CLOSE ((1<<0) | (1<<2))
  62. #define FLAGS_OPEN 0
  63. #define FLAGS_INSTANT (1<<2)
  64. #define COLOR_RED 0
  65. #define COLOR_GREEN 0
  66. #define COLOR_BLUE 0
  67. #define ALPHA 255
  68.  
  69. #define TASK_PREFIX 794539
  70.  
  71. #if defined PRETHINK_REDRAW
  72. #define FLAGS_REDRAW 0
  73.  
  74. #define TASK_CLOSING_PREFIX 3985642
  75.  
  76. new bool:g_iseyes_closing[MAX_PLAYERS + 1]
  77.  
  78. public plugin_modules() {
  79. require_module("engine")
  80. }
  81. #endif
  82.  
  83. new bool:g_iseyes_closed[MAX_PLAYERS + 1]
  84. new bool:g_isflashed[MAX_PLAYERS + 1]
  85.  
  86. new bool:g_ftb[MAX_PLAYERS + 1]
  87. new bool:g_firstperson[MAX_PLAYERS + 1]
  88. new g_spectate[MAX_PLAYERS + 1]
  89.  
  90. new g_msg_screen_fade
  91.  
  92. /* *************************************************** Base **************************************************** */
  93.  
  94. public plugin_init() {
  95. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
  96.  
  97. register_clcmd("+szemhej", "cmd_close_open")
  98. register_clcmd("-szemhej", "cmd_close_open")
  99.  
  100. register_event("ScreenFade", "event_screen_reset", "b", "1=4", "2=0", "3=0", "4=0", "5=0", "6=0", "7=0")
  101. register_event("ScreenFade", "event_flash", "be", "1>0", "2>0", "3=0", "4=255", "5=255", "6=255", "7>199")
  102. register_event("ScreenFade", "event_ftb", "bd", "1=12288", "2=12288", "3=5", "4=0", "5=0", "6=0", "7=255")
  103. register_event("DeathMsg", "event_death_msg", "a")
  104. register_event("SpecHealth2", "event_spectate", "bd")
  105. register_event("TextMsg", "event_spec_mode", "bd", "1=4", "2&#Spec_Mode")
  106.  
  107. g_msg_screen_fade = get_user_msgid("ScreenFade")
  108. }
  109.  
  110. public cmd_close_open(id) {
  111. if (g_isflashed[id] || !is_user_alive(id))
  112. return PLUGIN_HANDLED
  113.  
  114. new cmd[2]
  115. read_argv(0, cmd, 1)
  116. new bool:close = (cmd[0] == '+') ? true : false
  117. if (close == g_iseyes_closed[id])
  118. return PLUGIN_HANDLED
  119.  
  120. g_iseyes_closed[id] = close
  121.  
  122. #if defined PRETHINK_REDRAW
  123. if (close) {
  124. new Float:delay = float(DELAY_COPEN) / 1000
  125. new taskid = id + TASK_CLOSING_PREFIX
  126. clear_task(taskid)
  127. g_iseyes_closing[id] = true
  128. set_task(delay, "task_on_closed" , taskid)
  129. }
  130. #endif
  131.  
  132. new flags = close ? FLAGS_CLOSE : FLAGS_OPEN
  133. close_open(id, flags)
  134. update_spectators(id, flags)
  135.  
  136. return PLUGIN_HANDLED
  137. }
  138.  
  139. #if defined PRETHINK_REDRAW
  140. public task_on_closed(taskid) {
  141. g_iseyes_closing[taskid - TASK_CLOSING_PREFIX] = false
  142. }
  143. #endif
  144.  
  145. public event_flash(id) {
  146. if (g_iseyes_closed[id]) {
  147. close_open(id, FLAGS_INSTANT)
  148. update_spectators(id, FLAGS_INSTANT)
  149. return
  150. }
  151.  
  152. g_isflashed[id] = true
  153. new Float:delay = float(read_data(2)) / 1000
  154. new taskid = id + TASK_PREFIX
  155. clear_task(taskid)
  156. set_task(delay, "task_on_unflash" , taskid)
  157. }
  158.  
  159. public task_on_unflash(taskid) {
  160. g_isflashed[taskid - TASK_PREFIX] = false
  161. }
  162.  
  163. public event_ftb(id) {
  164. g_ftb[id] = true
  165. }
  166.  
  167. public event_spec_mode(id) {
  168. new mode[12]
  169. read_data(2, mode, 11)
  170. if (mode[10] == '4') {
  171. if (!g_ftb[id] && g_iseyes_closed[g_spectate[id]])
  172. close_open(id, FLAGS_INSTANT)
  173.  
  174. g_firstperson[id] = true
  175. }
  176. else {
  177. if (!g_ftb[id] && g_firstperson[id] && g_iseyes_closed[g_spectate[id]])
  178. reset_screen(id)
  179.  
  180. g_firstperson[id] = false
  181. }
  182. }
  183.  
  184. public event_spectate(id) {
  185. new id2 = read_data(2)
  186. if (g_spectate[id] == id2)
  187. return
  188.  
  189. if (get_cvar_num("mp_fadetoblack") && !g_ftb[id] && g_firstperson[id]) {
  190. if (g_iseyes_closed[id2])
  191. close_open(id, FLAGS_INSTANT)
  192. else
  193. reset_screen(id)
  194. }
  195.  
  196. g_spectate[id] = id2
  197. }
  198.  
  199. public event_screen_reset(id) {
  200. g_ftb[id] = false
  201. if (!is_user_alive(id) && g_firstperson[id] && g_iseyes_closed[g_spectate[id]])
  202. close_open(id, FLAGS_INSTANT)
  203. }
  204.  
  205. public event_death_msg() {
  206. new id = read_data(2)
  207. if (g_iseyes_closed[id])
  208. close_open(id, FLAGS_OPEN)
  209.  
  210. death_disconnect(id)
  211. }
  212.  
  213. public client_disconnect(id) {
  214. death_disconnect(id)
  215. }
  216.  
  217. #if defined PRETHINK_REDRAW
  218. public client_PreThink(id) {
  219. if (g_iseyes_closed[id] && !g_iseyes_closing[id])
  220. close_open(id, FLAGS_REDRAW)
  221. }
  222. #endif
  223.  
  224. /* ************************************************** Stocks *************************************************** */
  225.  
  226. stock close_open(id, flags) {
  227. new delay = (flags == FLAGS_INSTANT) ? 0 : DELAY_COPEN
  228. message_begin(MSG_ONE, g_msg_screen_fade, {0, 0, 0}, id)
  229. write_short(delay)
  230. write_short(delay)
  231. write_short(flags)
  232. write_byte(COLOR_RED)
  233. write_byte(COLOR_GREEN)
  234. write_byte(COLOR_BLUE)
  235. write_byte(ALPHA)
  236. message_end()
  237. }
  238.  
  239. stock reset_screen(id) {
  240. message_begin(MSG_ONE, g_msg_screen_fade, {0, 0, 0}, id)
  241. write_short(0)
  242. write_short(0)
  243. write_short(0)
  244. write_byte(0)
  245. write_byte(0)
  246. write_byte(0)
  247. write_byte(0)
  248. message_end()
  249. }
  250.  
  251. stock update_spectators(id, flags) {
  252. for (new i = 1; i <= MAX_PLAYERS; ++i) {
  253. if (is_user_connected(i) && !is_user_alive(i) && !g_ftb[i] && g_firstperson[i] && g_spectate[i] == id)
  254. close_open(i, flags)
  255. }
  256. }
  257.  
  258. stock clear_task(taskid) {
  259. if (task_exists(taskid))
  260. remove_task(taskid)
  261. }
  262.  
  263. stock death_disconnect(id) {
  264. clear_task(id + TASK_PREFIX)
  265. g_iseyes_closed[id] = false
  266. g_isflashed[id] = false
  267. g_firstperson[id] = false
  268. g_spectate[id] = 0
  269. }
  270.  
  271. /* ********************************************** Captured Events ********************************************** */
  272.  
  273. /*
  274. // Screen Reset
  275. L 12/10/2005 - 14:41:44: [msglogging.amxx] MessageBegin ScreenFade(98) Arguments=7 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
  276. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 1 (Short): 4
  277. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 2 (Short): 0
  278. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 3 (Short): 0
  279. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 4 (Byte): 0
  280. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 5 (Byte): 0
  281. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 6 (Byte): 0
  282. L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 7 (Byte): 0
  283. L 12/10/2005 - 14:41:44: [msglogging.amxx] MessageEnd ScreenFade(98)
  284. */
  285.  
  286. /*
  287. // Flash
  288. L 12/10/2005 - 14:42:00: [msglogging.amxx] MessageBegin ScreenFade(98) Arguments=7 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
  289. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 1 (Short): 21315
  290. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 2 (Short): 3480
  291. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 3 (Short): 0
  292. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 4 (Byte): 255
  293. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 5 (Byte): 255
  294. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 6 (Byte): 255
  295. L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 7 (Byte): 200
  296. L 12/10/2005 - 14:42:00: [msglogging.amxx] MessageEnd ScreenFade(98)
  297. */
  298.  
  299. /*
  300. // Fade to Black
  301. L 12/10/2005 - 14:42:04: [msglogging.amxx] MessageBegin ScreenFade(98) Arguments=7 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
  302. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 1 (Short): 12288
  303. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 2 (Short): 12288
  304. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 3 (Short): 5
  305. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 4 (Byte): 0
  306. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 5 (Byte): 0
  307. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 6 (Byte): 0
  308. L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 7 (Byte): 255
  309. L 12/10/2005 - 14:42:04: [msglogging.amxx] MessageEnd ScreenFade(98)
  310. */
  311.  
  312. /*
  313. // Spec. Health
  314. L 12/10/2005 - 14:42:08: [msglogging.amxx] MessageBegin SpecHealth2(137) Arguments=2 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
  315. L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 1 (Byte): 34
  316. L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 2 (Byte): 2
  317. L 12/10/2005 - 14:42:08: [msglogging.amxx] MessageEnd SpecHealth2(137)
  318. */
  319.  
  320. /*
  321. // Spec. Mode
  322. L 12/10/2005 - 14:42:08: [msglogging.amxx] MessageBegin TextMsg(77) Arguments=2 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
  323. L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 1 (Byte): 4
  324. L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 2 (String): #Spec_Mode4
  325. L 12/10/2005 - 14:42:08: [msglogging.amxx] MessageEnd TextMsg(77)
  326. */
  327.  
  328. /* ************************************************** The End ************************************************** */
  329.