Help Not a previous Clockwork developer (Angel)

Status
Not open for further replies.

Angel

she/her/they nonbinary transfem
Joined
Apr 26, 2016
Messages
9,940
Nebulae
8,986
Code:
SWEP.PrintName = "Chair Thrower"
SWEP.Author = "Angel"
SWEP.Instructions = "Left mouse to fire a chair. \n Right mouse to fire chair. \n Reload to fire Melons"

SWEP.Spawnable = true
SWEP.AdminOnly = true


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.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 ShootSound1 = Sound("Metal.SawbladeStick")
local ShootSound2 = Sound("garrysmod/balloon_pop_cute.wav")


function SWEP:PrimaryAttack()

    self:EmitSound( ShootSound1 )

    self.Weapon:SetNextPrimaryFire( 0.5 )

    self:ThrowChair( "models/props/cs_office/Chair_office.mdl" )

end


function SWEP:SecondaryAttack()

    self:EmitSound( ShootSound2 )

    self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )

end


function SWEP:Reload()

    self:ThrowMelon( "models/props_junk/watermelon01.mdl" )

end

function SWEP:ThrowMelon(model_file)


    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("Thrown_Melon")
        undo.AddEntity( ent )
        undo.SetPlayer( self.Owner )
    undo.Finish()

end


function SWEP:ThrowChair(model_file)


    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("Thrown_Chair")
        undo.AddEntity( ent )
        undo.SetPlayer( self.Owner )
    undo.Finish()

end

I want to make the chair throwing gun shoot three chairs a click, instead of a full auto (Mouse 1) and 1 single chair (mouse 2).

Please help.
 
Reactions: List

Ace of Spades

Proton
Joined
Apr 26, 2016
Messages
250
Nebulae
119
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"

Look below at that shit and maybe the code will answer the question for you.
 
Reactions: List

romodomo

Proton
B A N N E D
Joined
Apr 26, 2016
Messages
239
Nebulae
1,298
self.Weapon:SetNextPrimaryFire( 0.5 )

this is based on CurTime() you should change it to self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 ) instead

as for the three chairs a click im thinking you can make your ThrowChair function pass a number variable of how many chairs it should throw, and inside of the function make a for i = 1, (number variable goes here) loop, and inside of that loop, create the chairs

so it would look like this

Code:
function SWEP:ThrowChair(model_file, number)
    if ( CLIENT ) then return end

    for i = 1, number do
        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("Thrown_Chair")
            undo.AddEntity( ent )
            undo.SetPlayer( self.Owner )
        undo.Finish()
    end
end

although im sure the chairs would spawn almost simultaneously, but i think you get the point

then in your primary attack just change self:ThrowChair( "models/props/cs_office/Chair_office.mdl" ) to
self:ThrowChair( "models/props/cs_office/Chair_office.mdl", 3 ) and in the secondary attack
self:ThrowChair( "models/props/cs_office/Chair_office.mdl" , 1)
 
Reactions: List

Angel

she/her/they nonbinary transfem
Joined
Apr 26, 2016
Messages
9,940
Nebulae
8,986
this is based on CurTime() you should change it to self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 ) instead

as for the three chairs a click im thinking you can make your ThrowChair function pass a number variable of how many chairs it should throw, and inside of the function make a for i = 1, (number variable goes here) loop, and inside of that loop, create the chairs

so it would look like this

Code:
function SWEP:ThrowChair(model_file, number)
    if ( CLIENT ) then return end

    for i = 1, number do
        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("Thrown_Chair")
            undo.AddEntity( ent )
            undo.SetPlayer( self.Owner )
        undo.Finish()
    end
end

although im sure the chairs would spawn almost simultaneously, but i think you get the point

then in your primary attack just change self:ThrowChair( "models/props/cs_office/Chair_office.mdl" ) to
self:ThrowChair( "models/props/cs_office/Chair_office.mdl", 3 ) and in the secondary attack
self:ThrowChair( "models/props/cs_office/Chair_office.mdl" , 1)
I might be retarded, but I... uh.

think it's not working :\ maybe I just did it wrong.
 

Angel

she/her/they nonbinary transfem
Joined
Apr 26, 2016
Messages
9,940
Nebulae
8,986
send code
I just fixed it in a different way...

Code:
function SWEP:SecondaryAttack()

   self:EmitSound( ShootSound2 )

   self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )
   self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )
   self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )

end
lol
 

romodomo

Proton
B A N N E D
Joined
Apr 26, 2016
Messages
239
Nebulae
1,298
I just fixed it in a different way...

Code:
function SWEP:SecondaryAttack()

   self:EmitSound( ShootSound2 )

   self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )
   self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )
   self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )

end
lol
thats probably why it doesnt work lol

just use what i sent you, it will probably work, read about for loops in lua if you dont understand what they do
https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index76d2.html
 
Reactions: List

patty

Proton
Joined
Apr 26, 2016
Messages
244
Nebulae
179
thats probably why it doesnt work lol

just use what i sent you, it will probably work, read about for loops in lua if you dont understand what they do
https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index76d2.html
b17f1c4cee.png
 
Reactions: List

Angel

she/her/they nonbinary transfem
Joined
Apr 26, 2016
Messages
9,940
Nebulae
8,986
I've found that the new wiki is fucking shit when it comes to guides.
Really incomplete.

Either way, I got my shit fixed, so ya can lock.

@Elliot
 
Status
Not open for further replies.