So, I have been messing around with the code for the "chair throwing gun", [URL="http://wiki.garrysmod.com/page/Chair_Throwing_Gun"]found here.[/URL] and I have been messing around with it, and trying to get things to work, but I'm having two problems.
1. I get kicked with the error below, when the prop tries to delete itself.
[IMG]http://i.imgur.com/pXRHhxy.png[/IMG]
2. It plays both ShootSound and TauntSound when I shoot, but only plays TauntSound when I taunt.
Here is my current code for it.
[CODE]
Look below.
[/CODE]
Thanks for reading, I am new to programming, and I am trying to get better by messing around with other bits and pieces of code.
Any help will probably help me out, thanks! :p
Bump?
Also, cleaned up the code a bit.
[CODE]
-- Variables that are used on both client and server
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = "Left click to shoot a turtle. Right click to taunt."
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.UseHands = true
SWEP.ViewModel = "models/weapons/c_toolgun.mdl"
SWEP.WorldModel = "models/weapons/w_toolgun.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.PrintName = "Turtle Shooter"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.UseHands = true
local ShootSound = Sound( "FX_RicochetSound.Ricochet" )
local TauntSound = Sound( "Doll.Squeak" )
--[[---------------------------------------------------------
Reload does nothing
-----------------------------------------------------------]]
function SWEP:Reload()
end
--[[---------------------------------------------------------
Think does nothing
-----------------------------------------------------------]]
function SWEP:Think()
end
--[[---------------------------------------------------------
PrimaryAttack
-----------------------------------------------------------]]
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 7.5 )
self:ThrowChair( "models/props/de_tides/vending_turtle.mdl" )
self:EmitSound( ShootSound )
timer.Simple(2, function()
if ThrowChair:IsValid() then ThrowChair:Remove() end
end)
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 1.5 )
self:ThrowChair( "" )
end
function SWEP:ThrowChair( model_file )
self:EmitSound( TauntSound )
if ( CLIENT ) then return end
local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( model_file )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity * 2225
velocity = velocity + ( VectorRand() * 10 )
phys:ApplyForceCenter( velocity )
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
--[[---------------------------------------------------------
Name: ShouldDropOnDie
Desc: Should this weapon be dropped when its owner dies?
-----------------------------------------------------------]]
function SWEP:ShouldDropOnDie()
return false
end
[/CODE]
[lua]
-- Variables that are used on both client and server
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = "Left click to shoot a turtle. Right click to taunt."
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.UseHands = true
SWEP.ViewModel = "models/weapons/c_toolgun.mdl"
SWEP.WorldModel = "models/weapons/w_toolgun.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.PrintName = "Turtle Shooter"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.UseHands = true
local ShootSound = Sound( "FX_RicochetSound.Ricochet" )
local TauntSound = Sound( "Doll.Squeak" )
--[[---------------------------------------------------------
Reload does nothing
-----------------------------------------------------------]]
function SWEP:Reload()
end
--[[---------------------------------------------------------
Think does nothing
-----------------------------------------------------------]]
function SWEP:Think()
end
--[[---------------------------------------------------------
PrimaryAttack
-----------------------------------------------------------]]
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 7.5 )
self:ThrowChair()
self:EmitSound( ShootSound )
timer.Simple(2, function()
if self.chair:IsValid() then self.chair:Remove() end
end)
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 1.5 )
self:ThrowChair()
end
function SWEP:ThrowChair()
self:EmitSound( TauntSound )
if ( CLIENT ) then return end
local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( "props_c17/FurnitureChair001a.mdl" )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
self.chair = ent
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity * 2225
velocity = velocity + ( VectorRand() * 10 )
phys:ApplyForceCenter( velocity )
cleanup.Add( self.Owner, "props", ent )
undo.Create( "Thrown_Chair" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
--[[---------------------------------------------------------
Name: ShouldDropOnDie
Desc: Should this weapon be dropped when its owner dies?
-----------------------------------------------------------]]
function SWEP:ShouldDropOnDie()
return false
end
[/lua]
I fixed everything I saw wrong with it.
Sorry, you need to Log In to post a reply to this thread.