#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <colorchat>
#include <cstrike>
#define PLUGIN "Spec Info"
#define VERSION "1.0"
#define AUTHOR "crash"
#pragma semicolon 1
#define RED 0
#define GREEN 255
#define BLUE 159
#define UPDATEINTERVAL 1.0
#define FLAG ADMIN_IMMUNITY
new cvar_x;
new cvar_y;
new g_spectarget[33];
new g_specmode[33];
new bool:ShowkeysON[33];
new gMaxPlayers;
new gCvarImmunity;
new bool:gOnOff[33] = { true, ... };
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_PlayerPostThink, "fwd_playerpostthink");
register_event("TextMsg", "event_textmsg", "b", "2&#Spec_Mode");
register_event("StatusValue", "event_statusvalue", "bd", "1=2");
register_event("SpecHealth2", "event_spechealth2", "bd");
register_event("ResetHUD", "event_resethud", "be");
cvar_x = register_cvar("keylistenhud_x", "-1.0");
cvar_y = register_cvar("keylistenhud_y", "0.46");
gCvarImmunity = register_cvar("amx_speclist_immunity", "0", 0, 0.0);
register_clcmd("say /showkeys","cmdShowkeys", -1, "");
register_clcmd("say_team /showkeys","cmdShowkeys", -1, "");
register_clcmd("say /speclist", "cmdSpecList", -1, "");
register_clcmd("say_team /speclist", "cmdSpecList", -1, "");
gMaxPlayers = get_maxplayers();
set_task(UPDATEINTERVAL, "tskShowSpec", 123094, "", 0, "b", 0);
}
public cmdSpecList(id)
{
if( gOnOff[id] ){
gOnOff[id] = false;
ColorChat(id, GREEN, "^x01* You will no longer see who's spectating you");
}
else{
gOnOff[id] = true;
ColorChat(id, GREEN, "^x01* You will now see who's spectating you");
}
}
public tskShowSpec()
{
static szHud[1102];//32*33+45
static szName[34];
static bool:send;
for( new alive = 1; alive <= gMaxPlayers; alive++ )
{
new bool:sendTo[33];
send = false;
if( !is_user_alive(alive) )
{
continue;
}
sendTo[alive] = true;
get_user_name(alive, szName, 32);
format(szHud, 45, "Spectating:^n");
for( new dead = 1; dead <= gMaxPlayers; dead++ )
{
if( is_user_connected(dead) )
{
if( is_user_alive(dead)
|| is_user_bot(dead) )
{
continue;
}
if( pev(dead, pev_iuser2) == alive )
{
if( !(get_pcvar_num(gCvarImmunity)&&get_user_flags(dead, 0)&FLAG) )
{
get_user_name(dead, szName, 32);
add(szName, 33, "^n", 0);
add(szHud, 1101, szName, 0);
send = true;
}
sendTo[dead] = true;
}
}
}
if( send == true )
{
for( new i = 1; i <= gMaxPlayers; i++ )
{
if( sendTo[i] == true
&& gOnOff[i] == true )
{
set_hudmessage(RED, GREEN, BLUE,
0.75, 0.15, 0, 0.0, UPDATEINTERVAL + 0.1, 0.0, 0.0, -1);
show_hudmessage(i, szHud);
}
}
}
}
return PLUGIN_CONTINUE;
}
public client_connect(id) {
reset(id);
ShowkeysON[id] = false;
gOnOff[id] = true;
}
public client_disconnect(id) {
reset(id);
ShowkeysON[id] = false;
gOnOff[id] = true;
}
public event_resethud(id) {
reset(id);
}
public reset(id) {
g_spectarget[id] = 0, g_specmode[id] = false;
}
public cmdShowkeys(id) {
if(!ShowkeysON[id]) {
ShowkeysON[id] = true;
ColorChat(id, GREEN, "^x01* Showkeys are now^x04 enabled");
}
else
{
ShowkeysON[id] = false;
ColorChat(id, GREEN, "^x01* Showkeys are now^x04 disabled");
}
}
public event_textmsg(id) {
static specmode[12];
read_data(2, specmode, 11);
if(equal(specmode, "#Spec_Mode2") || equal(specmode, "#Spec_Mode4"))
g_specmode[id] = true;
else
g_specmode[id] = false;
return PLUGIN_CONTINUE;
}
public event_statusvalue(id) {
if(is_user_connected(id) && !is_user_alive(id))
set_spec_target(id, read_data(2));
}
public event_spechealth2(id) {
if(is_user_connected(id) && !is_user_alive(id))
set_spec_target(id, read_data(2));
}
public set_spec_target(index, target) {
if(target > 0)
g_spectarget[index] = target;
}
public fwd_playerpostthink(id) {
if(!is_user_alive(id) || g_specmode[id]) {
new target = g_spectarget[id];
if((target < 1) || !is_user_alive(target))
return FMRES_IGNORED;
new button = pev(target, pev_button);
static key[6][6];
formatex(key[0], 5, "%s", (button & IN_FORWARD) && !(button & IN_BACK) ? " W " : " ");
formatex(key[1], 5, "%s", (button & IN_BACK) && !(button & IN_FORWARD) ? " S " : " ");
formatex(key[2], 5, "%s", (button & IN_MOVELEFT) && !(button & IN_MOVERIGHT) ? "A" : " ");
formatex(key[3], 5, "%s", (button & IN_MOVERIGHT) && !(button & IN_MOVELEFT) ? "D" : " ");
formatex(key[4], 5, "%s", (button & IN_DUCK) ? " DUCK " : " ");
formatex(key[5], 5, "%s", (button & IN_JUMP) ? " JUMP " : " ");
set_hudmessage(0, 255, 159, get_pcvar_float(cvar_x), get_pcvar_float(cvar_y), 0, _, 0.1, _, _, 1);
show_hudmessage(id, "%s^n%s %s %s^n^n%s %s", key[0], key[2], key[1], key[3], key[4], key[5]);
}
else if(is_user_alive(id) && ShowkeysON[id]) {
if((id < 1) || !is_user_alive(id))
return FMRES_IGNORED;
new buttonkey = pev(id, pev_button);
static keybutton[6][6];
formatex(keybutton[0], 5, "%s", (buttonkey & IN_FORWARD) && !(buttonkey & IN_BACK) ? " W " : " ");
formatex(keybutton[1], 5, "%s", (buttonkey & IN_BACK) && !(buttonkey & IN_FORWARD) ? " S " : " ");
formatex(keybutton[2], 5, "%s", (buttonkey & IN_MOVELEFT) && !(buttonkey & IN_MOVERIGHT) ? "A" : " ");
formatex(keybutton[3], 5, "%s", (buttonkey & IN_MOVERIGHT) && !(buttonkey & IN_MOVELEFT) ? "D" : " ");
formatex(keybutton[4], 5, "%s", (buttonkey & IN_DUCK) ? " DUCK " : " ");
formatex(keybutton[5], 5, "%s", (buttonkey & IN_JUMP) ? " JUMP " : " ");
set_hudmessage(0, 255, 159, get_pcvar_float(cvar_x), get_pcvar_float(cvar_y), 0, _, 0.1, _, _, 1);
show_hudmessage(id, "%s^n%s %s %s^n^n%s %s", keybutton[0], keybutton[2], keybutton[1], keybutton[3], keybutton[4], keybutton[5]);
}
return FMRES_IGNORED;
}