Hello.
Question: Why does the frequency of the call ham_think (for a particular entity!) Increases with the total number of "healthkit_entity"?
Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#pragma semicolon 1
// Шансы и количества
#define HK_FULL_CHANCE 10 // Процент вероятности выпадение полной аптечки (0 - никогда, 100 - всегда)
#define HK_FULL_HEALTH 100 // Сколько восстанавливает полная аптечка? (Лимит не привышаем)
#define HK_HEADSHOT_CHANCE 100 // Процент вероятности выпадения аптечки при убийстве в голову (0 - никогда, 100 - всегда)
#define HK_HEADSHOT_HEALTH 30 // Сколько восстанавливает аптечка при убийстве в голову? (Лимит не привышаем)
#define HK_NORMAL_CHANCE 100 // Процент вероятности выпадения простой аптечки 0 - никогда, 100 - всегда)
#define HK_NORMAL_HEALTH 15 // Сколько восстанавливает простая аптечка? (Лимит не привышаем)
#define HK_LIMIT_HEALTH 100 // Сколько максимум HP может быть у игроков?
// Эффекты
#define HK_HEALTHKIT_GLOW 1 // Подсвечивать аптечки? (0 - нет, 1 - да)
#define HK_PLAYER_FADE 1 // Затемнять игроку экран при поднятии аптечки? (0 - нет, 1 - да)
#define HK_PLAYER_HUD 1 // Показывать игроку HUD сообщение при поднятии аптечки? (0 - нет, 1 - да)
#define HK_HEALTHKIT_EFFECT 1 // Включить эффект плавного исчезания аптечки? (0 - нет, 1 - да)
// Другое
#define HK_ROUND_REMOVE 1 // Убирать аптечки в начале раунда? (0 - нет, 1 - да)
#define HK_LIFE_TIME 60 // Сколько секунд может лежать аптечка? (0 - бесконечно)
#define HK_OWNER_ONLY 0 // Только убийца может подобрать аптечку? (0 - нет, 1 - да, но после смерти или выхода могут все, 2 - да, но после смерти или выхода убрать аптечки, 3 - всегда, но после выхода могут все, 4 - всегда, но после выхода убрать аптечки) [Не советовал бы ставить 1 или 2]
// Дальше трогаем только если есть хоть чутка мозгов
#define min_ex(%1,%2) (%1 <= %2 ? %1 : %2)
new msg_pickup;
#if HK_PLAYER_FADE == 1
new msg_fade;
#endif
public plugin_init()
{
register_plugin("Healthkit", "3.3.1", "Tuty ft. Sho0ter");
#if HK_ROUND_REMOVE == 1
register_event("HLTV", "ev_start", "a", "1=0", "2=0");
#endif
register_event("DeathMsg", "ev_death", "a", "1>0");
#if HK_PLAYER_FADE == 1
msg_fade = get_user_msgid("ScreenFade");
#endif
msg_pickup = get_user_msgid("ItemPickup");
return PLUGIN_CONTINUE;
}
public plugin_precache()
{
precache_model("models/w_medkit.mdl");
return precache_sound("items/smallmedkit1.wav");
}
public ev_death()
{
#if HK_OWNER_ONLY > 0
new killer_id = read_data(1);
if(!is_user_connected(killer_id))
{
killer_id = 0;
}
#endif
new type, victim_id = read_data(2), chance = random_num(1, 100);
#if HK_OWNER_ONLY == 1 || HK_OWNER_ONLY == 2
remove_owner(victim_id);
#endif
if(chance <= HK_FULL_CHANCE)
{
type = 1;
}
else if(read_data(3))
{
if(chance <= HK_HEADSHOT_CHANCE)
{
type = 2;
}
else
{
return PLUGIN_CONTINUE;
}
}
else if(chance <= HK_NORMAL_CHANCE)
{
type = 3;
}
else
{
return PLUGIN_CONTINUE;
}
new entity;
if(!pev_valid((entity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target")))))
{
return PLUGIN_CONTINUE;
}
set_pev(entity, pev_classname, "healthkit_entity");
#if HK_OWNER_ONLY > 0
set_pev(entity, pev_owner, killer_id);
#endif
set_pev(entity, pev_iuser1, 0);
engfunc(EngFunc_SetSize, entity, Float:{-23.160000, -13.660000, -0.050000}, Float:{11.470000, 12.780000, 6.720000});
set_pev(entity, pev_solid, SOLID_TRIGGER);
set_pev(entity, pev_movetype, MOVETYPE_TOSS);
new Float:angles[3] = {0.0, 0.0, 0.0};
angles[1] = float(random_num(0, 180));
set_pev(entity, pev_angles, angles);
new Float:origin[3];
pev(victim_id, pev_origin, origin);
engfunc(EngFunc_SetOrigin, entity, origin);
engfunc(EngFunc_SetModel, entity, "models/w_medkit.mdl");
#if HK_HEALTHKIT_GLOW == 1
set_pev(entity, pev_renderfx, kRenderFxGlowShell);
set_pev(entity, pev_rendercolor, type == 1 ? (Float:{255.0, 0.0, 0.0}) : (type == 2 ? (Float:{0.0, 255.0, 0.0}) : (Float:{0.0, 0.0, 255.0})));
set_pev(entity, pev_rendermode, kRenderFxNone);
set_pev(entity, pev_renderamt, 25.0);
#endif
set_pev(entity, pev_health, type == 1 ? float(HK_FULL_HEALTH) : (type == 2 ? float(HK_HEADSHOT_HEALTH) : float(HK_NORMAL_HEALTH)));
#if HK_LIFE_TIME > 0
set_pev(entity, pev_iuser2, _:RegisterHamFromEntity(Ham_Think, entity, "ham_think", 1));
set_pev(entity, pev_nextthink, get_gametime() + float(HK_LIFE_TIME));
#endif
return set_pev(entity, pev_iuser3, _:RegisterHamFromEntity(Ham_Touch, entity, "ham_touch", 1));
}
public ham_touch(entity, touch_id)
{
if(!pev_valid(entity) || !is_user_connected(touch_id))
{
return HAM_IGNORED;
}
#if HK_OWNER_ONLY > 0
new owner = pev(entity, pev_owner);
if(owner && owner != touch_id)
{
return HAM_IGNORED;
}
#endif
new current_hp = pev(touch_id, pev_health);
if(current_hp >= HK_LIMIT_HEALTH)
{
return HAM_IGNORED;
}
new healthkit_value = pev(entity, pev_health);
#if HK_HEALTHKIT_EFFECT == 1
if(!healthkit_value)
{
return HAM_IGNORED;
}
#endif
#if HK_PLAYER_HUD == 1
switch(healthkit_value)
{
case HK_FULL_HEALTH: set_hudmessage(255, 0, 0, -1.0, 0.80, 0, 1.0, 1.0, 1.0, 1.0);
case HK_HEADSHOT_HEALTH: set_hudmessage(0, 255, 0, -1.0, 0.80, 0, 1.0, 1.0, 1.0, 1.0);
case HK_NORMAL_HEALTH: set_hudmessage(0, 0, 255, -1.0, 0.80, 0, 1.0, 1.0, 1.0, 1.0);
}
show_hudmessage(touch_id, "+ %d HP", healthkit_value);
#endif
set_pev(touch_id, pev_health, float(min_ex(current_hp + healthkit_value, HK_LIMIT_HEALTH)));
emit_sound(touch_id, CHAN_ITEM, "items/smallmedkit1.wav", VOL_NORM, ATTN_NORM , 0, PITCH_NORM);
message_begin(MSG_ONE_UNRELIABLE, msg_pickup, _, touch_id);
write_string("item_healthkit");
message_end();
#if HK_PLAYER_FADE == 1
message_begin(MSG_ONE_UNRELIABLE, msg_fade , _, touch_id);
write_short(1 << 10);
write_short(1 << 10);
write_short(0x0000);
write_byte(healthkit_value == HK_FULL_HEALTH ? 255 : 0);
write_byte(healthkit_value == HK_HEADSHOT_HEALTH ? 255 : 0);
write_byte(healthkit_value == HK_NORMAL_HEALTH ? 255 : 0);
write_byte(100);
message_end();
#endif
#if HK_HEALTHKIT_EFFECT == 1
return ham_think(entity);
#else
return remove_entity(entity);
#endif
}
public ham_think(entity)
{
if(!pev_valid(entity))
{
return HAM_IGNORED;
}
#if HK_HEALTHKIT_EFFECT == 1
if(pev(entity, pev_rendermode) != kRenderTransAlpha)
{
set_pev(entity, pev_health, 0.0);
set_pev(entity, pev_rendercolor, Float:{0.0, 0.0, 0.0});
set_pev(entity, pev_rendermode, kRenderTransAlpha);
set_pev(entity, pev_renderamt, 250.0);
}
else
{
new amount = pev(entity, pev_renderamt);
if(!amount)
{
return remove_entity(entity);
}
set_pev(entity, pev_renderamt, float(amount - 10));
}
return set_pev(entity, pev_nextthink, get_gametime() + 0.1);
#else
return remove_entity(entity);
#endif
}
#if HK_ROUND_REMOVE == 1
public ev_start()
{
new entity;
while((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", "healthkit_entity")))
{
remove_entity(entity);
}
return PLUGIN_CONTINUE;
}
#endif
#if HK_OWNER_ONLY > 0
public client_disconnect(client_id)
{
return remove_owner(client_id);
}
stock remove_owner(client_id)
{
new entity;
while((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", "healthkit_entity")))
{
if(pev(entity, pev_owner) == client_id)
{
#if HK_OWNER_ONLY == 1 || HK_OWNER_ONLY == 3
set_pev(entity, pev_owner, 0);
#else
#if HK_HEALTHKIT_EFFECT == 1
ham_think(entity);
#else
remove_entity(entity);
#endif
#endif
}
}
return PLUGIN_CONTINUE;
}
#endif
stock remove_entity(entity)
{
#if HK_LIFE_TIME > 0
DisableHamForward(HamHook:pev(entity, pev_iuser2));
#endif
DisableHamForward(HamHook:pev(entity, pev_iuser3));
return engfunc(EngFunc_RemoveEntity, entity);
}