Console Command Help

I am trying to make a console command that rolls a number between 0 and 100 for my own RP gamemode. It is supposed to look like this in chat:

Gatekeeper828 has rolled a 75 out of 100.

Whenever I type “roll” in my console, it says it’s an unknown command. I looked at the wiki and even tried the example yet it did not work.

Here’s the code:

function roll() 
    Chat.Add(Color(0,0,255), player:GetName().." has rolled "..math.random(0, 100).." out of 100."

concommand.Add( "roll", roll )


Also, is there anyone who could tell me where I would put this script if I wanted it in a gamemode? Thanks in advance.

Chat.AddText is clientside only, if you are only placing this in cl_init or another clientside file. It will work. Avoid to add console commands in shared files, it’ll get confusing and usually not work…

Alright, I will try it out later. Thanks for the help.

Also It’s ‘chat’ not ‘Chat’

I changed up the code but it’s still saying “Unknown Command” in the console. Would it be possible to create a Derma panel or a chat command that performs the function? If so could you show me how to create a chat command?

Remove the last end, also you should post errors (You have to look pretty far up in the console to find autorun errors)

[lua]chat.AddText(Color(0,0,255), player:GetName()…" has rolled “…math.random(0, 100)…” out of 100."…"
") [/lua]

Try that instead. Fixed a couple errors in it.

Here’s an error I found:

[gamemodes\Test\gamemode\cl_init.lua:4] ‘)’ expected near ‘’
There was a problem opening the gamemode file ‘Test/gamemode/cl_init.lua’

Line four is this:

chat.AddText(Color(0,0,255), player:GetName().." has rolled "..math.random(0, 100).." out of 100."

Show the whole code.

Here’s all I have in cl_init:

include( shared.lua )

function roll(player, command, arguments)
chat.AddText(Color(0,0,255), player:GetName()… has rolled …math.random(0, 100)…out of 100.

concommand.Add( roll, roll )

That code works fine here.

[editline]13th February 2011[/editline]

I see why your previous code errored now, you should really use [noparse][lua][/lua][/noparse] tags, the syntax highlighting would have showed what was wrong immediately.

Thanks for helping me out.

Now no errors are popping up but the command is still unknown.

You need to put the first roll in quotes