Le chaise lanceur: The chair gun

Call me “stupid” all you want but I’m incredibly confused as to why this doesn’t work.
I have 2 problems.

  1. I have it set to run out of chairs after it shoots 3 but I realize know that it may not work that way
  2. I have a timer set to delete the chairs shot after 10 seconds.

Original code: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8e50.html

Code now:
[lua]
if SERVER then

//This makes sure clients download the file
AddCSLuaFile ("shared.lua")


SWEP.Weight = 5


SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

elseif CLIENT then // This is where the cl_init.lua stuff goes

SWEP.Slot = 4
SWEP.SlotPos = 1

//Sets drawing the ammuntion levels for this weapon
SWEP.DrawAmmo = true


SWEP.DrawCrosshair = true


language.Add("Undone_Thrown_SWEP_Entity","Undone Thrown SWEP Entity")

end

SWEP.Base = “weapon_tttbase”
//The category that you SWep will be shown in, in the Spawn (Q) Menu
//(This can be anything, GMod will create the categories for you)

SWEP.CanBuy = {ROLE_TRAITOR}
SWEP.InLoadoutFor = nil
SWEP.LimitedStock = true
SWEP.EquipMenuData = {
type = “Launcher”,
desc = “Clearly shoots chairs.”
};
SWEP.Kind = WEAPON_EQUIP1
SWEP.Spawnable = false – Whether regular players can see it
SWEP.AdminSpawnable = true – Whether Admins/Super Admins can see it

SWEP.ViewModel = “models/weapons/v_RPG.mdl” – This is the model used for clients to see in first person.
SWEP.WorldModel = “models/weapons/w_rocket_launcher.mdl” – This is the model shown to all other clients and in third-person.

SWEP.Primary.ClipSize = 10

//This sets the number of rounds in the clip when you first get the gun. Again it can be set to -1.
SWEP.Primary.DefaultClip = 10

//Obvious. Determines whether the primary fire is automatic. This should be true/false
SWEP.Primary.Automatic = false

SWEP.Primary.Ammo = “base_ammo_ttt”

SWEP.Secondary.ClipSize = 10
SWEP.Secondary.DefaultClip = 10
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “base_ammo_ttt”
SWEP.Primary.Delay = 10
SWEP.Secondary.Delay = 10
//When the script loads, the sound ‘‘Metal.SawbladeStick’’ will be precached,
//and a local variable with the sound name created.
local ShootSound = Sound(“Metal.SawbladeStick”)

function SWEP:Reload()
end

function SWEP:Think()
end

function SWEP:throw_attack (model_file)
local tr = self.Owner:GetEyeTrace()

self:EmitSound(ShootSound)
self.BaseClass.ShootEffects(self)

if (!SERVER) then return end

//The next task is to create a physics prop based on the supplied model
local ent = ents.Create("prop_physics")
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 !(phys && IsValid(phys)) then ent:Remove() return end


phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() *  math.pow(tr.HitPos:Length(), 3))


cleanup.Add(self.Owner, "props", ent)

undo.Create ("Thrown_SWEP_Entity")
	undo.AddEntity (ent)
	undo.SetPlayer (self.Owner) 
undo.Finish()

end

function SWEP:PrimaryAttack()
self:throw_attack(“models/props/cs_office/Chair_office.mdl”)
end

function SWEP:SecondaryAttack()
self:throw_attack(“models/props_c17/FurnitureChair001a.mdl”)
end

function ENT:Initialize()
timer.Simple(5, function() self:Remove() end)
end
[/lua]

Just found these errors in the console:
Lua Error: [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_chairswag/shared.lua:148: attempt to index global ‘ENT’ (a nil value) 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_chairswag/shared.lua:148

I also am typing with one hand to hold my foot that feels like toe charlie horses. I’ll fix errors later.

You mean “Le Lance-Chaise”, right ?

And you can’t use

function ENT:Initialize() timer.Simple(5, function() self:Remove() end) end
In a swep code

[lua]
function SWEP:throw_attack (model_file)
local tr = self.Owner:GetEyeTrace()

self:EmitSound(ShootSound)
self.BaseClass.ShootEffects(self)

if (!SERVER) then return end

//The next task is to create a physics prop based on the supplied model
local ent = ents.Create("prop_physics")
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 !(phys && IsValid(phys)) then ent:Remove() return end


phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() *  math.pow(tr.HitPos:Length(), 3))

timer.Simple(2, function()
if ent:IsValid() then ent:Remove() end
end)

end

[/lua]

What about the unlimited ammo?

[lua]
function SWEP:throw_attack (model_file)

self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

if not self:CanPrimaryAttack() then return end

if not worldsnd then
self.Weapon:EmitSound( self.Primary.Sound, self.Primary.SoundLevel )
elseif SERVER then
sound.Play(self.Primary.Sound, self:GetPos(), self.Primary.SoundLevel)
end

self:TakePrimaryAmmo( 1 )

//Get an eye trace. This basically draws an invisible line from
//the players eye. This SWep makes very little use of the trace, except to 
//calculate the amount of force to apply to the object thrown.
local tr = self.Owner:GetEyeTrace()

//Play some noises/effects using the sound we precached earlier
--self:EmitSound(ShootSound)
self.BaseClass.ShootEffects(self)

//We now exit if this function is not running serverside
if (!SERVER) then return end

//The next task is to create a physics prop based on the supplied model
local ent = ents.Create("prop_physics")
ent:SetModel(model_file)

//Set the initial position and angles of the object. This might need some fine tuning;
//but it seems to work for the models I have tried.
ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
ent:SetAngles(self.Owner:EyeAngles())
ent:Spawn()
//Now we need to get the physics object for our entity so we can apply a force to it
local phys = ent:GetPhysicsObject()

//Check if the physics object is valid. If not, remove the entity and stop the function
if !(phys && IsValid(phys)) then ent:Remove() return end

//Time to apply the force. My method for doing this was almost entirely empirical 
//and it seems to work fairly intuitively with chairs.
phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() *  math.pow(tr.HitPos:Length(), 3))

timer.Simple(2, function() 
if ent:IsValid() then ent:Remove() end
end)

local owner = self.Owner
if not IsValid(owner) or owner:IsNPC() or (not owner.ViewPunch) then return end

owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
end
[/lua]

Thanks!