concommand.Add not working or what?

Hello guys.
Some days ago I started to do my first gamemode. I’ve been having this problem since the beginning.
So basicly I made a vgui panel in cl_init.lua and I added a command to run the function for the panel creation.
What I get when I test the gamemode is a “Unknown command”. Anyone got a fix to this? The code is this.

[LUA]
include( “shared.lua” )

function CharacterCreationModelMenu()

local SpawnModel = {}

    SpawnModel[1] = "models/humans/Group01/Male_01.mdl"
    SpawnModel[2] = "models/humans/Group01/Male_02.mdl"
    SpawnModel[3] = "models/humans/Group01/Male_03.mdl"
    SpawnModel[4] = "models/humans/Group01/Male_07.mdl"
    SpawnModel[5] = "models/humans/Group01/Female_01.mdl"
    SpawnModel[6] = "models/humans/Group01/Female_02.mdl"
    SpawnModel[7] = "models/humans/Group01/Female_03.mdl"
    SpawnModel[8] = "models/humans/Group01/Female_03.mdl"

local CharMenuSpawnFrame = vgui.Create( "DFrame" )
local CharMenuSpawnList = vgui.Create( "DPanelList", CharMenuSpawnFrame )

CharMenuSpawnFrame:Center()
CharMenuSpawnFrame:SetSize( 250, 250 )
CharMenuSpawnFrame:SetTitle( "Scegli un modello" )
CharMenuSpawnFrame:ShowCloseButton( false )
CharMenuSpawnFrame:MakePopup()

CharMenuSpawnList:EnableVerticalScrollbar( true )
CharMenuSpawnList:EnableHorizontal( true )
CharMenuSpawnList:SetPadding( 4 )
CharMenuSpawnList:SetPos( 10, 30 )
CharMenuSpawnList:SetSize( 200, 160)

for k, v in pairs(SpawnModel) do
    
	local SpawnIcon = vgui.Create( "SpawnIcon", IconList )
    SpawnIcon:SetModel( v )
    CharMenuSpawnList:AddItem( SpawnIcon )
    SpawnIcon.DoClick = function( SpawnIcon ) 
	    surface.PlaySound( "ui/buttonclickrelease.wav" ) 
		CharacterCreationNameMenu()
		CharMenuSpawnFrame:SetVisible( false )
		
	end
end

end

function CharacterCreationNameMenu()

local CharNameFrame = vgui.Create( “DFrame” )
CharNameFrame:Center()
CharNameFrame:SetSize( 300, 70 )
CharNameFrame:SetTitle( “Digita un nome per il tuo personaggio” )
CharNameFrame:ShowCloseButton( false )
CharNameFrame:MakePopup()

local errortext = “Nome non valido.”
local CharNameText = vgui.Create( “DTextEntry”, CharNameFrame )
CharNameText:SetPos( 20, 25 )
CharNameText:SetTall( 20 )
CharNameText:SetWide( 250 )
CharNameText:SetEnterAllowed( true )
CharNameText.OnEnter = function()

if CharNameText:GetValue() == nil or CharNameText:GetValue() == errortext then
    CharNameText:SetText( errortext )
elseif CharNameText:GetValue() != nil or CharNameText:GetValue() != errortext then
    surface.PlaySound( "ui/buttonclickrelease.wav" ) 
    CharNameFrame:SetVisible( false )
	ply:SetTeam( 1 )
	GM:PlayerSpawn()
end

end
end

concommand.Add( “character_creation_tutorial”, CharacterCreationModelMenu )
[/LUA]

Oh, by the way, my error is yellow (so it should be clientside).

Try using usermessages instead.

Try putting the declaration of CharacterCreationNameMenu() infront of where it’s being called, I’m not sure if Lua does this but I’m guessing that if the function is not declared before where it’s being called, then it errors.

What?

Look, he’s calling the function CharacterCreationNameMenu() before it was declared/made.

He isent calling anything, anywhere.



SpawnIcon.DoClick = function( SpawnIcon ) 
            surface.PlaySound( "ui/buttonclickrelease.wav" ) 
            CharacterCreationNameMenu() -- This right here, it's inside the CharacterCreationModelMenu() function


The function CharacterCreationNameMenu() is being declared after that.

Ah, I missed that part. You’re right then. :buddy:

I got another problem. I’m trying to make my own HUD, so I made a code like this in cl_init. When I test the HUD it simply doesn’t show up, hovewer the default HUD is hidden. Any fix for this?

[LUA]
CHOCOHUD = { }

function CHOCOHUD:HealthCorner( )

client = client or LocalPlayer();
if( !client:Alive( ) ) then return; end

surface.SetDrawColor( 255, 255, 255, 255 )
surface.DrawOutlinedRect( ScrW() - 10, ScrH() - 10, 100, 20 )

end
hook.Add( “HUDPaint”, “CHOCOHUD:HealthCorner”, HealthCorner )

function CHOCOHUD:HealthBackground( )

client = client or LocalPlayer();
if( !client:Alive( ) ) then return; end

surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( ScrW() - 10, ScrH() - 10, 100, 20 )

end
hook.Add( “HUDPaint”, “CHOCOHUD:HealthBackground”, HealthBackground )

function CHOCOHUD:HealthBar( )

client = client or LocalPlayer();
if( !client:Alive( ) ) then return; end

surface.SetDrawColor( 185, 225, 35, 255 )
surface.DrawRect( ScrW() - 10, ScrH() - 10, LocalPlayer():Health(), 20 )

end
hook.Add( “HUDPaint”, “CHOCOHUD:HealthBar”, HealthBar )

function hidehud(name)
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)
[/LUA]

Oh by the way, thank you for finding me a fix for the console problem :stuck_out_tongue:

Remove this, didn’t you even look at the name of the function? :slight_smile:

[lua]

function hidehud(name)
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)
[/lua]

Tried it right now. Doesn’t work, it just shows the default HUD (The HL2 one) and keeps to not showing up the custom HUD.