• Console Command Help
    12 replies, posted
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: [CODE] function roll() Chat.Add(Color(0,0,255), player:GetName().." has rolled "..math.random(0, 100).." out of 100."\n") end concommand.Add( "roll", roll ) end [/CODE] 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.Add[b]Text[/b] 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..
[QUOTE=leiftiger;28026001]Chat.Add[b]Text[/b] 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..[/QUOTE] 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.".."\n") [/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 '\' [cpp] There was a problem opening the gamemode file 'Test/gamemode/cl_init.lua' Line four is this: [CODE] chat.AddText(Color(0,0,255), player:GetName().." has rolled "..math.random(0, 100).." out of 100."\n") [/CODE]
Show the whole code.
Here's all I have in cl_init: [lua] 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.\n) end concommand.Add( roll, roll ) [/lua]
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. Edit: Now no errors are popping up but the command is still unknown.
You need to put the first roll in quotes [lua] concommand.Add("roll",roll) [/lua]
Sorry, you need to Log In to post a reply to this thread.