From 386dd3aebb149334e8215bf73ba452869a39f323 Mon Sep 17 00:00:00 2001 From: koolaid Date: Tue, 7 Nov 2023 12:58:06 -0500 Subject: [PATCH] Upload files to "lua/weapons" --- lua/weapons/koolaids_poo_blaster.lua | 132 +++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 lua/weapons/koolaids_poo_blaster.lua diff --git a/lua/weapons/koolaids_poo_blaster.lua b/lua/weapons/koolaids_poo_blaster.lua new file mode 100644 index 0000000..c9b16ea --- /dev/null +++ b/lua/weapons/koolaids_poo_blaster.lua @@ -0,0 +1,132 @@ +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.ClipSize = -1 +SWEP.Primary.DefaultClip = -1 +SWEP.Primary.Automatic = true +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/Combine_Helicopter/helicopter_bomb01.mdl","models/props_interiors/pot01a.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() + 0.5 ) + 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() + 0.1 ) + self:EmitSound( self.Secondary.Sound ) + self:ThrowChair( "models/weapons/w_bugbait.mdl" ) +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() + local pos = aimvec * 32 -- This creates a new vector object + pos:Add( owner:EyePos() ) -- This translates the local aimvector to world coordinates + + -- Set the position to the player's eye position plus 16 units forward. + ent:SetPos( pos ) + + -- 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 + -- 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( 1000 ) -- Add a random vector with elements [-10, 10) + 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() + 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 \ No newline at end of file