/*================================================================================
-------------------------------------------------
-*- [ZP] Extra Item: Thermal Goggles 1.0 -*-
-------------------------------------------------
~~~~~~~~~~~~~~~
- Description -
~~~~~~~~~~~~~~~
This item gives humans the ability to detect players in a gamet through thermal detection.
Credits :
Cheapsuit - For thermal code
G-dog, alan el more & Alejandro - For correcting me ^^
================================================================================*/
#include <amxmodx>
#include <engine>
#include <xs>
#include <zombieplague>
#include <fakemeta>
new const g_item_name[] = { "Thermal Goggles" };
new const g_item_cost = 0
new const g_sound_buygoggles[] = { "items/nvg_on.wav" }
new Float:g_fDelay[33]
new g_itemid_goggles;
new g_ThermalOn[33]
new sprite_playerheat
new cvar_maxdistance
new cvar_updatedelay
static const PLUGIN_NAME[] = "Thermal Goggles"
static const PLUGIN_AUTHOR[] = "ROADRAGE"
static const PLUGIN_VERSION[] = "1.0"
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_cvar(PLUGIN_NAME, PLUGIN_VERSION, FCVAR_SPONLY|FCVAR_SERVER)
g_itemid_goggles = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_HUMAN);
cvar_maxdistance = register_cvar("amx_tig_distance", "700")
cvar_updatedelay = register_cvar("amx_tig_updatedelay", "0.2")
register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
register_forward(FM_PlayerPreThink,"FW_PlayerPreThink");
}
public plugin_precache()
{
sprite_playerheat = precache_model("sprites/poison.spr")
precache_sound(g_sound_buygoggles)
}
public FW_PlayerPreThink(id) // THANKS TO CHEAPSUIT FOR THERMAL CODE
{
if(!is_user_alive(id) ||zp_get_user_zombie(id)||!g_ThermalOn[id])
return PLUGIN_CONTINUE
if((g_fDelay[id] + get_pcvar_float(cvar_updatedelay)) > get_gametime())
return PLUGIN_CONTINUE
g_fDelay[id] = get_gametime()
new Float:fMyOrigin[3]
entity_get_vector(id, EV_VEC_origin, fMyOrigin)
static Players[32], iNum
get_players(Players, iNum, "a")
for(new i = 0; i < iNum; ++i) if(id != Players[i])
{
new target = Players[i]
new Float:fTargetOrigin[3]
entity_get_vector(target, EV_VEC_origin, fTargetOrigin)
if((get_distance_f(fMyOrigin, fTargetOrigin) > get_pcvar_num(cvar_maxdistance))
|| !is_in_viewcone(id, fTargetOrigin))
continue
new Float:fMiddle[3], Float:fHitPoint[3]
xs_vec_sub(fTargetOrigin, fMyOrigin, fMiddle)
trace_line(-1, fMyOrigin, fTargetOrigin, fHitPoint)
new Float:fWallOffset[3], Float:fDistanceToWall
fDistanceToWall = vector_distance(fMyOrigin, fHitPoint) - 10.0
normalize(fMiddle, fWallOffset, fDistanceToWall)
new Float:fSpriteOffset[3]
xs_vec_add(fWallOffset, fMyOrigin, fSpriteOffset)
new Float:fScale, Float:fDistanceToTarget = vector_distance(fMyOrigin, fTargetOrigin)
if(fDistanceToWall > 100.0)
fScale = 8.0 * (fDistanceToWall / fDistanceToTarget)
else
fScale = 2.0
te_sprite(id, fSpriteOffset, sprite_playerheat, floatround(fScale), 125)
}
return PLUGIN_CONTINUE
}
stock te_sprite(id, Float:origin[3], sprite, scale, brightness)
{
message_begin(MSG_ONE, SVC_TEMPENTITY, _, id)
write_byte(TE_SPRITE)
write_coord(floatround(origin[0]))
write_coord(floatround(origin[1]))
write_coord(floatround(origin[2]))
write_short(sprite)
write_byte(scale)
write_byte(brightness)
message_end()
}
stock normalize(Float:fIn[3], Float:fOut[3], Float:fMul)
{
new Float:fLen = xs_vec_len(fIn)
xs_vec_copy(fIn, fOut)
fOut[0] /= fLen, fOut[1] /= fLen, fOut[2] /= fLen
fOut[0] *= fMul, fOut[1] *= fMul, fOut[2] *= fMul
}
public zp_extra_item_selected(player, itemid)
{
if ( g_ThermalOn[player] )
{
client_print(player, print_chat, "[ZP] You already bought this.")
return PLUGIN_HANDLED
}
if (itemid == g_itemid_goggles)
{
FW_PlayerPreThink(player)
g_ThermalOn[player] = true
engfunc(EngFunc_EmitSound, player, CHAN_BODY, g_sound_buygoggles, 1.0, ATTN_NORM, 0, PITCH_NORM)
client_print(player, print_chat, "[ZP] You've bought thermal goggles")
}
return PLUGIN_CONTINUE
}
// Reset goggles for all players on newround
public EVENT_round_start()
{
for (new id; id <= 32; id++) g_ThermalOn[id] = true;
}