|
#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <cstrike>
#include <xs>
#define PLUGIN "joaquimandrade"
#define AUTHOR "AntiCamper"
#define VERSION "1.0"
new Array:CampingPositions[33 char]
new MaxPlayers
const Float:CampingMeasureDelay = 2.5
const CampingMeasureSamples = 4
new CampMeterShow = 50
new CampingMeasurerPreClass[] = "measurer_pre";
new CampingMeasurerPostClass[] = "measurer_post";
new CampingMeasurerSamples[33 char]
new CampingMeasurerAttached[33]
new CampMeterPercent[33]
new CsTeams:PlayerTeam[33 char]
new CsTeams:TeamsSum = CS_TEAM_CT + CS_TEAM_T
new TeamsBits = (1 << _:CS_TEAM_T) | (1 << _:CS_TEAM_CT)
new CvarFreezeTime
new CvarPercent
new MsgHostagePosID
new MsgHostageKID
new MsgStatusIconID
new CampMaxIcon[] = "item_battery"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Spawn,"player","playerSpawnPre",0)
RegisterHam(Ham_Spawn,"player","playerSpawnPost",1)
register_think(CampingMeasurerPreClass,"campingMeasurerPreThink")
register_think(CampingMeasurerPostClass,"campingMeasurerPostThink")
RegisterHam(Ham_Killed,"player","playerKilled")
CvarFreezeTime = get_cvar_pointer("mp_freezetime")
CvarPercent = register_cvar("anticamper_percent","80")
register_cvar("anticamper_version",VERSION,FCVAR_SERVER|FCVAR_SPONLY)
}
public plugin_cfg()
{
MaxPlayers = get_maxplayers();
for(new i=1;i<=MaxPlayers;i++)
{
CampingPositions{i} = ArrayCreate(3);
}
MsgHostagePosID = get_user_msgid("HostagePos")
MsgHostageKID = get_user_msgid("HostageK")
MsgStatusIconID = get_user_msgid("StatusIcon")
if(find_ent_by_class(-1,"hostage_entity"))
{
TeamsBits &= ~(1 << _:CS_TEAM_T)
}
if(find_ent_by_class(-1,"func_bomb_target"))
{
register_event("TextMsg","bombPlanted","a","2=#Bomb_Planted")
TeamsBits &= ~(1 << _:CS_TEAM_CT)
}
}
public bombPlanted()
{
new Float:delay = 0.0
for(new id=1;id<=MaxPlayers;id++)
{
if(CampingMeasurerAttached[id])
{
removeAttached(id)
}
else if(is_user_alive(id))
{
new CsTeams:team = cs_get_user_team(id)
if(team == CS_TEAM_CT)
{
addCampingMeasurerPreSampling(id,delay)
delay += 0.1
}
}
}
}
public client_authorized(id)
{
checkAttachedRemoval(id)
}
public client_disconnect(id)
{
checkAttachedRemoval(id)
}
public playerKilled(id,attackerID,shouldgib)
{
checkAttachedRemoval(id)
}
checkAttachedRemoval(id)
{
if(CampingMeasurerAttached[id])
{
removeAttached(id);
}
}
removeAttached(id)
{
remove_entity(CampingMeasurerAttached[id])
CampingMeasurerAttached[id] = 0
if(!is_user_bot(id))
{
if(CampMeterPercent[id] == 100)
{
showMaxCamper(id,true)
}
else if(CampMeterPercent[id] > 0)
{
new number1 = CampMeterPercent[id] % 10
new number2 = CampMeterPercent[id] / 10
showNumber(id,number1 - _:(number2 == number1),true);
showNumber(id,number2,true);
}
}
}
addCampingMeasurer(id,class[],Float:delay = 0.0)
{
new ent = create_entity("info_target")
assert ent;
CampingMeasurerAttached[id] = ent
entity_set_string(ent,EV_SZ_classname,class)
entity_set_float(ent,EV_FL_nextthink,get_gametime() + delay)
entity_set_edict(ent,EV_ENT_owner,id)
}
addCampingMeasurerPreSampling(id,Float:delay = 0.0)
{
CampingMeasurerSamples{id} = 0
ArrayClear(CampingPositions{id})
CampMeterPercent[id] = 0
addCampingMeasurer(id,CampingMeasurerPreClass,delay);
}
addCampingMeasurerPreSamplingT(id)
{
new Float:freezeTime = get_pcvar_float(CvarFreezeTime);
if(freezeTime < 0.0)
freezeTime = 0.0
addCampingMeasurerPreSampling(id,freezeTime);
}
addCampingMeasurerPostSampling(id)
{
addCampingMeasurer(id,CampingMeasurerPostClass);
}
public campingMeasurerPreThink(ent)
{
new id = entity_get_edict(ent,EV_ENT_owner)
if(CampingMeasurerSamples{id}++ == (CampingMeasureSamples - 1))
{
remove_entity(ent);
addCampingMeasurerPostSampling(id)
}
else
{
static Float:origin[3]
entity_get_vector(id,EV_VEC_origin,origin)
ArrayPushArray(CampingPositions{id},origin)
entity_set_float(ent,EV_FL_nextthink,get_gametime() + CampingMeasureDelay)
}
}
public campingMeasurerPostThink(ent)
{
new id = entity_get_edict(ent,EV_ENT_owner)
new Float:originSum[3]
for(new i=0;i<CampingMeasureSamples - 1;i++)
{
static Float:originSample[3]
ArrayGetArray(CampingPositions{id},i,originSample)
xs_vec_add(originSum,originSample,originSum);
}
static Float:origin[3]
entity_get_vector(id,EV_VEC_origin,origin)
ArrayPushArray(CampingPositions{id},origin)
xs_vec_add(originSum,origin,originSum);
static Float:originAvg[3]
xs_vec_div_scalar(originSum, float(CampingMeasureSamples) ,originAvg)
new Float:originVariance[3]
for(new i=0;i<CampingMeasureSamples;i++)
{
static Float:originSample[3]
ArrayGetArray(CampingPositions{id},i,originSample)
for(new j=0;j<3;j++)
{
originVariance[j] += floatpower(originSample[j] - originAvg[j], 2.0);
}
}
new Float:originVarianceSum
for(new i=0;i<3;i++)
{
originVarianceSum += originVariance[i] / CampingMeasureSamples
}
originVarianceSum = floatsqroot(originVarianceSum / 3.0)
originVarianceSum -= 120.0
originVarianceSum /= 14.0
new newCampMeterValue = clamp(CampMeterPercent[id] - floatround(originVarianceSum),0,100)
if(!is_user_bot(id))
{
if(CampMeterPercent[id] != newCampMeterValue)
{
if(CampMeterPercent[id] >= CampMeterShow)
{
if(CampMeterPercent[id] == 100)
{
showMaxCamper(id,true)
}
else
{
new number1 = CampMeterPercent[id] % 10
new number2 = CampMeterPercent[id] / 10
showNumber(id,number1 - _:(number2 == number1),true);
showNumber(id,number2,true);
}
}
CampMeterPercent[id] = newCampMeterValue
if(CampMeterPercent[id] >= CampMeterShow)
{
new color[3] = {0,160,0}
if(CampMeterPercent[id] >= clamp(get_pcvar_num(CvarPercent),80,100))
{
color = {255,0,0}
}
else if(CampMeterPercent[id] >= 65)
{
color = {255,255,0}
}
if(CampMeterPercent[id] == 100)
{
showMaxCamper(id,.color=color)
}
else
{
new number1 = CampMeterPercent[id] % 10
new number2 = CampMeterPercent[id] / 10
showNumber(id,number1 - _:(number2 == number1),.color=color);
showNumber(id,number2,.color=color);
}
}
}
}
CampMeterPercent[id] = newCampMeterValue
if(CampMeterPercent[id] >= clamp(get_pcvar_num(CvarPercent),80,100))
{
new CsTeams:adversary = TeamsSum - PlayerTeam{id}
for(new i=1;i<=MaxPlayers;i++)
{
if(is_user_connected(i) && !is_user_bot(i) && (cs_get_user_team(i) == adversary))
{
showOnRadar(i,id,origin)
}
}
}
ArrayDeleteItem(CampingPositions{id},0)
entity_set_float(ent,EV_FL_nextthink,get_gametime() + CampingMeasureDelay)
}
public playerSpawnPre(id)
{
if(is_user_alive(id))
{
checkAttachedRemoval(id)
}
}
public playerSpawnPost(id)
{
if(is_user_alive(id))
{
checkAttachedRemoval(id)
PlayerTeam{id} = cs_get_user_team(id);
if(TeamsBits & (1 << _:PlayerTeam{id}))
{
addCampingMeasurerPreSamplingT(id)
}
}
}
showOnRadar(id,camperID,Float:origin[3])
{
message_begin(MSG_ONE_UNRELIABLE, MsgHostagePosID, .player=id)
write_byte(id)
write_byte(camperID)
engfunc(EngFunc_WriteCoord,origin[0])
engfunc(EngFunc_WriteCoord,origin[1])
engfunc(EngFunc_WriteCoord,origin[2])
message_end()
message_begin(MSG_ONE_UNRELIABLE, MsgHostageKID, .player=id)
write_byte(camperID)
message_end()
}
showNumber(id,number,bool:hide = false, color[3] = {0,0,0})
{
static numberString[] = "number_x"
clamp(number,0,9);
numberString[sizeof numberString - 2] = number + 48;
message_begin(MSG_ONE_UNRELIABLE, MsgStatusIconID,.player=id);
write_byte(!hide);
write_string(numberString);
if(!hide)
{
write_byte(color[0]);
write_byte(color[1]);
write_byte(color[2]);
}
message_end();
}
showMaxCamper(id,bool:hide = false, color[3] = {0,0,0})
{
message_begin(MSG_ONE_UNRELIABLE, MsgStatusIconID,.player=id);
write_byte(!hide);
write_string(CampMaxIcon);
if(!hide)
{
write_byte(color[0]);
write_byte(color[1]);
write_byte(color[2]);
}
message_end();
} |
|