Alright I tried todo something. It will for sure give you the idea what I have done or make it better since I just used natives from all modules. Not that it is bad, just use the right natives and it is fine.
In that code I basically removed the c4 drop from a player and c4 drop by dieing. It creates an entity with the c4 model and hooks the touch and gives the c4 to that player.
Keep in mind, that I have added a code that the owner of the last thrower of the c4 can't pickup it anymore, since he would pick it right up if he drops it.
PHP Code:
#include <amxmodx>
#include <engine>
#include <cstrike>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "C4 Drop"
#define VERSION "1.0"
#define AUTHOR "AMXX Community"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Killed, "player", "Ham_CBasePlayer_Killed_Pre", 0)
register_touch("weapon_c4_custom", "player", "TouchBomb")
register_clcmd("drop", "DropBomb")
}
public Ham_CBasePlayer_Killed_Pre(iVictim)
{
if(user_has_weapon(iVictim, CSW_C4))
{
new Float:origin[3]
pev(iVictim,pev_origin,origin)
ham_strip_c4(iVictim, "weapon_c4")
create_c4(iVictim, origin)
}
}
public DropBomb(id)
{
if(is_user_alive(id) && get_user_weapon(id) == CSW_C4)
{
new Float:iOrigin[3]
pev(id, pev_origin, iOrigin)
ham_strip_c4(id, "weapon_c4")
create_c4(id, iOrigin)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
create_c4(id, Float:iOrigin[3])
{
new C4 = create_entity("func_wall")
entity_set_string(C4, EV_SZ_classname, "weapon_c4_custom")
entity_set_model(C4, "models/w_backpack.mdl")
entity_set_int(C4, EV_INT_solid, SOLID_TRIGGER)
entity_set_size(C4, Float:{-2.0,-2.0,-2.0}, Float:{2.0,2.0,2.0})
entity_set_edict(C4, EV_ENT_owner, id)
entity_set_origin(C4, iOrigin)
drop_to_floor(C4)
}
public TouchBomb(C4, id)
{
new owner = entity_get_edict(C4, EV_ENT_owner)
if(owner == id)
return
give_item(id, "weapon_c4")
remove_entity(C4)
}
ham_strip_c4(id,weapon[])
{
new wId = get_weaponid(weapon);
if(!wId) return 0;
new wEnt;
while((wEnt = engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
if(!wEnt) return 0;
if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
ExecuteHamB(Ham_Item_Kill,wEnt);
set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));
cs_set_user_plant(id,0,0);
cs_set_user_bpammo(id,CSW_C4,0);
return 1;
}
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.