#๐Ÿ“Œ Dynamic EventDispatcher

1 messages ยท Page 1 of 1 (latest)

unique vale
#

Hey,
Iโ€™ve decided to release my small event dispatcher that I use on my own server.
It makes it super easy to create custom events, register listeners in any resource, and modify values across your code without having to hard-link everything together.

๐Ÿ”ง Features

  • Create and dispatch events anywhere
  • Add multiple listeners per event
  • Stop propagation when needed
  • Lightweight & easy to use

**๐Ÿ“Œ Example Usage: Paychecks **

    --- Send paycheck to a player
    --- @param player Player Player object
    --- @param payment number Payment amount
    sendPaycheck = function(player, payment)
        local event = exports['ilo_utils']:CreateEvent()
        event:set('player', player)
        event:set('payment', payment)

        -- Dispatch paycheck event
        exports['ilo_eventdispatcher']:DispatchEvent('qbx_core:sendPaycheck', event)

        -- Get potentially modified payment value
        payment = event:get('payment')

        if payment <= 0 then return end

        player.Functions.AddMoney('bank', payment)
        Notify(player.PlayerData.source, locale('info.received_paycheck', payment))
    end

Other resource:

--- Example: Add extra payment if player is on shop duty
--- @param event EventObject
exports['ilo_eventdispatcher']:RegisterListener('qbx_core:sendPaycheck', function(event)
    local currentPayment = event:get('payment')
    --- @type Player
    local player = event:get('player')

    if player.PlayerData.source ~= nil then
        local src = player.PlayerData.source

        if IsShopDuty(src) then
            currentPayment = currentPayment + config.payCheck
            -- Update event payment value
            event:set('payment', currentPayment)
        end
    end
end)

More detailed information is available at the github repository!
https://github.com/iloomilo/ilo_eventdispatcher

GitHub

A lightweight Lua-based event dispatcher designed for modular event handling in FiveM. This module allows you to create custom events, register listeners, and control event propagation. - iloomilo/...

unique vale
#

๐Ÿ“Œ Dynamic EventDispatcher

queen plank
#

What is the use of that?

unique vale
#

great to decouple your stuff, like in the paycheck example