#include <amxmodx>
#include <reapi>
#tryinclude <resemiclip> // using amxx version by Next21 (https://github.com/Next21Team/resemiclip-amxx)
#if REAPI_VERSION < 524300
#include <engine>
#endif
#define Plugin_Name "[GM] Spawn semiclip"
#define Plugin_Version "1.1.1"
#define Plugin_Author "[GM] NWC"
new Float: g_flRadius;
new bool: g_bSpawn[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin(Plugin_Name, Plugin_Version, Plugin_Author);
#if defined _engine_included
register_touch("player", "player", "@RH_SV_AllowPhysent");
#elseif REAPI_VERSION < 524309
RegisterHookChain(RH_ExecuteServerStringCmd, "@RH_SV_AllowPhysent", false);
#else
RegisterHookChain(RH_SV_AllowPhysent, "@RH_SV_AllowPhysent", false);
#endif
#if defined _resemiclip_included
resemiclip_take_control(true);
#endif
RegisterHookChain(RG_CBasePlayer_Spawn, "@RG_CBasePlayer_Spawn_Pre", false);
RegisterHookChain(RG_CBasePlayer_Spawn, "@RG_CBasePlayer_Spawn_Post", true);
bind_pcvar_float(create_cvar("ss_radius", "32.0", FCVAR_NONE, "Radius for check",
.has_min = true, .min_val = 32.0,
.has_max = true, .max_val = 256.0),
g_flRadius
);
}
@RG_CBasePlayer_Spawn_Pre(iPlayer)
{
g_bSpawn[iPlayer] = true;
}
@RG_CBasePlayer_Spawn_Post(iPlayer)
{
CheckSemiclip(iPlayer);
}
@RH_SV_AllowPhysent(iPlayerOne, iPlayerTwo)
{
if (g_bSpawn[iPlayerOne])
{
UTIL_SetSemiclip(iPlayerOne, true);
RequestFrame("CheckSemiclip", iPlayerOne);
}
if (g_bSpawn[iPlayerTwo])
{
UTIL_SetSemiclip(iPlayerTwo, true);
RequestFrame("CheckSemiclip", iPlayerTwo);
}
return PLUGIN_HANDLED;
}
public CheckSemiclip(const iPlayer)
{
if (!UTIL_FindPlayerInSphere(iPlayer))
{
g_bSpawn[iPlayer] = false;
UTIL_SetSemiclip(iPlayer, false);
}
else
{
RequestFrame("CheckSemiclip", iPlayer);
}
}
stock bool: UTIL_IsValidPlayer(const iPlayer)
{
if (0 < iPlayer <= MAX_PLAYERS) return true;
return false;
}
stock UTIL_SetSemiclip(const iPlayer, bool: bToggle)
{
#if defined _resemiclip_included
resemiclip_set_user_mask(iPlayer, bToggle ? 0xFFFFFFFF : 0);
#else
set_entvar(iPlayer, var_solid, bToggle ? SOLID_NOT : SOLID_SLIDEBOX);
#endif
}
stock UTIL_FindPlayerInSphere(const iPlayer)
{
new iEnt, Float: vecOrigin[3];
get_entvar(iPlayer, var_origin, vecOrigin);
while ((iEnt = find_ent_in_sphere(iEnt, vecOrigin, g_flRadius)))
{
if (UTIL_IsValidPlayer(iEnt) && iEnt != iPlayer && is_user_alive(iEnt)) return iEnt;
}
return 0;
}