AddEvent: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Info|Function|Server & Client|1.0}} | {{Info|Function|Server & Client|1.0}} | ||
{{FuncDescription|Adds a function as event handler which will be called when a certain event occurs. Multiple functions can be bound to a single event.}} | {{FuncDescription|Adds a function as event handler which will be called when a certain event occurs. Multiple functions can be bound to a single event. | ||
You can also specify new event names that do not exist.}} | |||
{{FuncSyntax|AddEvent(EventName, LuaFunction)}} | {{FuncSyntax|AddEvent(EventName, LuaFunction)}} | ||
Line 9: | Line 11: | ||
{{FuncParam|LuaFunction |The function which will be called when the event occurs.}} | {{FuncParam|LuaFunction |The function which will be called when the event occurs.}} | ||
{{FuncReturnValue|This function | {{FuncReturnValue|This function returns '''true'''.}} | ||
== Example == | == Example == |
Revision as of 09:34, 2 September 2020
Description
Adds a function as event handler which will be called when a certain event occurs. Multiple functions can be bound to a single event.
You can also specify new event names that do not exist.
Syntax
AddEvent(EventName, LuaFunction)
Parameters
- EventName
The name of the event. See Server Events or Client Events for a list of events. - LuaFunction
The function which will be called when the event occurs.
Return Value
- This function returns true.
Example
function OnPlayerDeath(player, instigator)
if instigator == nil then
AddPlayerChat(player, "You died :(")
else
AddPlayerChat(player, "You have been killed by "..GetPlayerName(instigator))
end
end
AddEvent("OnPlayerDeath", OnPlayerDeath)