AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED]remove (weapon) entity from player (https://forums.alliedmods.net/showthread.php?t=229257)

HLM 11-04-2013 07:11

[SOLVED]remove (weapon) entity from player
 
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(idweaponsnum)
    new 
weaps entity_get_int(idEV_INT_weapons);
    
client_print(0print_chat"%d weapons (EV = %d)"/* Where is %d?"*/numweaps//, get_weaponid("weapon_handgrenade"));    //returns 0, pointless
    
    
new Float:origin[3];
    
entity_get_vector(idEV_VEC_originorigin);
    
    new 
iEnt = -1;
    while( (
iEnt find_ent_in_sphere(iEntorigin0.0)) != 0)
    {
        
//
        
new classname[33], ownerFloat:location[3]
        
entity_get_string(iEntEV_SZ_classnameclassnamecharsmax(classname))
        
entity_get_vector(iEntEV_VEC_originlocation)
        
owner entity_get_edict(iEntEV_ENT_owner)
        
client_print(idprint_chat"%s %d"classnameowner);
        
        if(
equal(classname"weapon_handgrenade"))
        {
            
client_print(idprint_chat"TITS!");
            new 
flags entity_get_int(iEntEV_INT_flags)
            
entity_set_int(iEntEV_INT_flags, (flags FL_KILLME));
            
call_think(iEnt);
            
user_has_weapon(idHLW_HANDGRENADE0);
            
//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)


All times are GMT -4. The time now is 23:22.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.