Inventory Swep

I’m attempting to make a swep to access the “DerpInv” addon.

I have it set up so it runs the command on right click, but it runs the command 2-5 times on 1 click.



function SWEP:Initialize()
	self:SetWeaponHoldType("normal")
end

function SWEP:Deploy()
	if SERVER then
		self.Owner:DrawViewModel(false)
		self.Owner:DrawWorldModel(false)
	end
end

function SWEP:PrimaryAttack()
        RunConsoleCommand("");
end

function SWEP:SecondaryAttack()
	if CLIENT then
		RunConsoleCommand("drp_showinv");
	end
end


I looked up a wait command for lua but nothing works. I can’t code in lua myself but i can understand it. I learned a little bit of C#, C++ and Python but just the minimum basics.
Any way to make it so it only does it once a click?

What are the firing settings for the SWEP? You haven’t defined any firing delay, I’m guessing that the SWEP is firing fully automatic which may cause SecondaryAttack() to be called multiple times in the time it takes to right click.

Try adding these two lines to the top of the script:
[lua]
SWEP.Secondary.Delay = 0.5
SWEP.Secondary.Automatic = false
[/lua]


if SERVER then
	AddCSLuaFile("shared.lua")
end

if CLIENT then
	SWEP.PrintName = "Inventory"
	SWEP.Slot = 1
	SWEP.SlotPos = 3
	SWEP.DrawAmmo = false
	SWEP.DrawCrosshair = false
end

SWEP.Author = "Nick Vascuas"
SWEP.Instructions = "Click to access inventory."
SWEP.Contact = ""
SWEP.Purpose = ""

SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix	 = "rpg"

SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.Sound = ""
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""

function SWEP:Initialize()
	self:SetWeaponHoldType("normal")
end

function SWEP:Deploy()
	if SERVER then
		self.Owner:DrawViewModel(false)
		self.Owner:DrawWorldModel(false)
	end
end

function SWEP:PrimaryAttack()
        RunConsoleCommand("");
end

function SWEP:SecondaryAttack()
	if CLIENT then
		RunConsoleCommand("drp_showinv");
	end
end


It still opens 2-5 times.

Anything else to try?

When I replaced the bottom two functions with these;
[lua]
function SWEP:PrimaryAttack()
Msg(“primary test”)
end

function SWEP:SecondaryAttack()
if CLIENT then
Msg(“secondary test”)
end
end
[/lua]
I confirmed that when I right clicked, “secondary test” was only printed once on the client.

I would therefore suggest that the problem may lie in your command.

[lua]
if SERVER then
AddCSLuaFile(“shared.lua”)
end

if CLIENT then
SWEP.PrintName = “Inventory”
SWEP.Slot = 1
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end

SWEP.Author = “Nick Vascuas”
SWEP.Instructions = “Click to access inventory.”
SWEP.Contact = “”
SWEP.Purpose = “”

SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = “rpg”

SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.Sound = “”
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “”

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “”

function SWEP:Initialize()
self:SetWeaponHoldType(“normal”)
end

function SWEP:Deploy()
if SERVER then
self.Owner:DrawViewModel(false)
self.Owner:DrawWorldModel(false)
end
end

function SWEP:PrimaryAttack()
RunConsoleCommand("");
end

function SWEP:SecondaryAttack()
self:SetNextSecondaryFire(CurTime()+0.5)
if CLIENT then
RunConsoleCommand(“drp_showinv”);
end
end
[/lua]

Solution is here http://www.facepunch.com/threads/1155158

I see. How would i put this into my script? I don’t know where it would go.

Nevermind i got it.