• Problem with my addon! Please help!
    8 replies, posted
Hello Facepunch Community, I had a problem with my Addon. It won't work! Heres the Code: if ( SERVER ) then AddCSLuaFile( "weapon_chairgun.lua" ) end -- Basics SWEP.PrintName = "Chair Launcher" SWEP.Author = "Felix_Dev" SWEP:Instructions = "A Chair Launcher who shoot Chairs" SWEP.Spawnable = true SWEP.AdminOnly = true SWEP.Category = "Other" SWEP.Base = "weapon_cs_base" SWEP.HoldType = "pistol" -- SWEP Ammo and Clip 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's more info SWEP.Weight = 5 SWEP.AutoSwtichTo = false SWEP.AutoSwitchFrom = false SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true -- SWEP's Model SWEP.ViewModel = "models/weapons/v_pistol.mdl" SWEP.WorldModel = "models/weapons/w_pistol.mdl" -- SWEP's Sound local ShootSound = Sound(Metal_SawbladeStick) -- SWEP's Primary Attack function SWEP:PrmiaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 ) self.ThrowChair( "models/props_c17/FurnitureChair001a.mdl" ) end function SWEP:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" ) self:EmitSound( ShootSound ) if ( CLIENT ) then return end local ent = ents.Create( "prop_physics" ) if ( !IsValid( ent ) ) then return end ent:SetModel( "models/props_c17/FurnitureChair001a.mdl" ) ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVecotr() * 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 * 100 velocity = velocity + ( VectorRand() * 10 ) phys:ApplyForceCenter( velocity ) -- Add to Undo List cleanup.Add( self.Owner, "props", ent) undo.Create( "Thrown_Chair" ) undo.AddEntity (ent) undo.SetPlayer( self.Owner ) undo.Finish()
[QUOTE=ToFastForYou;50855434]Hello Facepunch Community, I had a problem with my Addon. It won't work! Heres the Code: [B] - Huge code probably from the WIKI since I've also been looking to know how to throw stuff :v: -[/B] [/QUOTE] Any errors? Also, I would simply place AddCSLuaFile() without the if SERVER stuff.
[QUOTE=AlbertoBC;50855452]Any errors? Also, I would simply place AddCSLuaFile() without the if SERVER stuff.[/QUOTE] I would try it.
After revising the code again, I've found a couple of things that bugged me: First: The function SWEP:PrimaryAttack() is [B]not well spelt[/B] it says "PrmiaryAttack" instead of "PrimaryAttack" Second: There's an function (ThrowChair) which is not properly called. It's called with a dot (self.ThrowChair) instead of two (self:ThrowChair).
[QUOTE=AlbertoBC;50855452]Any errors? Also, I would simply place AddCSLuaFile() without the if SERVER stuff.[/QUOTE] It won't work.
I fixed my last reply, check those things out.
[QUOTE=AlbertoBC;50855541]I fixed my last reply, check those things out.[/QUOTE] Thanks for this reply. But the problem is that it does not appear in the weapons category.
[QUOTE=ToFastForYou;50855946]Thanks for this reply. But the problem is that it does not appear in the weapons category.[/QUOTE] That's actually the first time you mentioned an error. If you want us to help, let us know what are the expected results, and what do you get instead [aka errors]. Also, you might need a shared spawn function in order to get it work. To have the swep appear in the weapons category, there's a chance you need to make sure that you have client, server and shared lua files together.
Sorry, you need to Log In to post a reply to this thread.