-=反蹲坑=-【未汉化】
#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
new MaxPlayers
const Float:CampingMeasureDelay = 2.5
const CampingMeasureSamples = 4
new CampMeterShow = 50
new CampingMeasurerPreClass[] = "measurer_pre";
new CampingMeasurerPostClass[] = "measurer_post";
new CampingMeasurerSamples
new CampingMeasurerAttached
new CampMeterPercent
new CsTeams:PlayerTeam
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)
{
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)
{
removeAttached(id);
}
}
removeAttached(id)
{
remove_entity(CampingMeasurerAttached)
CampingMeasurerAttached = 0
if(!is_user_bot(id))
{
if(CampMeterPercent == 100)
{
showMaxCamper(id,true)
}
else if(CampMeterPercent > 0)
{
new number1 = CampMeterPercent % 10
new number2 = CampMeterPercent / 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 = 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 = 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
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
for(new i=0;i<CampingMeasureSamples - 1;i++)
{
static Float:originSample
ArrayGetArray(CampingPositions{id},i,originSample)
xs_vec_add(originSum,originSample,originSum);
}
static Float:origin
entity_get_vector(id,EV_VEC_origin,origin)
ArrayPushArray(CampingPositions{id},origin)
xs_vec_add(originSum,origin,originSum);
static Float:originAvg
xs_vec_div_scalar(originSum, float(CampingMeasureSamples) ,originAvg)
new Float:originVariance
for(new i=0;i<CampingMeasureSamples;i++)
{
static Float:originSample
ArrayGetArray(CampingPositions{id},i,originSample)
for(new j=0;j<3;j++)
{
originVariance += floatpower(originSample - originAvg, 2.0);
}
}
new Float:originVarianceSum
for(new i=0;i<3;i++)
{
originVarianceSum += originVariance / CampingMeasureSamples
}
originVarianceSum = floatsqroot(originVarianceSum / 3.0)
originVarianceSum -= 120.0
originVarianceSum /= 14.0
new newCampMeterValue = clamp(CampMeterPercent - floatround(originVarianceSum),0,100)
if(!is_user_bot(id))
{
if(CampMeterPercent != newCampMeterValue)
{
if(CampMeterPercent >= CampMeterShow)
{
if(CampMeterPercent == 100)
{
showMaxCamper(id,true)
}
else
{
new number1 = CampMeterPercent % 10
new number2 = CampMeterPercent / 10
showNumber(id,number1 - _:(number2 == number1),true);
showNumber(id,number2,true);
}
}
CampMeterPercent = newCampMeterValue
if(CampMeterPercent >= CampMeterShow)
{
new color = {0,160,0}
if(CampMeterPercent >= clamp(get_pcvar_num(CvarPercent),80,100))
{
color = {255,0,0}
}
else if(CampMeterPercent >= 65)
{
color = {255,255,0}
}
if(CampMeterPercent == 100)
{
showMaxCamper(id,.color=color)
}
else
{
new number1 = CampMeterPercent % 10
new number2 = CampMeterPercent / 10
showNumber(id,number1 - _:(number2 == number1),.color=color);
showNumber(id,number2,.color=color);
}
}
}
}
CampMeterPercent = newCampMeterValue
if(CampMeterPercent >= 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)
{
message_begin(MSG_ONE_UNRELIABLE, MsgHostagePosID, .player=id)
write_byte(id)
write_byte(camperID)
engfunc(EngFunc_WriteCoord,origin)
engfunc(EngFunc_WriteCoord,origin)
engfunc(EngFunc_WriteCoord,origin)
message_end()
message_begin(MSG_ONE_UNRELIABLE, MsgHostageKID, .player=id)
write_byte(camperID)
message_end()
}
showNumber(id,number,bool:hide = false, color = {0,0,0})
{
static numberString[] = "number_x"
clamp(number,0,9);
numberString = number + 48;
message_begin(MSG_ONE_UNRELIABLE, MsgStatusIconID,.player=id);
write_byte(!hide);
write_string(numberString);
if(!hide)
{
write_byte(color);
write_byte(color);
write_byte(color);
}
message_end();
}
showMaxCamper(id,bool:hide = false, color = {0,0,0})
{
message_begin(MSG_ONE_UNRELIABLE, MsgStatusIconID,.player=id);
write_byte(!hide);
write_string(CampMaxIcon);
if(!hide)
{
write_byte(color);
write_byte(color);
write_byte(color);
}
message_end();
}
页:
[1]