Код:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#define KEVLAR 1
#define VESTHELM 2
#define ARMORTYPE_OFFSET 112
#define TITLE "Armor Drop"
#define VERSION "1.0"
#define AUTHOR "OneEyed"
new g_ArmorType[33], Float:g_ArmorAmount[33], fArmor[33]
new armor_dm1[] = "models/armor_dm/armor_dm_1.mdl"
new armor_dm2[] = "models/armor_dm/armor_dm_2.mdl"
new armor_sound1[] = "armor_sound/armor_sound.wav"
new g_msgScreenFade
new Float:multiplier
public plugin_precache()
{
precache_model(armor_dm1)
precache_model(armor_dm2)
precache_sound(armor_sound1)
}
public plugin_init() {
register_plugin(TITLE, VERSION, AUTHOR)
register_cvar(TITLE,VERSION,FCVAR_SERVER)
register_cvar("armor_pct","31")
register_cvar("armor_max","200")
register_cvar("armor_min","15")
register_cvar("armor_removetime","350")
register_cvar("armor_start_amount","50")
register_cvar("armor_start_type","2")
register_touch("FakeArmor","player","grabArmor")
register_event("DeathMsg","createArmor","a")
g_msgScreenFade = get_user_msgid("ScreenFade")
}
public removeArmor() {
new tempid = -1
while ( ( tempid = find_ent_by_class(tempid, "FakeArmor") ) > 0)
if(is_valid_ent(tempid)) {
remove_entity(tempid)
remove_task(tempid)
}
return PLUGIN_CONTINUE
}
public removeThisArmor(id)
if(is_valid_ent(id))
remove_entity(id)
public grabArmor(pToucher, pTouched) {
if(is_user_alive(pTouched) && is_user_connected(pTouched) && entity_get_float(pTouched,EV_FL_armorvalue) < float(get_cvar_num("armor_max"))) {
new owner = entity_get_int(pToucher, EV_INT_iuser1)
if(is_valid_ent(fArmor[owner])) {
get_armor_values(pTouched)
multiplier = float(get_cvar_num("armor_pct")) * 0.01
//Retrieve armor values left on the dropped kevlar
new armortype = entity_get_int(fArmor[owner], EV_INT_iuser3)
new armoramt = entity_get_int(fArmor[owner], EV_INT_iuser4)
client_cmd(pTouched,"spk %s",armor_sound1)
screen_fade(pTouched)
//Set armor accordingly to how player has theirs, and what type they grab.
if(g_ArmorType[pTouched] == 0)
csset_user_armor(pTouched, armoramt*multiplier, (armortype==1?KEVLAR:VESTHELM))
else if(g_ArmorType[pTouched] == 1 && armortype == 1)
csset_user_armor(pTouched, entity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), KEVLAR)
else if((g_ArmorType[pTouched] == 1 && armortype == 2) || g_ArmorType[pTouched] == 2)
csset_user_armor(pTouched, entity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), VESTHELM)
// If their armor goes over MAXARMOR set it to MAXARMOR
if(entity_get_float(pTouched,EV_FL_armorvalue) > float(get_cvar_num("armor_max")))
entity_set_float(pTouched,EV_FL_armorvalue, float(get_cvar_num("armor_max")))
g_ArmorType[pTouched] = armortype
remove_entity(fArmor[owner])
remove_task(fArmor[owner])
}
}
return PLUGIN_HANDLED
}
public screen_fade(id) {
message_begin(MSG_ONE, g_msgScreenFade, {0,0,0}, id)
write_short(1<<12)
write_short(1<<12)
write_short(1<<12)
write_byte(0)
write_byte(0)
write_byte(255)
write_byte(20)
message_end()
}
public createArmor(id)
{
new num = random_num(0, 5)
if(num > 1 || num < 0)
return PLUGIN_HANDLED
new victim = read_data(2) //grab user ID who died
get_armor_values(victim)
if(g_ArmorAmount[victim] <= float(get_cvar_num("armor_min")))
return PLUGIN_CONTINUE
new Float:fOrigin[3]
pev(victim, pev_origin, fOrigin);
fArmor[victim] = create_entity("info_target")
entity_set_string(fArmor[victim],EV_SZ_classname,"FakeArmor")
entity_set_origin(fArmor[victim], fOrigin)
entity_set_vector(fArmor[victim], EV_VEC_mins, Float: {-6.0, -8.0, -1.5})
entity_set_vector(fArmor[victim], EV_VEC_maxs, Float: {6.0, 8.0, 1.5})
entity_set_int(fArmor[victim], EV_INT_solid, SOLID_TRIGGER)
entity_set_int(fArmor[victim], EV_INT_movetype, MOVETYPE_PUSHSTEP)
switch(random_num(0,1))
{
case 0: entity_set_model(fArmor[victim],armor_dm1)
case 1: entity_set_model(fArmor[victim],armor_dm2)
}
// Sets iuser1 to victim ID
entity_set_int(fArmor[victim], EV_INT_iuser1, victim)
// Sets iuser3 to Armor Type (kevlar of vest+helm)
entity_set_int(fArmor[victim], EV_INT_iuser3, g_ArmorType[victim])
// Sets iuser4 to Armor Value (amount victim had when he died)
entity_set_int(fArmor[victim], EV_INT_iuser4, floatround(g_ArmorAmount[victim]))
new Float: fVelocity[3];
fVelocity[0] = random_float(50.0, 100.0)
fVelocity[1] = random_float(50.0, 100.0)
fVelocity[2] = random_float(200.0, 250.0)
entity_set_vector(fArmor[victim], EV_VEC_velocity, fVelocity)
set_task(float(get_cvar_num("armor_removetime")),"removeThisArmor",fArmor[victim])
return PLUGIN_HANDLED
}
public get_armor_values(id) {
if(entity_get_float(id,EV_FL_armorvalue) <= 0.0) {
g_ArmorType[id] = get_cvar_num("armor_start_type")
g_ArmorAmount[id] = float(get_cvar_num("armor_start_amount"))
}
else {
g_ArmorAmount[id] = entity_get_float(id,EV_FL_armorvalue)
g_ArmorType[id] = get_pdata_int(id,ARMORTYPE_OFFSET)
}
}
public csset_user_armor(id, Float:amount, type) {
entity_set_float(id,EV_FL_armorvalue, amount)
set_pdata_int(id,ARMORTYPE_OFFSET,type)
}