#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <cs_weapons_api>
#include <amx_settings_api>
#include <ttt>
#define WEAPON_CSWID CSW_DEAGLE
#define WEAPON_NAME "weapon_deagle"
/*RECICLÉ PARTE DEL CÓDIGO DE STHONY DEL ITEM INVERSE GOLDEN*/
new g_szModels[3][TTT_FILELENGHT];
new g_BGun;
new bool:g_iBlinded[33];
new cvar_weapon_ammo, cvar_weapon_clip, cvar_weapon_price, cvar_weapon_reload, cvar_weapon_recoil, cvar_weapon_teamallow, cvar_weapon_time, g_MaxPlayers;
new g_msgScreenFade;
public plugin_precache()
{
if(!amx_load_setting_string(TTT_SETTINGSFILE, "BLINDING GUN", "MODEL_V", g_szModels[0], charsmax(g_szModels[])))
{
g_szModels[0] = "models/ttt/v_bgun.mdl";
amx_save_setting_string(TTT_SETTINGSFILE, "BLINDING GUN", "MODEL_V", g_szModels[0]);
}
precache_model(g_szModels[0]);
if(!amx_load_setting_string(TTT_SETTINGSFILE, "BLINDING GUN", "MODEL_P", g_szModels[1], charsmax(g_szModels[])))
{
g_szModels[1] = "models/ttt/p_bgun.mdl";
amx_save_setting_string(TTT_SETTINGSFILE, "BLINDING GUN", "MODEL_P", g_szModels[1]);
}
precache_model(g_szModels[1]);
if(!amx_load_setting_string(TTT_SETTINGSFILE, "BLINDING GUN", "MODEL_W", g_szModels[2], charsmax(g_szModels[])))
{
g_szModels[2] = "models/ttt/w_bgun.mdl";
amx_save_setting_string(TTT_SETTINGSFILE, "BLINDING GUN", "MODEL_W", g_szModels[2]);
}
precache_model(g_szModels[2]);
}
public plugin_init()
{
register_plugin("[TTT] Item: Blinding Gun", TTT_VERSION, "GabsHp & Sthony");
register_forward(FM_AddToFullPack, "AddToFullPackPost",1);
cvar_weapon_clip = my_register_cvar("ttt_bgun_clip", "1", "Blinding Gun clip(s). (Default: 2)");
cvar_weapon_ammo = my_register_cvar("ttt_bgun_ammo", "0", "Blinding Gun ammo (Default: 0)");
cvar_weapon_reload = my_register_cvar("ttt_bgun_reload", "0.0", "Blinding Gun reload speed. (Default: 0.0)");
cvar_weapon_recoil = my_register_cvar("ttt_bgun_recoil", "0.0", "Blinding Gun recoil. (Default: 0.0)");
cvar_weapon_price = my_register_cvar("ttt_bgun_price", "2", "Blinding Gun price. (Default: 2)");
cvar_weapon_teamallow = my_register_cvar("ttt_bgun_teamallow", "0", "Permitir el uso contra compañeros");
cvar_weapon_time = my_register_cvar("ttt_bgun_duration", "3", "Tiempo que durará cegado y congelado");
g_MaxPlayers = get_maxplayers();
g_msgScreenFade = get_user_msgid( "ScreenFade" );
}
public ttt_plugin_cfg()
{
g_BGun = ttt_buymenu_add( "Blinding Gun", get_pcvar_num(cvar_weapon_price), PC_DETECTIVE);
}
public ttt_gamemode(gamemode)
{
if(gamemode == GAME_ENDED || gamemode == GAME_RESTARTING)
{
for( new i = 1; i <= g_MaxPlayers; i++ )
{
if(g_iBlinded[i])
{
g_iBlinded[i] = false;
}
}
}
}
public ttt_item_selected(id, item, name[], price)
{
if(g_BGun == item)
{
if(user_has_weapon(id, WEAPON_CSWID))
engclient_cmd(id, "drop", WEAPON_NAME);
static data[STOREABLE_STRUCTURE];
if(!data[STRUCT_CSWA_CSW])
{
data[STRUCT_CSWA_ITEMID] = g_BGun;
data[STRUCT_CSWA_CSW] = WEAPON_CSWID;
data[STRUCT_CSWA_CLIP] = get_pcvar_num(cvar_weapon_clip);
data[STRUCT_CSWA_MAXCLIP] = get_pcvar_num(cvar_weapon_clip);
data[STRUCT_CSWA_AMMO] = get_pcvar_num(cvar_weapon_ammo);
data[STRUCT_CSWA_STACKABLE] = true;
data[STRUCT_CSWA_SILENCED] = -1;
data[STRUCT_CSWA_DAMAGE] = 1.0;
data[STRUCT_CSWA_RELOADTIME] = _:get_pcvar_float(cvar_weapon_reload);
data[STRUCT_CSWA_RECOIL] = _:get_pcvar_float(cvar_weapon_recoil);
data[STRUCT_CSWA_MODEL_V] = g_szModels[0];
data[STRUCT_CSWA_MODEL_P] = g_szModels[1];
data[STRUCT_CSWA_MODEL_W] = g_szModels[2];
}
cswa_give_specific(id, data);
client_print_color(id, print_team_default, "%s Compraste: !g'Blinding Gun'", TTT_TAG);
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public cswa_damage(weapon_id, victim, attacker, Float:damage)
{
if(get_weapon_edict(weapon_id, REPL_CSWA_ITEMID) == g_BGun)
{
if(ttt_get_playerstate(attacker) != PC_DETECTIVE ){
new szAttackerName[32]; get_user_name(attacker, szAttackerName, 31);
client_print_color(attacker, print_team_default, "%s !nEsta es un arma exclusiva de detectives, evita ser baneado!", TTT_TAG);
return HAM_IGNORED;
}
//FUNCION DE CONGELAR Y CEGAR AL ATACADO ...
if(ttt_get_playerstate(victim) == PC_DETECTIVE && get_pcvar_num(cvar_weapon_teamallow)!=1)
{
client_print_color(attacker, print_team_default, "%s !nHas sido castigado por intentar usar el arma en contra de tu team!", TTT_TAG);
FreezePlayer(attacker);
return HAM_IGNORED;
}
FreezePlayer(victim);
client_print_color(attacker, print_team_default, "%s !gHas sido blindeado por un detective!", TTT_TAG);
}
return HAM_IGNORED;
}
public FreezePlayer( const iId)
{
if(!is_user_connected(iId))
return;
entity_set_float( iId, EV_FL_maxspeed, 1.0 );
entity_set_vector( iId, EV_VEC_velocity, Float:{ 0.0, 0.0, 0.0 } );
g_iBlinded[iId]=true;
set_screenfade(iId, get_pcvar_num(cvar_weapon_time), 255);
set_task(Float:(get_pcvar_num(cvar_weapon_time)), "UnFreezePlayer", iId);
}
public UnFreezePlayer(const iId)
{
if(!is_user_connected(iId))
return;
ExecuteHamB( Ham_CS_Player_ResetMaxSpeed, iId );
g_iBlinded[iId]=false;
}
public AddToFullPackPost(es_handle, e, ent, host, hostflags, player, pSet)
{
if (!player)
return FMRES_IGNORED;
if (g_iBlinded[ent])
{
set_es(es_handle, ES_RenderFx, kRenderFxGlowShell);
if(ttt_get_playerstate(host) == PC_TRAITOR && ttt_get_playerstate(ent) == PC_TRAITOR)
{
//SI EL ATACADO ES TRAIDOR, SETEA UN COLOR AMARILLO QUE SOLO VERÁN LOS TRAIDORES
set_es ( es_handle, ES_RenderColor, { 255, 255, 0 } );
}
else
{
//SI EL HOST ES INOCENTE O DETECTIVE, EL GLOW LO VERÁN BLANCO BLANCO
set_es ( es_handle, ES_RenderColor, { 255, 255, 255 } );
}
}
return FMRES_IGNORED;
}
stock set_screenfade( id, iDuracion, iAlpha )
{
message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, g_msgScreenFade, _, id );
write_short( iDuracion * 4096 );
write_short( iDuracion * 4096 );
write_short( 0x0000 );
write_byte(255); // Color 1
write_byte(255); // Color 2
write_byte(255); // Color 3
write_byte( iAlpha );
message_end( );
}