Stungun SWEP

  • Thread starter Thread starter UberSamji
  • Start date Start date
U

UberSamji

Guest
:thumbs: Hi, everyone.

I've been playing around with Lua scripting in Gmod 10 and have created a pretty rudamentary stungun.

Here is a snippet of the script for it (shared.lua) for primary attack.


Code:
/*------------------------------------------------------------------
            PrimaryAttack (stun target)
------------------------------------------------------------------*/
function SWEP:PrimaryAttack()

    // set firing alignment
    local tr = self.Owner:GetEyeTrace()
    
    // set firing effect for contact with a target
    local effectdata = EffectData()
        effectdata:SetOrigin( tr.HitPos )
        effectdata:SetNormal( tr.HitNormal )
        effectdata:SetMagnitude( 2 )
        effectdata:SetScale( 1 )
        effectdata:SetRadius( 2 )
    util.Effect ( "StunstickImpact", effectdata )
    
    // show fire effect
    self.BaseClass.ShootEffects( self )
    
    // play fire sound
    self.Weapon:EmitSound("Weapon.")
    
    // fire stun charge (damage, bullet, aimcone)
    self.Weapon:ShootBullet(-1, 0, 0.1)
    
end

I have two questions:

(1) Is it possible to determine if the gun is pointing at an NPC and therefore carryout the effect of the stun stick or determine the gun is not being fired at an NPC and so do a different effect such as sparks?

(2) Is it possible to knock an NPC over when this gun is fired at them and any pointers on how to achieve this?
I just want them to be knocked to the ground / maybe change facial expression to a shocked look.

Any help greatly appreciated. Thanks in advance.
 
NPCs can't be knocked over and get up again - the version of Havok that does that came out after HL2's release.
 
Hmmm... never mind. Thanks for the prompt reply.
Is there maybe something else I could make the NPC do such as recoil or shield their face when they are hit?
Thanks again.
 
Back
Top