How to use Events

From GTA Connected
Revision as of 16:49, 16 August 2018 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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)
    outputChatBox(client.player.name .. ' has joined the server!', COLOUR_GREEN)
end)