#include <amxmodx>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fun>
#define PLUGIN "DropPack"
#define VERSION "1.0"
#define AUTHOR "cypis"
new const maxAmmo[] = {0,52,0,90,0,32,0,100,90,0,120,100,100,90,90,90,100,120,30,120,200,32,90,120,90,0,35,90,90,0,100,0,0,0};
new const maxClip[] = {0,13,0,10,0,7,0,30,30,0,30,20,25,30,35,25,12,20,10,30,100,8,30,30,20,0,7,30,30,0,50,0,0,0};
new const g_szWeaponEntity[][24] =
{
"",
"weapon_p228",
"weapon_shield",
"weapon_scout",
"weapon_hegrenade",
"weapon_xm1014",
"weapon_c4",
"weapon_mac10",
"weapon_aug",
"weapon_smokegrenade",
"weapon_elite",
"weapon_fiveseven",
"weapon_ump45",
"weapon_sg550",
"weapon_galil",
"weapon_famas",
"weapon_usp",
"weapon_glock18",
"weapon_awp",
"weapon_mp5navy",
"weapon_m249",
"weapon_m3",
"weapon_m4a1",
"weapon_tmp",
"weapon_g3sg1",
"weapon_flashbang",
"weapon_deagle",
"weapon_sg552",
"weapon_ak47",
"weapon_knife",
"weapon_p90",
"item_kevlar",
"item_assaultsuit",
""
}
new const ITEM_MODEL_AMMO[] = "models/w_chainammo.mdl"
new const ITEM_MODEL_MEDKIT[] = "models/w_medkit.mdl"
new const SND_GETAMMO[] = "items/9mmclip1.wav"
new const SND_GETMEDKIT[] = "items/smallmedkit1.wav"
new const Float:ITEM_HULL_MIN[3] = {-1.0, -1.0, 0.0}
new const Float:ITEM_HULL_MAX[3] = {1.0, 1.0, 10.0}
new cvar_itempercent;
new cvar_weaponstay;
new cvar_medkit_give;
new g_iMaxPlayers;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_touch("ctf_item", "player", "item_touch")
RegisterHam(Ham_Killed, "player", "player_killed", 1)
cvar_itempercent = register_cvar("amx_itempercent", "30")
cvar_weaponstay = register_cvar("amx_weaponstay", "30")
cvar_medkit_give = register_cvar("amx_medkithp", "25")
g_iMaxPlayers = get_maxplayers()
}
public plugin_precache()
{
precache_model(ITEM_MODEL_AMMO)
precache_model(ITEM_MODEL_MEDKIT)
precache_sound(SND_GETAMMO)
precache_sound(SND_GETMEDKIT)
}
public player_killed(id, killer)
{
player_spawnItem(id)
}
public player_spawnItem(id)
{
if(random_num(1, 100) > get_pcvar_float(cvar_itempercent))
return
new ent = create_entity("info_target");
if(!ent)
return
new Float:origin[3];
entity_get_vector(id, EV_VEC_origin, origin);
new iType = random_num(0, 1)
entity_set_string(ent ,EV_SZ_classname, "ctf_item");
entity_set_edict(ent ,EV_ENT_owner, id);
entity_set_int(ent, EV_INT_movetype, MOVETYPE_TOSS);
entity_set_origin(ent, origin);
entity_set_int(ent, EV_INT_solid, SOLID_BBOX);
switch(iType)
{
case 0: entity_set_model(ent, ITEM_MODEL_AMMO)
case 1: entity_set_model(ent, ITEM_MODEL_MEDKIT)
}
entity_set_size(ent, ITEM_HULL_MIN, ITEM_HULL_MAX)
entity_set_int(ent, EV_INT_iuser2, iType)
drop_to_floor(ent);
remove_task(ent)
set_task(get_pcvar_float(cvar_weaponstay), "weapon_startFade", ent)
}
public weapon_startFade(ent)
{
if(!is_valid_ent(ent))
return
new szClass[32]
entity_get_string(ent, EV_SZ_classname, szClass, charsmax(szClass))
if(!equal(szClass, "weaponbox") && !equal(szClass, "ctf_item"))
return
entity_set_int(ent, EV_INT_movetype, MOVETYPE_FLY)
entity_set_int(ent, EV_INT_rendermode, kRenderTransAlpha)
entity_set_int(ent, EV_INT_renderfx, kRenderFxGlowShell)
entity_set_float(ent, EV_FL_renderamt, 255.0)
entity_set_vector(ent, EV_VEC_rendercolor, Float:{255.0, 255.0, 0.0})
entity_set_vector(ent, EV_VEC_velocity, Float:{0.0, 0.0, 20.0})
weapon_fadeOut(ent, 255.0)
}
public weapon_fadeOut(ent, Float:fStart)
{
if(!is_valid_ent(ent))
{
remove_task(ent)
return
}
static Float:fFadeAmount[4096]
if(fStart)
{
remove_task(ent)
fFadeAmount[ent] = fStart
}
fFadeAmount[ent] -= 25.5
if(fFadeAmount[ent] > 0.0)
{
entity_set_float(ent, EV_FL_renderamt, fFadeAmount[ent])
set_task(0.1, "weapon_fadeOut", ent)
}
else
remove_entity(ent)
}
public item_touch(ent, id)
{
if(is_user_alive(id) && is_valid_ent(ent) && entity_get_int(ent, EV_INT_flags) & FL_ONGROUND)
{
new iType = entity_get_int(ent, EV_INT_iuser2)
switch(iType)
{
case 0:
{
if(!player_getAmmo(id))
return PLUGIN_HANDLED
client_print(id, print_center, "Podniosles ammo pack")
emit_sound(id, CHAN_ITEM, SND_GETAMMO, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
}
case 1:
{
new iHealth = get_user_health(id)
if(iHealth >= 150)
return PLUGIN_HANDLED
new givehp = get_pcvar_num(cvar_medkit_give)
new new_heath = (iHealth+givehp<150)? iHealth+givehp: 150;
set_user_health(id, new_heath);
client_print(id, print_center, "Podniosles apteczke dostales +%d HP", givehp)
emit_sound(id, CHAN_ITEM, SND_GETMEDKIT, VOL_NORM, ATTN_NORM, 0, 110)
}
}
remove_task(ent)
remove_entity(ent)
}
return PLUGIN_CONTINUE
}
bool:player_getAmmo(id)
{
if(!is_user_alive(id))
return false
new iWeapons
new iWeaponList[32]
new bool:bGotAmmo = false
get_user_weapons(id, iWeaponList, iWeapons)
for(new iAmmo, iClip, ent, w, i = 0; i < iWeapons; i++)
{
w = iWeaponList[i]
if(maxAmmo[w])
{
ent = find_ent_by_owner(g_iMaxPlayers, g_szWeaponEntity[w], id)
iAmmo = cs_get_user_bpammo(id, w)
iClip = (ent ? cs_get_weapon_ammo(ent) : 0)
if((iAmmo + iClip) < (maxAmmo[w] + maxClip[w]))
{
cs_set_user_bpammo(id, w, maxAmmo[w] + (maxClip[w] - iClip))
bGotAmmo = true
}
}
}
return bGotAmmo
}