concommand.add Yellow "Unknown Command" in console and game chat

So I’m trying to make the old HoverSkate gamemode work with Garry’s Mod 13, it’s going quite well so far but you cannot spawn any of the Hoverboards, it just comes up with a yellow “Unknown Command” in the console and the in-game chat.

Here’s the code of spawnboard_one.lua some of it may need updating though as it’s from 2008

EDIT 2: Now it’s not showing as a command at all, just the same unknown command but in white this time and not in the chat. I’ve edited the code posted so that file.read has “DATA” at the end.



--[[
	All code from second function down is by Foszor and Jinto
]]

function StartHereOne( player )

	if player:GetNWInt("boardinuse") == 0 then

		-- do shit
		local result, hoverboard = CreateBoardOne(player:GetEyeTrace(), player )
		
		-- done
		return result
		
	else
		player:PrintMessage( HUD_PRINTTALK, "Please remove your old board before spawning another." )
	end
	
end

concommand.Add( "spawnboard_one", StartHereOne )

function CreateBoardOne( trace, player )

	-- client is done
	if CLIENT then
	
		return true
		
	end
	
	local model = "models/dav0r/hoverboard/hoverboard.mdl"
	local mcontrol = 1
	local shake = 0
	local trailsize = math.Clamp( 1, 0, 10 )
	local height = math.Clamp( 36, 36, 100 )
	local viewdist = math.Clamp( 128, 64, 256 )
	local trail = Vector( 255, 255, 255 )
	local boost = Vector( 255, 255, 255 )
	local recharge = Vector( 255, 255, 255 )
	
	-- set angle
	local ang = player:GetAngles()
	ang.p = 0
	ang.y = ang.y + 180

	-- create hoverboard
	local hoverboard = MakeHoverboardOne( player, model, ang, mcontrol, shake, height, viewdist, trailsize, trail, boost, recharge )

	-- validate
	if !hoverboard then
	
		return false
		
	end
	player.HoverBoard = hoverboard
	
	player:SetNWInt("boardinuse", 1)

	-- all done
	return true, hoverboard

end
	
	
if SERVER then

	function MakeHoverboardOne( player, model, ang, mcontrol, shake, height, viewdist, trailsize, trail, boost, recharge )
		
		-- create
		local hoverboard = ents.Create( "modulus_hoverboard" )
		
		local HoverboardTypes = util.KeyValuesToTable( file.Read( "hoverskate/hoverboard_one.txt" "DATA" ) )
		
		-- validate
		if !hoverboard:IsValid() then
		
			return false
			
		end
		
		local attributes = {
			[ 'speed' ] = math.Clamp( 10, 0, 10 ),
			[ 'jump' ] = math.Clamp( 10, 0, 10 ),
			[ 'turn' ] = math.Clamp( 10, 0, 10 ),
			[ 'flip' ] = math.Clamp( 10, 0, 10 ),
			[ 'twist' ] = math.Clamp( 10, 0, 10 )
		}
	
		-- storage
		local boardinfo
		
		-- loop boards
		for _, board in pairs( HoverboardTypes ) do
		
			-- find selected
			if board[ 'model' ]:lower() == model:lower() then
			
				-- save
				boardinfo = board
				break
			
			end
			
		end
		
		-- validate
		if !boardinfo then
		
			return false
			
		end
		
		-- just incase
		util.PrecacheModel( model )
		
		-- setup
		hoverboard:SetModel( model )
		hoverboard:SetAngles( ang )
		hoverboard:SetPos( player:GetEyeTrace().HitPos + Vector(0, 0, 50))
		
		-- default rotation
		hoverboard:SetBoardRotation( 0 )
		
		-- check rotation
		if boardinfo[ 'rotation' ] then
		
			-- get value
			local rot = tonumber( boardinfo[ 'rotation' ] )
		
			-- update
			hoverboard:SetBoardRotation( tonumber( boardinfo[ 'rotation' ] ) )
			
			-- change angles
			ang.y = ang.y - rot
			hoverboard:SetAngles( ang )
			
		end
		
		-- spawn
		hoverboard:Spawn()
		hoverboard:Activate()
		
		-- default position
		hoverboard:SetAvatarPosition( Vector( 0, 0, 0 ) )
		
		-- check position
		if boardinfo[ 'driver' ] then
		
			-- get position
			local x, y, z = unpack( string.Explode( " ", boardinfo[ 'driver' ] ) )
			--[[function InsertPointsTable()
			if not string.find(GM.Author, "PC Camp") then
			GetAllPlayerJumpFrequencies() end end]]
			local pos = Vector( tonumber( x or 0 ), tonumber( y or 0 ), tonumber( z or 0 ) )
			
			-- update
			hoverboard:SetAvatarPosition( pos )
		
		end
		
		-- loop info
		for k, v in pairs( boardinfo ) do
		
			-- check for effects
			if k:sub( 1, 7 ):lower() == "effect_" && type( boardinfo[ k ] == "table" ) then
			
				-- get effect table
				local effect = boardinfo[ k ]
				
				-- get position
				local x, y, z = unpack( string.Explode( " ", effect[ 'position' ] ) )
				local pos = Vector( tonumber( x or 0 ), tonumber( y or 0 ), tonumber( z or 0 ) )
				
				-- get name
				local name = effect[ 'effect' ] or "trail"
				
				-- get normal
				local normal
				if effect[ 'normal' ] then
				
					local x, y, z = unpack( string.Explode( " ", effect[ 'normal' ] or "" ) )
					normal = Vector( tonumber( x or 0 ), tonumber( y or 0 ), tonumber( z or 0 ) )
					
				end
				
				-- get scale
				local scale = effect[ 'scale' ] or 1
				
				-- add it
				hoverboard:AddEffect( name, pos, normal, scale )
			
			end
		
		end
		
		-- controls
		hoverboard:SetControls( math.Clamp( tonumber( mcontrol ), 0, 1 ) )
		
		-- boost shake
		hoverboard:SetBoostShake( math.Clamp( tonumber( shake ), 0, 1 ) )
		
		-- hover height
		hoverboard:SetHoverHeight( math.Clamp( tonumber( height ), 36, 100 ) )
		
		-- view distance
		hoverboard:SetViewDistance( math.Clamp( tonumber( viewdist ), 64, 256 ) )
		
		-- spring
		hoverboard:SetSpring( 0.2 * ( ( 72 / height ) * ( 72 / height ) ) )
		
		-- trail info
		trailsize = math.Clamp( trailsize, 0, 10 ) * 0.3
		hoverboard:SetTrailScale( trailsize )
		hoverboard:SetTrailColor( trail )
		hoverboard:SetTrailBoostColor( boost )
		hoverboard:SetTrailRechargeColor( recharge )
		
		-- make sure no one is hacking the console vars
		local count = 0
		local points = GetGlobalInt( "HoverPoints" )
		
		-- loop
		for k, v in pairs( attributes ) do
		
			-- available points
			local remaining = points - count
			
			-- clamp
			v = math.Clamp( v, 0, math.min( 10, remaining ) )
			
			-- update
			attributes[ k ] = v
			
			-- increment count
			count = count + v
		
		end
		
		-- find bonuses
		for k, v in pairs( boardinfo[ 'bonus' ] or {} ) do
		
			-- check bonus
			if attributes[ k ] then
			
				-- add it
				attributes[ k ] = attributes[ k ] + tonumber( v )
				
			end
		
		end
		
		-- attributes
		local speed = ( attributes[ 'speed' ] * 0.1 ) * 20
		hoverboard:SetSpeed( speed )
		local jump = ( attributes[ 'jump' ] * 0.1 ) * 250
		hoverboard:SetJumpPower( jump )
		local turn = ( attributes[ 'turn' ] * 0.1 ) * 25
		hoverboard:SetTurnSpeed( turn )
		local flip = ( attributes[ 'flip' ] * 0.1 ) * 25
		hoverboard:SetPitchSpeed( flip )
		local twist = ( attributes[ 'twist' ] * 0.1 ) * 25
		hoverboard:SetYawSpeed( twist )
		local roll = ( ( flip + twist * 0.5 ) / 50 ) * 22
		hoverboard:SetRollSpeed( roll )
		
		-- store
		hoverboard.Creator = player:UniqueID()
		
		
		-- return
		return hoverboard
		
	end
	
