# triggerEvent (Shared)

> Triggers an event on this side, on `source`. The element's own handlers and its ancestors' propagating ones are called right away, before the function returns.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Events
- **URL**: https://wiki.mymp.gg/en/triggerEvent

## Syntax

```lua
bool triggerEvent(string eventName, element source, any ...)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `eventName` | `string` | The name of a registered event. |
| `source` | `element` | The element the event happens on. It becomes the handlers' `source` global. |
| `...` | `any` | Arguments passed to every handler. |

## Returns

`false` if the event does not exist or a handler cancelled it with `cancelEvent`, else `true`.

To carry an event to the other side, use `triggerServerEvent` or `triggerClientEvent`. In the handlers, `sourceResource` is the resource that called `triggerEvent`.

## Example

```lua
addEvent("onRaceFinish")

addEventHandler("onRaceFinish", root, function(position)
    if position > 3 then
        cancelEvent(true, "no podium")
    end
end)

local podium = triggerEvent("onRaceFinish", resourceRoot, 2)
```

## See also

- [addEvent (Shared)](https://wiki.mymp.gg/en/addEvent.md): Registers a new event under this name. Only then can handlers be added to it and can it be triggered.
- [addEventHandler (Shared)](https://wiki.mymp.gg/en/addEventHandler.md): Makes a function run whenever the event happens on the given element or, with propagate, on any of its descendants.
- [cancelEvent (Shared)](https://wiki.mymp.gg/en/cancelEvent.md): Marks the running event as cancelled. What cancelling prevents depends on the event.
- [triggerClientEvent (Server)](https://wiki.mymp.gg/en/triggerClientEvent.md): Sends an event to the players' clients, which trigger it on source. The function returns before the clients receive it.
