Thread: Making a player-dropped AS scripted weapon require +USE to pick up

Results 1 to 3 of 3
  1. #1
    monster_robogrunt Zorbos's Avatar
    Join Date
    May 2015
    Location
    Hammer
    Posts
    115

    Making a player-dropped AS scripted weapon require +USE to pick up

    As the title suggests, I am wondering if it is possible to achieve this..
    I can pretty easily get the weapon to require a +USE when it's FIRST picked up (from its original spawn position) by setting pev.spawnflags = 256 (example below), but what about after a player drops it on the ground? Ideally I'd like to not throw out the entity's owner and if possible, would like to do this with the weapon script itself rather than having a serverside AS plugin dedicated to it. Although if that's what needs to be done, I am ok with it.

    Here's what I'm doing to make it require a use on first pick up
    Code:
    void Spawn()
    {
            Precache();
            g_EntityFuncs.SetModel( self, "models/w_9mmhandgun.mdl" );
            self.m_iDefaultAmmo = 9MM_DEFAULT_AMMO;
    
            self.pev.spawnflags = 256; // Require +use on pickup
    
            self.FallInit();// get ready to fall
    }
    I tried adding a Drop() function into the weapon in hopes that it would be called when the weapon is dropped, but that seemed to have no effect. I think it may actually be DropItem() that I need to use, but that returns a CBasePlayerItem@ and I'm not sure how to handle it. Any suggestions?

  2. #2
    begadang jangan begadang =_= anggara_nothing's Avatar
    Join Date
    Jan 2016
    Location
    Indonesia
    Posts
    155

    Re: Making a player-dropped AS scripted weapon require +USE to pick up

    This is the same thing that i asked a long time ago, even the hook request already exist for a longer time.

    Here's my solution in my edited weapon_deployentity.
    PHP Code:
    const float WDE_DROP_NEXT_THINK 0.1;
    private    
    CScheduledFunctionm_pPostDropItemSched null;
    void Holsterint skiplocal /* = 0 */ )
    {
        
    // etc....
        
        // This is used for handling dropped weapon (weaponbox) - anggaranothing
        
    if( m_pPostDropItemSched !is null )
            
    g_Scheduler.RemoveTimerm_pPostDropItemSched );
        
        @
    m_pPostDropItemSched g_Scheduler.SetTimeout( @this"PostDropItem"WDE_DROP_NEXT_THINK );
    }

    void PostDropItem()
    {
        
    CBaseEntitypWeaponbox g_EntityFuncs.Instanceself.pev.owner );
        
        if( 
    pWeaponbox is null )
            return;
        
        if( !
    pWeaponbox.pev.ClassNameIs"weaponbox" ) )
            return;
        
        
    // Do whatever you like here...


  3. #3
    monster_robogrunt Zorbos's Avatar
    Join Date
    May 2015
    Location
    Hammer
    Posts
    115

    Re: Making a player-dropped AS scripted weapon require +USE to pick up

    Okay so I managed to somewhat get it working by doing the following:

    1. Remove the weaponbox (the actual dropped weapon)
    2. CreateEntity a new weapon of the same type at the player's origin and set it's velocity such that it is thrown outwards from the player
    3. Using a dictionary, set the spawnflags to 1280 (USE only and never respawn)

    But now I have another issue. I want to bypass the short delay where you can't pick up a new weapon of the same type as the one you recently dropped. In other words, you're always allowed to pick up your own dropped weapons immediately, but if you dropped your 9mmhandgun, and then walked over to a 9mmhandgun placed by the mapper, you'd have to wait for a short bit (like 15 seconds or so) before being able to pick it up.

    Is there some way to bypass that? I thought maybe it was related to the owner, so I tried setting the m_hPlayer to the pPlayer that dropped the weapon, but that seemed to have no effect.

    Here's the code:
    Code:
    void Holster( int skiplocal /* = 0 */ )
    {
        self.m_fInReload = false;// cancel any reload in progress.
        m_pPlayer.m_flNextAttack = g_WeaponFuncs.WeaponTimeBase() + 0.5;
    		
        if(m_pPostDropItemSched !is null)
        g_Scheduler.RemoveTimer(m_pPostDropItemSched);
    		
        @m_pPostDropItemSched = g_Scheduler.SetTimeout(@this, "PostDropItem", 0.1, @m_pPlayer);
    }
    
    void PostDropItem(CBasePlayer@ pPlayer)
    {
        CBaseEntity@ pWeaponbox = g_EntityFuncs.Instance(self.pev.owner);
    		
        if(pWeaponbox is null)
            return;
    		
        if(!pWeaponbox.pev.ClassNameIs("weaponbox"))
            return;
    		
        // Remove the 'actual' dropped weapon..
        g_EntityFuncs.Remove(pWeaponbox);
    		
        // Spawn a new weapon and throw it outwards from the player
        string plrOrigin = "" + pPlayer.pev.origin.x + " " +
                                pPlayer.pev.origin.y + " " +
    		            pPlayer.pev.origin.z;
        dictionary@ pValues = {{"spawnflags", "1280"}, {"origin", plrOrigin}};
    		
        CBaseEntity@ pItem = g_EntityFuncs.CreateEntity("weapon_dcaxe", @pValues, true);
        CBasePlayerWeapon@ pNew = cast< CBasePlayerWeapon@ >(pItem);
    		
        pNew.pev.velocity = g_Engine.v_forward * 250 + g_Engine.v_up * 150;
        pNew.m_hPlayer = pPlayer;
    }
    Also, if there's something I could optimize with the code in PostDropItem() (or anywhere really), feel free to let me know


    EDIT: Nevermind! I got it to work! I needed to call CBasePlayer::SetItemPickupTimes(float flTime) with an arg of 0
    Last edited by Zorbos; 25-08-2017 at 08:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •