/* AMX Mod X
* Eye Lids
*
* (c) Copyright 2005 by jsauce and VEN
*
* This file is provided as is (no warranties)
*
* DESCRIPTION:
* Plugin: provides an ability of closing eyes it could be used against flashbangs.
* Usage: all you need to do is just bind a client command "+eyelids" to a button.
* Note: if you have a troubles make sure you have no other screen fade plugins enabled.
*
* FEATURES:
* - fade in/out effects for real close/open
* - inability of closing eyes when flashed/dead
* - spectators support (+ obey mp_fadetoblack 1)
*
* COMMANDS:
* +eyelids - allows to a player close his eyes
* -eyelids - allows to a player open his eyes
*
* THANKS:
* Damaged Soul - his "Message Logging" plugin very useful as always
*
* CREDITS:
* jsauce
* - initial idea
* - initial code
* - spectators idea
* - beta testing
* - other
* VEN
* - rewrote initial code from scratch
* - fade in/out effects for real close/open
* - numerous exploit fixes
* - spectators support
* - beta testing
* - other
*/
/* *************************************************** Head **************************************************** */
#define PLUGIN_NAME "Eye Lids"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "jsauce and VEN"
#include <amxmodx>
/* ********************************************** Defines/Globals ********************************************** */
// experimental redraw method
// could solve some problems
// engine module required
// spectators not supported
// uncomment to enable
//#define PRETHINK_REDRAW
#define MAX_PLAYERS 32
#define DELAY_COPEN 1000 // delay in milliseconds for real close/open
#define FLAGS_CLOSE ((1<<0) | (1<<2))
#define FLAGS_OPEN 0
#define FLAGS_INSTANT (1<<2)
#define COLOR_RED 0
#define COLOR_GREEN 0
#define COLOR_BLUE 0
#define ALPHA 255
#define TASK_PREFIX 794539
#if defined PRETHINK_REDRAW
#define FLAGS_REDRAW 0
#define TASK_CLOSING_PREFIX 3985642
new bool:g_iseyes_closing[MAX_PLAYERS + 1]
public plugin_modules() {
require_module("engine")
}
#endif
new bool:g_iseyes_closed[MAX_PLAYERS + 1]
new bool:g_isflashed[MAX_PLAYERS + 1]
new bool:g_ftb[MAX_PLAYERS + 1]
new bool:g_firstperson[MAX_PLAYERS + 1]
new g_spectate[MAX_PLAYERS + 1]
new g_msg_screen_fade
/* *************************************************** Base **************************************************** */
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_clcmd("+szemhej", "cmd_close_open")
register_clcmd("-szemhej", "cmd_close_open")
register_event("ScreenFade", "event_screen_reset", "b", "1=4", "2=0", "3=0", "4=0", "5=0", "6=0", "7=0")
register_event("ScreenFade", "event_flash", "be", "1>0", "2>0", "3=0", "4=255", "5=255", "6=255", "7>199")
register_event("ScreenFade", "event_ftb", "bd", "1=12288", "2=12288", "3=5", "4=0", "5=0", "6=0", "7=255")
register_event("DeathMsg", "event_death_msg", "a")
register_event("SpecHealth2", "event_spectate", "bd")
register_event("TextMsg", "event_spec_mode", "bd", "1=4", "2&#Spec_Mode")
g_msg_screen_fade = get_user_msgid("ScreenFade")
}
public cmd_close_open(id) {
if (g_isflashed[id] || !is_user_alive(id))
return PLUGIN_HANDLED
new cmd[2]
read_argv(0, cmd, 1)
new bool:close = (cmd[0] == '+') ? true : false
if (close == g_iseyes_closed[id])
return PLUGIN_HANDLED
g_iseyes_closed[id] = close
#if defined PRETHINK_REDRAW
if (close) {
new Float:delay = float(DELAY_COPEN) / 1000
new taskid = id + TASK_CLOSING_PREFIX
clear_task(taskid)
g_iseyes_closing[id] = true
set_task(delay, "task_on_closed" , taskid)
}
#endif
new flags = close ? FLAGS_CLOSE : FLAGS_OPEN
close_open(id, flags)
update_spectators(id, flags)
return PLUGIN_HANDLED
}
#if defined PRETHINK_REDRAW
public task_on_closed(taskid) {
g_iseyes_closing[taskid - TASK_CLOSING_PREFIX] = false
}
#endif
public event_flash(id) {
if (g_iseyes_closed[id]) {
close_open(id, FLAGS_INSTANT)
update_spectators(id, FLAGS_INSTANT)
return
}
g_isflashed[id] = true
new Float:delay = float(read_data(2)) / 1000
new taskid = id + TASK_PREFIX
clear_task(taskid)
set_task(delay, "task_on_unflash" , taskid)
}
public task_on_unflash(taskid) {
g_isflashed[taskid - TASK_PREFIX] = false
}
public event_ftb(id) {
g_ftb[id] = true
}
public event_spec_mode(id) {
new mode[12]
read_data(2, mode, 11)
if (mode[10] == '4') {
if (!g_ftb[id] && g_iseyes_closed[g_spectate[id]])
close_open(id, FLAGS_INSTANT)
g_firstperson[id] = true
}
else {
if (!g_ftb[id] && g_firstperson[id] && g_iseyes_closed[g_spectate[id]])
reset_screen(id)
g_firstperson[id] = false
}
}
public event_spectate(id) {
new id2 = read_data(2)
if (g_spectate[id] == id2)
return
if (get_cvar_num("mp_fadetoblack") && !g_ftb[id] && g_firstperson[id]) {
if (g_iseyes_closed[id2])
close_open(id, FLAGS_INSTANT)
else
reset_screen(id)
}
g_spectate[id] = id2
}
public event_screen_reset(id) {
g_ftb[id] = false
if (!is_user_alive(id) && g_firstperson[id] && g_iseyes_closed[g_spectate[id]])
close_open(id, FLAGS_INSTANT)
}
public event_death_msg() {
new id = read_data(2)
if (g_iseyes_closed[id])
close_open(id, FLAGS_OPEN)
death_disconnect(id)
}
public client_disconnect(id) {
death_disconnect(id)
}
#if defined PRETHINK_REDRAW
public client_PreThink(id) {
if (g_iseyes_closed[id] && !g_iseyes_closing[id])
close_open(id, FLAGS_REDRAW)
}
#endif
/* ************************************************** Stocks *************************************************** */
stock close_open(id, flags) {
new delay = (flags == FLAGS_INSTANT) ? 0 : DELAY_COPEN
message_begin(MSG_ONE, g_msg_screen_fade, {0, 0, 0}, id)
write_short(delay)
write_short(delay)
write_short(flags)
write_byte(COLOR_RED)
write_byte(COLOR_GREEN)
write_byte(COLOR_BLUE)
write_byte(ALPHA)
message_end()
}
stock reset_screen(id) {
message_begin(MSG_ONE, g_msg_screen_fade, {0, 0, 0}, id)
write_short(0)
write_short(0)
write_short(0)
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(0)
message_end()
}
stock update_spectators(id, flags) {
for (new i = 1; i <= MAX_PLAYERS; ++i) {
if (is_user_connected(i) && !is_user_alive(i) && !g_ftb[i] && g_firstperson[i] && g_spectate[i] == id)
close_open(i, flags)
}
}
stock clear_task(taskid) {
if (task_exists(taskid))
remove_task(taskid)
}
stock death_disconnect(id) {
clear_task(id + TASK_PREFIX)
g_iseyes_closed[id] = false
g_isflashed[id] = false
g_firstperson[id] = false
g_spectate[id] = 0
}
/* ********************************************** Captured Events ********************************************** */
/*
// Screen Reset
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
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 1 (Short): 4
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 2 (Short): 0
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 3 (Short): 0
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 4 (Byte): 0
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 5 (Byte): 0
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 6 (Byte): 0
L 12/10/2005 - 14:41:44: [msglogging.amxx] Arg 7 (Byte): 0
L 12/10/2005 - 14:41:44: [msglogging.amxx] MessageEnd ScreenFade(98)
*/
/*
// Flash
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
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 1 (Short): 21315
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 2 (Short): 3480
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 3 (Short): 0
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 4 (Byte): 255
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 5 (Byte): 255
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 6 (Byte): 255
L 12/10/2005 - 14:42:00: [msglogging.amxx] Arg 7 (Byte): 200
L 12/10/2005 - 14:42:00: [msglogging.amxx] MessageEnd ScreenFade(98)
*/
/*
// Fade to Black
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
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 1 (Short): 12288
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 2 (Short): 12288
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 3 (Short): 5
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 4 (Byte): 0
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 5 (Byte): 0
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 6 (Byte): 0
L 12/10/2005 - 14:42:04: [msglogging.amxx] Arg 7 (Byte): 255
L 12/10/2005 - 14:42:04: [msglogging.amxx] MessageEnd ScreenFade(98)
*/
/*
// Spec. Health
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
L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 1 (Byte): 34
L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 2 (Byte): 2
L 12/10/2005 - 14:42:08: [msglogging.amxx] MessageEnd SpecHealth2(137)
*/
/*
// Spec. Mode
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
L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 1 (Byte): 4
L 12/10/2005 - 14:42:08: [msglogging.amxx] Arg 2 (String): #Spec_Mode4
L 12/10/2005 - 14:42:08: [msglogging.amxx] MessageEnd TextMsg(77)
*/
/* ************************************************** The End ************************************************** */