1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Making Things For Gmod

Discussion in 'Hardware and Software' started by Markoozy, Feb 26, 2018.

  1. Markoozy

    Markoozy Retired Sever Admin

    Joined:
    Dec 8, 2013
    Posts:
    1,901
    Roleplay name:
    Marko Milosevic
    I am following this guide on the Gmod wiki.
    https://wiki.garrysmod.com/page/Chair_Throwing_Gun
    I cannot, for the life of me, figure out how to spawn in the gun after I have finished coding it.

    Also, if anyone is willing to teach / send me a guide on coding shit for Gmod, that'd be great.
     
  2. AngryBaldMan

    AngryBaldMan Active Member

    Joined:
    Jul 31, 2015
    Posts:
    269
    Roleplay name:
    Andrew Harrison
    Code:
    SWEP.Spawnable = true
    SWEP.AdminOnly = true
    SWEP.Category = "Markoozy" -- Isn't needed, by default would be in "Other" category
    If you mean you can't find it in your Q Menu, make sure you have that enabled. As well as it is in the correct directory. Make an Addon in your Addons folder (C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\addons) Make a folder such as "Markoozy's SWEPS" then in there add a folder called "lua" and in there add a folder called "weapons" and drop your SWEP file in there.
     
  3. Markoozy

    Markoozy Retired Sever Admin

    Joined:
    Dec 8, 2013
    Posts:
    1,901
    Roleplay name:
    Marko Milosevic
    What do you mean by this?
    C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\addons\chairlauncher\lua\weapons
    I'm pretty sure I did that right.
     
  4. AngryBaldMan

    AngryBaldMan Active Member

    Joined:
    Jul 31, 2015
    Posts:
    269
    Roleplay name:
    Andrew Harrison
    PM me your code or just drop it in here. Also, make sure you restarted your game after making it.
     
  5. Markoozy

    Markoozy Retired Sever Admin

    Joined:
    Dec 8, 2013
    Posts:
    1,901
    Roleplay name:
    Marko Milosevic
    Code:
    SWEP.PrintName = "Chair Thrower"
    SWEP.Author = "Markoozy"
    SWEP.Instructions = "Left mouse to fire a chair!"
    
    SWEP.Spawnable = true
    SWEP.AdminOnly = true
    
    SWEP.Primary.ClipSize = -1
    SWEP.Primary.DefaultClip = -1
    SWEP.Automatic = true
    SWEP.Primary.Ammo = "none"
    
    SWEP.Secondary.ClipSize = -1
    SWEP.Secondary.DefaultClip = -1
    SWEP.Secondary.Automatic = true
    SWEP.Secondary.Ammo = "none"
    
    SWEP.Weight = 5
    SWEP.AutoSwitchTo = false
    SWEP.AutoSwitchFrom = false
    
    SWEP.Slot = 1
    SWEP.SlotPos = 2
    SWEP.DrawAmmo = false
    SWEP.DrawCrosshair = true
    
    SWEP.ViewModel = "models/weapons/v_pistol.mdl"
    SWEP.WorldModel = "models/weapons/w_pistol.mdl"
    
    local ShootSound = Sound("Metal.SawbladeStick")
    
    
    function SWEP:PrimaryAttack()
    
        self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
        self:ThrowChair("models/props/cs_office/Chair_office.mdl")
    
    end
    
    function SWEP:SecondaryAttack()
    
        self:ThrowChair("models/props_c17/FurnitureChair001a.mdl")
    
    end
    
    function SWEP:ThrowChair(model_file)
    
        self:EmitSound(ShootSound)
    
        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 * 100
        velocity = velocity + (VectorRand() * 10)
        phys:ApplyForceCenter(velocity)
    
        cleanup.Add(self.Owner, "props", ent)
    
        undo.Create("Throw._Chair")
            undo.AddEntity(ent)
            undo.SetPlayer(self.Owner)
        undo.Finish()
    
     
  6. AngryBaldMan

    AngryBaldMan Active Member

    Joined:
    Jul 31, 2015
    Posts:
    269
    Roleplay name:
    Andrew Harrison
    Can you format it with the code tags just go to insert code.
     
  7. Markoozy

    Markoozy Retired Sever Admin

    Joined:
    Dec 8, 2013
    Posts:
    1,901
    Roleplay name:
    Marko Milosevic
    So that's how you do it. Speaking of which, I just realized I forgot an "end" at the end. :/

    Edit: Fixed it. Thanks for the help.

    Edit 2: Am now getting script errors, but I can figure that out on my own. :(
     
    Last edited: Feb 26, 2018
    • Like Like x 1
    • Funny Funny x 1