Hello! I am trying to remove an entity from a player so that they can pick up another of the same type.
The entity is weapon_handgrenade, and it is an aiment assigned to PlayerENT after they touch it (if it is drawn)
Here is what I tried to do:
PHP Code:
public Get_Weaponbits(id)
{
//
new weapons[32], num=0;
get_user_weapons(id, weapons, num)
new weaps = entity_get_int(id, EV_INT_weapons);
client_print(0, print_chat, "%d weapons (EV = %d)"/* Where is %d?"*/, num, weaps//, get_weaponid("weapon_handgrenade")); //returns 0, pointless
new Float:origin[3];
entity_get_vector(id, EV_VEC_origin, origin);
new iEnt = -1;
while( (iEnt = find_ent_in_sphere(iEnt, origin, 0.0)) != 0)
{
//
new classname[33], owner, Float:location[3]
entity_get_string(iEnt, EV_SZ_classname, classname, charsmax(classname))
entity_get_vector(iEnt, EV_VEC_origin, location)
owner = entity_get_edict(iEnt, EV_ENT_owner)
client_print(id, print_chat, "%s %d", classname, owner);
if(equal(classname, "weapon_handgrenade"))
{
client_print(id, print_chat, "TITS!");
new flags = entity_get_int(iEnt, EV_INT_flags)
entity_set_int(iEnt, EV_INT_flags, (flags & FL_KILLME));
call_think(iEnt);
user_has_weapon(id, HLW_HANDGRENADE, 0);
//remove_entity(iEnt); //CRASH
}
//iEnt = find_ent_in_sphere(iEnt, origin, 0.0)
}
}
This is a test command I call to make sure my code works as expected, unfortunately, I have not found a way to actually REMOVE the entity from player, I can get it to not show up in the weaponbits, however the player still has weapon_handgrenade attached to them, and trying to remove_entity on it will simply crash the server. Help?
EDIT: I have made a workaround by adding a global float to keep track of when the entity is touched, setting EF_DRAW on it when its touched, and removing it after it is meant to respawn and using this method to achieve what I want (and superceding the call to prevent the player from gaining the entity)
__________________