I want this plugin to give the player the ak47 and ammo instead of health
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>
#include <fakemeta>
#include <xs>
#include <cs_player_models_api>
#define PLUGIN "Medkit Drop"
#define VERSION "1.0"
#define AUTHOR "nobody"
new const g_medkit_name[] = "Medkit";
new g_medkits, HamHook:FW_TRACEATTACK_FUNC_HC_POST, HamHook:FW_KILLED_FUNC_HC_POST, medkit_gibs_mdl_index;
new MEDKIT_BREAK_SND[64] = "debris/metal5.wav", MEDKIT_W_MDL[64] = "models/w_medkit.mdl"
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /seet", "drop_medkit")
}
public plugin_precache()
{
precache_model(MEDKIT_W_MDL)
precache_sound(MEDKIT_BREAK_SND)
precache_sound("items/medshot4.wav")
precache_sound("items/medshotno1.wav")
precache_sound("items/medcharge4.wav")
}
public drop_medkit(id)
{
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "func_healthcharger"));
if(!ent) return;
new Float:fOrigin[3], Float:fOrigin2[3], Float:fVelocity[3];
velocity_by_aim(id, 250, fVelocity)
pev(id, pev_origin, fOrigin)
pev(id, pev_view_ofs, fOrigin2)
xs_vec_add(fOrigin, fOrigin2, fOrigin)
engfunc(EngFunc_SetOrigin, ent, fOrigin);
engfunc(EngFunc_SetModel, ent, MEDKIT_W_MDL);
//set_pev(ent, pev_spawnflags, SF_NORESPAWN);
dllfunc(DLLFunc_Spawn, ent);
engfunc(EngFunc_SetSize, ent, Float:{-5.0,-5.0,-5.0}, Float:{5.0,5.0,5.0});
set_pev(ent, pev_velocity, fVelocity);
fVelocity[0] = 0.0; fVelocity[2] = 0.0; fVelocity[1] = !random(1) ? -360.0:360.0;
set_pev(ent, pev_avelocity, fVelocity);
set_pev(ent, pev_friction, 1.4);
set_pev(ent, pev_globalname, g_medkit_name);
set_pev(ent, pev_owner, id);
set_pev(ent, pev_takedamage, DAMAGE_YES);
set_pev(ent, pev_health, 100.0);
set_pev(ent, pev_dmg_take, 25.0)
set_pev(ent, pev_solid, SOLID_BBOX);
set_pev(ent, pev_movetype, MOVETYPE_BOUNCE);
if(g_medkits == 1)
{
if(!FW_TRACEATTACK_FUNC_HC_POST)
{
DisableHamForward(FW_TRACEATTACK_FUNC_HC_POST = RegisterHam(Ham_TraceAttack, "func_healthcharger", "fw_tattack_func_hc_post", 1));
DisableHamForward(FW_KILLED_FUNC_HC_POST = RegisterHam(Ham_Killed, "func_healthcharger", "fw_killed_func_hg_pre"));
}
EnableHamForward(FW_TRACEATTACK_FUNC_HC_POST);
EnableHamForward(FW_KILLED_FUNC_HC_POST);
}
set_task(1.2, "reset_velocity", ent);
}
public fw_killed_func_hg_pre(victim, attacker, shouldgib)
{
new sTargetname[16];
pev(victim, pev_globalname, sTargetname, charsmax(sTargetname))
if(!equal(sTargetname, g_medkit_name)) return HAM_IGNORED;
new Float:fOrigin[3];
pev(victim, pev_origin, fOrigin)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_BREAKMODEL);
engfunc(EngFunc_WriteCoord, fOrigin[0]);
engfunc(EngFunc_WriteCoord, fOrigin[1]);
engfunc(EngFunc_WriteCoord, fOrigin[2] + 25.0);
write_coord(16); // size x
write_coord(16); // size y
write_coord(16); // size z
write_coord(random_num(-50,50)); // velocity x
write_coord(random_num(-50,50)); // velocity y
write_coord(25); // velocity z
write_byte(10); // random velocity
write_short(medkit_gibs_mdl_index); // model index that you want to break
write_byte(10); // count
write_byte(25); // life
write_byte(0x02); // flags
message_end();
emit_sound(victim, CHAN_BODY, MEDKIT_BREAK_SND, VOL_NORM, ATTN_NORM, 0, PITCH_HIGH);
set_pev(victim, pev_flags, FL_KILLME);
dllfunc(DLLFunc_Think, victim);
return HAM_IGNORED;
}
public fw_tattack_func_hc_post(ent, attacker, Float:damage, Float:direction[3], traceresult, damagebits)
{
static sTargetname[16];
pev(ent, pev_globalname, sTargetname, charsmax(sTargetname))
if(!equal(sTargetname, g_medkit_name)) return HAM_IGNORED;
if(pev(ent, pev_takedamage) == DAMAGE_YES)
{
static Float:fEnd[3];
get_tr2(traceresult, TR_vecEndPos, fEnd)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_GUNSHOT);
engfunc(EngFunc_WriteCoord, fEnd[0]);
engfunc(EngFunc_WriteCoord, fEnd[1]);
engfunc(EngFunc_WriteCoord, fEnd[2]);
message_end();
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_SPARKS);
engfunc(EngFunc_WriteCoord, fEnd[0]);
engfunc(EngFunc_WriteCoord, fEnd[1]);
engfunc(EngFunc_WriteCoord, fEnd[2]);
message_end();
}
return HAM_IGNORED;
}
public reset_velocity(ent)
{
if(pev_valid(ent))
{
set_pev(ent, pev_velocity, Float:{0.0,0.0,0.0});
set_pev(ent, pev_avelocity, Float:{0.0,0.0,0.0});
set_pev(ent, pev_owner, 33);
}
}