- Documentation
- Shared functions
- triggerEvent
Function
triggerEvent
Triggers an event on an element on the same side (server → server, client → client). The handlers run immediately, before the function returns. The event must be registered with addEvent or be built in.
Syntax
bool triggerEvent(string eventName, element baseElement [, any ...])Arguments
eventNamestring- Event name.
baseElementelement- The element that will be
source. ...any, optional- Arguments passed to the handlers.
Returns
false when a handler called cancelEvent; true otherwise.
Example
addEvent("onJobFinished")
addEventHandler("onJobFinished", root, function(pay)
givePlayerMoney(source, pay)
end)
addCommandHandler("koniec", function(player)
triggerEvent("onJobFinished", player, 500)
end)
See also
addEventRegisters a custom event with the given name so it can be triggered (triggerEvent,triggerClientEvent,triggerServerEvent) and handled (addEventHandler). WithallowRemoteTrigger = truethe event can come from the other side of the network: on the server - from a client viatriggerServerEvent, on the client - from the server viatriggerClientEvent. Without it, events from the network are rejected, which protects the server from clients faking events.cancelEventCancels the current event from inside its handler. For events that allow it, it blocks the default action, e.g.onPlayerChat(the message will not appear in chat),onPickupHit(the pickup will not be collected),onVehicleStartEnter(the player will not get in). Other handlers still run and can check the state withwasEventCancelled. On the server you can give a reason, readable withgetCancelReason.triggerClientEventSends an event from the server to one player, several players or everyone at once.