HowTo/Events: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
{{LuaCode|1=addEventHandler('onPlayerJoined', function(event,client) | {{LuaCode|1=addEventHandler('onPlayerJoined', function(event,client) | ||
message(client.player.name .. ' has joined the server!', COLOUR_GREEN) | |||
end)}} | end)}} |
Revision as of 12:14, 5 November 2020
Summary
Events are used to run your code when something specific occurs.
An event system is also called the observer pattern.
A scripting function can be bound to an event name.
When an event name is invoked, all scripting functions that are bound to that event name are called.
Example
Lua, Server-Side:
addEventHandler('onPlayerJoined', function(event,client)
message(client.player.name .. ' has joined the server!', COLOUR_GREEN)
end)