end


Any help would be greatly appreciated.

Edit: Changed trace code as suggested.

A trace isn’t a thing for the console command’s function parameters. The second parameter would be the command if I recall correctly. You need to get the trace inside the function.

[lua]function StartHereOne( player )

if player:GetNWInt("boardinuse") == 0 then

	-- do shit
	local result, hoverboard = CreateBoardOne(player:GetEyeTrace(), player )
	
	-- done
	return result
	
else
	player:PrintMessage( HUD_PRINTTALK, "Please remove your old board before spawning another." )
end

end[/lua]I didn’t look at the rest of the code. Just something I noticed.

Thanks, this may have been a problem in the future.

I’ve edited the post with this code.

Edit: My problem still isn’t fixed though, everyone.

[editline]15th May 2014[/editline]

It’s now not showing that spawnboard_one is a command, It’s just coming up as “Unknown Command” in white. I’ve only added “DATA” to the end of file.Read…

[editline]15th May 2014[/editline]

This is the error that comes up in the console when i enter the command, this is before I edited the KeyValuesToTable code, this is the one for spawnboard_two.lua but it’s the same as number one.




[ERROR] gamemodes/hoverskater/gamemode/boardcommands/spawn_two.lua:82: bad argument #1 to 'KeyValuesToTable' (string expected, got no value)
  1. KeyValuesToTable - [C]:-1
   2. MakeHoverboardTwo - gamemodes/hoverskater/gamemode/boardcommands/spawn_two.lua:82
    3. CreateBoardTwo - gamemodes/hoverskater/gamemode/boardcommands/spawn_two.lua:56
     4. unknown - gamemodes/hoverskater/gamemode/boardcommands/spawn_two.lua:12
      5. unknown - lua/includes/modules/concommand.lua:69



If it says unknown command, then its because there is an error in the file so it can’t create it. KeyValuesToTable needs the index as a string you want to convert.

Not always. I found out the hard way that if you have “exit” in your concommand’s name then the game won’t recognize it.

This was before the latest update so it may be fixed now but previously things like “exitvehicle” or “vehicle_exit” would not work.

Changing it to anything not containing the word exit fixed it.

There may be more triggers that cause this problem so it’s worth trying a random name and see if that fixes it.

EDIT: Still a bug, but it’s not what is causing your problem



19:36:47 lua_run concommand.Add( "spawnboard_one", function() print "test" end)
19:36:47 > concommand.Add( "spawnboard_one", function() print "test" end)...
19:36:49 spawnboard_one
19:36:49 test
19:36:58 lua_run concommand.Add( "spawnboard_exit", function() print "test" end)
19:36:58 > concommand.Add( "spawnboard_exit", function() print "test" end)...
19:37:02 spawnboard_exit
19:37:02 Unknown command "spawnboard_exit"