Update lua/weapons/koolaids_poo_blaster.lua

main
koolaid 2023-11-07 14:12:42 -05:00
parent 86c75fc752
commit 72a1c5fb54
1 changed files with 15 additions and 22 deletions

View File

@ -48,12 +48,10 @@ SWEP.ViewModelFOV = 50
SWEP.ViewModel = "models/weapons/c_rpg.mdl"
SWEP.WorldModel = "models/weapons/w_bugbait.mdl"
local mdls = {"models/props_docks/channelmarker_gib01.mdl","models/props_c17/doll01.mdl","models/props_junk/watermelon01.mdl"}
-- Called when the left mouse button is pressed
function SWEP:PrimaryAttack()
-- This weapon is 'automatic'. This function call below defines
-- the rate of fire. Here we set it to shoot every 0.5 seconds.
self:SetNextPrimaryFire( CurTime() )
self:SetNextPrimaryFire( CurTime() + 0.5 )
self:EmitSound( self.Primary.Sound )
-- Call 'ThrowChair' on self with this model
self:ThrowChair( mdls[math.random(1,table.Count(mdls))] )
@ -63,11 +61,18 @@ end
function SWEP:SecondaryAttack()
-- Though the secondary fire isn't automatic
-- players shouldn't be able to fire too fast
self:SetNextSecondaryFire( CurTime() )
self:SetNextSecondaryFire( CurTime() + 0.1 )
self:EmitSound( self.Secondary.Sound )
self:ThrowChair( "models/weapons/w_bugbait.mdl" )
for i=1,10 do
self:ThrowChair( "models/weapons/w_bugbait.mdl" )
end
end
function SWEP:blast(mdl,bool)
-- A custom function we added. When you call this the player will fire a chair!
function SWEP:ThrowChair( model_file )
local owner = self:GetOwner()
-- Make sure the weapon is being held before trying to throw a chair
if ( not owner:IsValid() ) then return end
-- Play the shoot sound we precached earlier!
@ -83,8 +88,8 @@ function SWEP:blast(mdl,bool)
if ( not ent:IsValid() ) then return end
-- Set the entity's model to the passed in model
ent:SetModel( mdl )
ent:SetMass(40)
ent:SetModel( model_file )
-- This is the same as owner:EyePos() + (self:GetOwner():GetAimVector() * 16)
-- but the vector methods prevent duplicitous objects from being created
-- which is faster and more memory efficient
@ -105,13 +110,12 @@ function SWEP:blast(mdl,bool)
-- If it isn't then we'll remove the entity.
local phys = ent:GetPhysicsObject()
if ( not phys:IsValid() ) then ent:Remove() return end
phys:SetMaterial("flesh")
-- Now we apply the force - so the chair actually throws instead
-- of just falling to the ground. You can play with this value here
-- to adjust how fast we throw it.
-- Now that this is the last use of the aimvector vector we created,
-- we can directly modify it instead of creating another copy
if bool then
if model_file == "models/weapons/w_bugbait.mdl" then
aimvec:Mul( -1000 ) -- Add a random vector with elements [-10, 10)
else
aimvec:Mul( 1000 )
@ -125,21 +129,10 @@ function SWEP:blast(mdl,bool)
undo.AddEntity( ent )
undo.SetPlayer( owner )
undo.Finish()
--ent:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
ent:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
ent:SetMaterial("models/props_pipes/GutterMetal01a")
-- A lot of items can clutter the workspace.
-- To fix this we add a 10 second delay to remove the chair after it was spawned.
-- ent:IsValid() checks if the item still exists before removing it, eliminating errors.
timer.Simple( 3, function() if ent and ent:IsValid() then ent:Remove() end end )
end
-- A custom function we added. When you call this the player will fire a chair!
function SWEP:ThrowChair( model_file )
local owner = self:GetOwner()
if model_file == "models/weapons/w_bugbait.mdl" then
for i=1,10 do
self:blast("models/weapons/w_bugbait.mdl",true)
end
else
self:blast(model_file,false)
end
end