I don't know how detailed my explanation has to be so I'm starting with a few hints and if you need more you can ask again.
1. I guess I will do a tutorial for that some time
You need to draw a rectangle with a background color and some text. You can do that with
set_color(red, green, blue, alpha)
draw_quad(x, y, width, height) -- x,y = coordinates of top left corner
draw_text(text, style)
in the draw2d hook.
To change the color when hovering you have to do three things:
1. store background color and alternative background color (for hovering) in variables
2. Create a variable called isHovering (or something like that). In the function that draws your butotn, check if it is true. If it is use the alternate background color otherwise the default.
3. Check if the mouse is over the button. Do it like this:
local function onMouseMove(x, y)
-- if x, y is in the bounds of the button then
isHovering = true
else isHovering = false
end
end
add_hook("mouse_move", "checkButtonHover", onMouseMove)
Done.
Btw: You can check if the button was clicked pretty similar to the hover checking with the mouse_button_down or mouse_button_up hook. They use a function with the arguments (mouseButton, x, y)
2. Short explanation of the hooks (scroll down if you just want to know how to use them):
For chat commands there are two hooks you can use: Either console or command. The command hook was introduced in Toribash 3.91 so you have to use the console hook for people who still use earlier versions. This is why in my script I check the Toribash version. The difference between the two hooks is that the command hook is designed to listen for commands, so for example you can type "/jump" to execute stuff. The console hook listens for chat input. Stuff like "/jump" doesn't go to the chat (since it's a command) and therefore doesn't work with the console hook. But if you type "/ec jump" you will use a built in Toribash command that simply echoes "jump" (which will only be displayed locally, so in multiplayer nobody will see this).
Now to
how to use the hooks:
the command hook:
local function executeCommand(cmd)
-- check if the user typed a command you know
-- a command without arguments:
if cmd == "help" then
-- echo usage
return true
-- a command with arguments, like /jump 40 to jump 40 frames
-- cmd will be "jump 40" so we have to check if the first 4 letters are jump:
elseif cmd:sub(1, 4) =="jump" then
-- now check how many fames to jump. this will be the 6th character till the end
-- also we have to turn the string into a number
jump(tonumber(cmd:sub(6))
return true
else return false
end
end
add_hook("command", "checkCommand", executeCommand)
If you recognise the command, return true, otherwise false.
The console hook works similar, with the difference that it will execute the function everytime the user recieves a chat message and that it looks a little different:
-- use the same executeCommand function
add_hook("console", "checkCommand", function(message, type)
-- you could check for the message type to make sure it is not a chat message of someone else
-- but I'm too lazy to find out which is the correct type :D
return executeCommand(message)
end
)
Now that I think about it, if you don't need to check the message type it should be possible to simply do
add_hook("console", "checkCommand", excecuteCommand)
I haven't tested it but it should work.
Bottomline of the story: Both work pretty similar but if you can, use the command hook.