// Copyright © 2016 Vaqtincha
/****************************************************
* Credits: to
*
* VEN - "Teleport Smoke Grenade"
* ConnorMcLeod - Cstrike Pdatas
*
*****************************************************/
//================= CONFIG START ====================//
new const TELEPORT_SOUND[]= "player/pl_step4.wav"
//================== CONFIG END =====================//
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define MAX_PLAYERS 32
#define get_weapon_owner(%1) get_pdata_cbase(%1, m_pPlayer, XO_WEAPON)
const SMOKE_GROUND_OFFSET = 6
const SMOKE_EVENT = 1<<1
// offsets
#if AMXX_VERSION_NUM < 183
const m_bHasShield = 1<<24
const m_iUserPrefs = 510
#define HasShield(%1) (get_pdata_int(%1, m_iUserPrefs) & m_bHasShield)
#else
const m_bHasShield = 2043
#define HasShield(%1) get_pdata_bool(%1, m_bHasShield)
#endif
const m_pPlayer = 41
const m_usEvent = 114
new const Float:gflSign[4][2] = {{1.0, 1.0}, {1.0, -1.0}, {-1.0, -1.0}, {-1.0, 1.0}}
new const class[] = "weapon_smokegrenade"
new bool:gbMode[MAX_PLAYERS + 1]
public plugin_precache()
precache_sound(TELEPORT_SOUND) // for custom sounds
public plugin_init()
{
register_plugin("Smoke Grenade Modes Lite", "0.0.3", "Vaqtincha")
register_forward(FM_EmitSound, "FM_EmitSound_Pre", false)
RegisterHam(Ham_Weapon_SecondaryAttack, class, "Ham_SecAttack_Post", true)
RegisterHam(Ham_Item_Deploy, class, "Ham_ItemDeploy_Post", true)
}
public client_putinserver(id)
gbMode[id] = true // default smoke mode: true|false (teleport|smoke)
public FM_EmitSound_Pre(ent, channel, const sound[])
{
if(!equal(sound, "weapons/sg_explode.wav"))
return FMRES_IGNORED
if(~get_pdata_int(ent, m_usEvent) & SMOKE_EVENT)
return FMRES_IGNORED
static owner; owner = pev(ent, pev_owner)
if(gbMode[owner])
{
static Float:p_origin[3]
pev(owner, pev_origin, p_origin)
p_origin[2] -= 30
teleport_sprite_effect(p_origin)
static Float:origin[3]
pev(ent, pev_origin, origin)
origin[2] += SMOKE_GROUND_OFFSET
teleport_sprite_effect(origin)
// safe remove
engfunc(EngFunc_SetOrigin, ent, Float:{-8191.0, -8191.0, -8191.0})
// engfunc(EngFunc_RemoveEntity, ent)
static Float:mins[3], hull
pev(owner, pev_mins, mins)
origin[2] -= mins[2] + SMOKE_GROUND_OFFSET
hull = pev(owner, pev_flags) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN
if(!is_user_alive(owner)) // owner killed
return FMRES_IGNORED
if(is_hull_vacant(origin, hull))
engfunc(EngFunc_SetOrigin, owner, origin)
else{
static Float:vec[3]
vec[2] = origin[2]
for(new i; i < sizeof(gflSign); ++i)
{
vec[0] = origin[0] - mins[0] * gflSign[0]
vec[1] = origin[1] - mins[1] * gflSign[1]
if(is_hull_vacant(vec, hull))
{
engfunc(EngFunc_SetOrigin, owner, vec)
break
}
}
}
emit_sound(owner, CHAN_BODY, TELEPORT_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
}
return FMRES_IGNORED
}
stock teleport_sprite_effect(const Float:origin[3])
{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_TELEPORT)
write_coord(floatround(origin[0])) // position x
write_coord(floatround(origin[1])) // position y
write_coord(floatround(origin[2])+30) // position z
message_end()
}
// by VEN
stock bool:is_hull_vacant(const Float:origin[3], hull)
{
new tr = 0
engfunc(EngFunc_TraceHull, origin, origin, 0, hull, 0, tr)
if(!get_tr2(tr, TR_StartSolid) && !get_tr2(tr, TR_AllSolid) && get_tr2(tr, TR_InOpen))
return true
return false
}