bad argument #1 to 'KeyDown' (number expected, got string)

Hi all,

Currently I’m porting a old gmod 12 base I worked on into gmod 13…
So far the guns show up in the list, fixed the HUD and it deploys the weapon fine. However when I try to fire it nothing happens exept this error shows up in console as seen below:

[ERROR] addons/gunz/lua/weapons/my_base/shared.lua:567: bad argument #1 to ‘KeyDown’ (number expected, got string)

  1. KeyDown - [C]:-1
  2. CalculateModifiers - addons/gunz/lua/weapons/my_base/shared.lua:567
    3. BaseAttack - addons/gunz/lua/weapons/my_base/shared.lua:455
    4. FireFunction - addons/gunz/lua/weapons/my_base/shared.lua:130
    5. unknown - addons/gunz/lua/weapons/my_base/shared.lua:711

This is the function
function SWEP:CalculateModifiers(run,crouch,jump,iron)

local modifier = 1

if self.Owner:KeyDown("IN_FORWARD", "IN_BACK", "IN_MOVELEFT", "IN_MOVERIGHT") then
	modifier = modifier*run

this is line 567
[lua] if self.Owner:KeyDown(“IN_FORWARD”, “IN_BACK”, “IN_MOVELEFT”, “IN_MOVERIGHT”) then [/lua]

this is line 455
[lua] modifier = self:CalculateModifiers(self.RunModifier,self.CrouchModifier,self.JumpModifier,self.IronSightModifier) [/lua]

this is line 130
[lua] self:BaseAttack() [/lua] —> from [lua] SWEP.FireModes.Auto = {}
SWEP.FireModes.Auto.FireFunction = function(self)


end [/lua]

and this is line 711
[lua] self:FireFunction() [/lua]

which is from this fucntion : [lua] function SWEP:PrimaryAttack()

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

-- Fire function is defined under SWEP:SetFireMode()


Does anyone have a clue how to fix all of these to be compatible with gmod 13? I have no idea how lua works with gmod 13

Thanks in advance and sorry for bad English

IN_FORWARD not “IN_FORWARD” (remove the quotes).

Thank you so much, the base works now, but it still has some small issues

[ERROR] addons/gunz/lua/weapons/my_base/shared.lua:667: attempt to call method ‘DrawViewModel’ (a nil value)

  1. SetScope - addons/gunz/lua/weapons/my_base/shared.lua:667
  2. ResetVars - addons/gunz/lua/weapons/my_base/shared.lua:413
    3. unknown - addons/gunz/lua/weapons/my_base/shared.lua:379
    4. Give - [C]:-1
    5. unknown - gamemodes/sandbox/gamemode/commands.lua:690
    6. unknown - lua/includes/modules/concommand.lua:69

this is line 667: [lua] player:DrawViewModel(true) [/lua]

which is from this function: [lua]function SWEP:SetScope(b,player)

if CLIENT or (not player) or player:IsNPC() then return end

local PlaySound = b~= self.Weapon:GetNetworkedBool("Scope", not b) -- Only play zoom sounds when chaning in/out of scope mode
self.CurScopeZoom = 1 -- Just in case...

if b then 
	if PlaySound then
	if PlaySound then

-- Send the scope state to the client, so it can adjust the player's fov/HUD accordingly
self.Weapon:SetNetworkedBool("Scope", b) 

end [/lua]

Also, burst fire function seem act like semi auto only and gives this error:
[ERROR] addons/gunz/lua/weapons/my_base/shared.lua:437: attempt to index local ‘self’ (a nil value)

  1. unknown - addons/gunz/lua/weapons/my_base/shared.lua:437

Timer Failed! [Simple][@addons/gunz/lua/weapons/my_base/shared.lua (line 171)]

this is line 437
[lua] if not self:CanFire(self.Weapon:Clip1()) then return end [/lua]

which is from this function:
[lua] function SWEP:BaseAttack()

if not self:CanFire(self.Weapon:Clip1()) then return end

-- Calculate recover (cool down) scale
local fCurTime = CurTime()
local DeltaTime = fCurTime - self.LastAttack
local RecoverScale = (1 - DeltaTime/self.RecoverTime)
self.LastAttack = fCurTime

-- Apply cool-down to spread, spray, and recoil
self.CurrentSpread = math.Clamp(self.CurrentSpread*RecoverScale, self.MinSpread, self.MaxSpread)
self.CurrentRecoil = math.Clamp(self.CurrentRecoil*RecoverScale, self.MinRecoil, self.MaxRecoil)
self.CurrentSpray = math.Clamp(self.CurrentSpray*RecoverScale, self.MinSpray, self.MaxSpray)
self.SprayVec = self.SprayVec*((self.CurrentSpray - self.MinSpray)/(self.MaxSpray - self.MinSpray))

-- Calculate modifiers/take ammo
local modifier = 1
if not self.OwnerIsNPC then -- NPCs don't get modifiers

	modifier = self:CalculateModifiers(self.RunModifier,self.CrouchModifier,self.JumpModifier,self.IronSightModifier)
	self:TakePrimaryAmmo(1) -- NPCs get infinate ammo, as they don't know how to reload
local NewSpray 		= self.CurrentSpray*modifier

-- Fire the bullets
self:RGShootBullet(	self.Primary.Damage, 

-- Apply recoil and spray

-- Update spread, spray, and recoil
self.CurrentRecoil 	= math.Clamp(self.CurrentRecoil + self.DeltaRecoil, self.MinRecoil, self.MaxRecoil)
self.CurrentSpread 	= math.Clamp(self.CurrentSpread + self.DeltaSpread, self.MinSpread, self.MaxSpread)
self.CurrentSpray 	= math.Clamp(self.CurrentSpray + self.DeltaSpray, self.MinSpray, self.MaxSpray)

local DeltaSprayVec = VectorRand()*0.02 -- Change in spray vector
self.SprayVec = self.SprayVec + DeltaSprayVec + self.LastDeltaSprayVec -- This "smooths out" the motion of the spray vector
self.LastDeltaSprayVec = DeltaSprayVec

-- Shoot Effects

end [/lua]

and this is line 171:
[lua] timer.Simple(self.BurstDelay, self.BaseAttack, self) [/lua]

EDIT This may appear stupid as %@#^ but i dont have time to sort everything out, So if you think this is easy to solve feel free to reply instead of leaving a “dumb” tag :slight_smile:

The method “DrawViewModel” does not exist and timers don’t accept parameters in GMod 13.

DrawViewModel exist, but only on server I think.

nothing in the doc file describes what I should replace Drawviemodel and timer line with to fill the same function in gmod 13… Any ideas?

Or does it?, I suck hard with gmod 13 tbh

I meant it in the sense that his error complains that the method doesn’t exist, not that it doesn’t exist in GMod at all (which I don’t know if it does).

hmm panicx72 tagged us both as “dumb”

Stupid people give stupid ratings, you don’t need to point it out and nor should you post on his profile about his ratings, that’s just even more stupid.

Alright lets forget about that, back to whats this topic really about

EDIT: This thread is now closed, People who know this code or think they do rather leave a “dumb” rating with no Replies to my questions AKA this forum is useless.