135 lines
4.7 KiB
Lua
135 lines
4.7 KiB
Lua
AddCSLuaFile()
|
|
|
|
SWEP.Base = "weapon_base"
|
|
SWEP.PrintName = "poo blaster"
|
|
SWEP.Category = "koolaids poo blaster"
|
|
SWEP.Author = "koolaid"
|
|
SWEP.Instructions = "fard on yer enemies"
|
|
|
|
SWEP.HoldType = "cock"
|
|
SWEP.Slot = 3
|
|
SWEP.SlotPos = 0
|
|
SWEP.Weight = 5
|
|
SWEP.AutoSwitchTo = true
|
|
SWEP.AutoSwitchFrom = false
|
|
|
|
SWEP.Spawnable = true
|
|
SWEP.AdminSpawnable = true
|
|
|
|
SWEP.ViewModelFlip = false
|
|
SWEP.UseHands = false
|
|
SWEP.DrawCrosshair = true
|
|
|
|
SWEP.Primary.Delay = 0.08
|
|
SWEP.Primary.Recoil = 999
|
|
SWEP.Primary.Automatic = false
|
|
SWEP.Primary.Damage = 99999
|
|
SWEP.Primary.Cone = 0.25
|
|
SWEP.Primary.Sound = "pooblaster/fard.mp3"
|
|
SWEP.Primary.Automatic = true
|
|
|
|
SWEP.Primary.ClipSize = -1
|
|
SWEP.Primary.DefaultClip = -1
|
|
SWEP.Primary.Ammo = "none"
|
|
|
|
SWEP.Secondary.ClipSize = -1
|
|
SWEP.Secondary.DefaultClip = -1
|
|
SWEP.Secondary.Automatic = false
|
|
SWEP.Secondary.Ammo = "none"
|
|
|
|
SWEP.Secondary.Delay = 1
|
|
SWEP.Secondary.Sound = "pooblaster/pooblaster.ogg"
|
|
|
|
SWEP.AmmoEnt = "item_rpg_round"
|
|
|
|
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"}
|
|
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() + 0.4 )
|
|
self:EmitSound( self.Primary.Sound )
|
|
-- Call 'ThrowChair' on self with this model
|
|
self:ThrowChair( mdls[math.random(1,table.Count(mdls))] )
|
|
end
|
|
|
|
-- Called when the rightmouse button is pressed
|
|
function SWEP:SecondaryAttack()
|
|
-- Though the secondary fire isn't automatic
|
|
-- players shouldn't be able to fire too fast
|
|
self:SetNextSecondaryFire( CurTime() + 1 )
|
|
self:EmitSound( self.Secondary.Sound )
|
|
for i=1,20 do
|
|
self:ThrowChair( "models/weapons/w_bugbait.mdl" )
|
|
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()
|
|
|
|
-- 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!
|
|
|
|
-- If we're the client then this is as much as we want to do.
|
|
-- We play the sound above on the client due to prediction.
|
|
-- ( if we didn't they would feel a ping delay during multiplayer )
|
|
if ( CLIENT ) then return end
|
|
|
|
-- Create a prop_physics entity
|
|
local ent = ents.Create( "prop_physics" )
|
|
|
|
-- Always make sure that created entities are actually created!
|
|
if ( not ent:IsValid() ) then return end
|
|
|
|
-- Set the entity's model to the passed in model
|
|
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
|
|
-- AimVector is not directly modified as it is used again later in the function
|
|
local aimvec = owner:GetAimVector() -- This creates a new vector object
|
|
local pos = aimvec * 32
|
|
pos:Add( owner:EyePos() )
|
|
-- Set the position to the player's eye position plus 16 units forward.
|
|
ent:SetPos( pos + VectorRand( -10, 10 ))
|
|
|
|
-- Set the angles to the player'e eye angles. Then spawn it.
|
|
ent:SetAngles( owner:EyeAngles() )
|
|
ent:Spawn()
|
|
|
|
-- Now get the physics object. Whenever we get a physics object
|
|
-- we need to test to make sure its valid before using it.
|
|
-- If it isn't then we'll remove the entity.
|
|
local phys = ent:GetPhysicsObject()
|
|
if ( not phys:IsValid() ) then ent:Remove() return end
|
|
phys:SetMass(4)
|
|
-- 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
|
|
aimvec:Mul( 10000 )
|
|
aimvec:Add( VectorRand( -100, 100 ) )
|
|
phys:ApplyForceCenter( aimvec )
|
|
-- Assuming we're playing in Sandbox mode we want to add this
|
|
-- entity to the cleanup and undo lists. This is done like so.
|
|
cleanup.Add( owner, "props", ent )
|
|
|
|
undo.Create( "Blasted Poo" )
|
|
undo.AddEntity( ent )
|
|
undo.SetPlayer( owner )
|
|
undo.Finish()
|
|
if model_file == "models/weapons/w_bugbait.mdl" then
|
|
ent:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
|
|
end
|
|
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 |