Skip to content

Events

Shiva has two event systems: the internal event bus (cross-module Lua events) and FiveM net events (client/server communication). Both are typed and documented.

Internal Event Bus

The event bus lets modules communicate without direct dependencies. A module emits; any number of modules can subscribe.

lua
local bus = container:make('IEventBus')

-- Subscribe
bus:on('player:spawned', function(event)
    print('Player spawned:', event.playerId)
end)

-- Emit
bus:emit('player:spawned', {
    playerId = source,
    coords = GetEntityCoords(GetPlayerPed(source)),
})

Event Naming Convention

Events follow domain:action naming:

player:connected
player:disconnected
player:spawned
economy:moneyAdded
economy:moneyRemoved
jobs:jobChanged
inventory:itemAdded
inventory:itemRemoved

One-Time Listeners

lua
bus:once('shiva:ready', function()
    -- runs only once
end)

Removing Listeners

lua
local unsubscribe = bus:on('player:spawned', handler)
-- later...
unsubscribe()

FiveM Net Events

For client ↔ server communication, Shiva wraps FiveM's native TriggerNetEvent / RegisterNetEvent with type safety and logging:

lua
-- Server side: register a handler
Shiva.onNetEvent('shiva:player:requestData', function(source, data)
    -- data is validated before this runs
end, {
    schema = {
        characterId = 'number',
    }
})

-- Client side: trigger the server
Shiva.triggerServer('shiva:player:requestData', {
    characterId = 3,
})

Net Event Rules

  • All events in the shiva:* namespace are registered by Shiva
  • Your events should use yourmodule:* namespace
  • Never use raw TriggerNetEvent in Shiva modules — use the wrapper

Event Reference

See individual module docs for their emitted events:

See Also

Released under the MIT License.