{"id":31039766,"url":"https://github.com/iloomilo/ilo_eventdispatcher","last_synced_at":"2025-09-14T08:01:51.834Z","repository":{"id":313792856,"uuid":"1052704649","full_name":"iloomilo/ilo_eventdispatcher","owner":"iloomilo","description":"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.","archived":false,"fork":false,"pushed_at":"2025-09-08T13:57:44.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-08T14:45:21.964Z","etag":null,"topics":["event-driven","fivem","lua"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iloomilo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-08T12:39:25.000Z","updated_at":"2025-09-08T13:57:49.000Z","dependencies_parsed_at":"2025-09-08T14:45:23.575Z","dependency_job_id":"a2515243-7dbc-41f1-8f45-1ed04b34e20c","html_url":"https://github.com/iloomilo/ilo_eventdispatcher","commit_stats":null,"previous_names":["iloomilo/ilo_eventdispatcher"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/iloomilo/ilo_eventdispatcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloomilo%2Filo_eventdispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloomilo%2Filo_eventdispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloomilo%2Filo_eventdispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloomilo%2Filo_eventdispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iloomilo","download_url":"https://codeload.github.com/iloomilo/ilo_eventdispatcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloomilo%2Filo_eventdispatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275076591,"owners_count":25401318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["event-driven","fivem","lua"],"created_at":"2025-09-14T08:01:28.177Z","updated_at":"2025-09-14T08:01:51.816Z","avatar_url":"https://github.com/iloomilo.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ilo_eventdispatcher\n\nA 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.\n\n---\n\n## Features\n\n* **Create events** with custom key-value storage\n* **Register listeners** for named events\n* **Dispatch events** to all registered listeners\n* **Stop propagation** to prevent further listeners from firing\n* Simple, lightweight, and extensible\n\n---\n\n## API Reference\n\n### `CreateEvent()` → `EventObject`\n\nCreates a new event object.\n\n**Example:**\n\n```lua\nlocal event = exports['ilo_eventdispatcher']:CreateEvent()\nevent:set(\"foo\", \"bar\")\n```\n\n---\n\n### `RegisterListener(eventName: string, callback: fun(event: EventObject))`\n\nRegisters a listener for the given event name. Multiple listeners can be registered for the same event.\n\n**Example:**\n\n```lua\nexports['ilo_eventdispatcher']:RegisterListener(\"my:event\", function(event)\n    print(\"foo is:\", event:get(\"foo\"))\nend)\n```\n\n---\n\n### `DispatchEvent(eventName: string, event: EventObject)`\n\nDispatches an event to all listeners registered under `eventName`. Listeners are executed in the order they were registered. Propagation can be stopped using `event:stopPropagation()`.\n\n**Example:**\n\n```lua\nlocal event = exports['ilo_eventdispatcher']:CreateEvent()\nevent:set(\"foo\", \"bar\")\n\nexports['ilo_eventdispatcher']:DispatchEvent(\"my:event\", event)\n```\n\n---\n\n### EventObject Methods\n\n* **`set(key: string, value: any)`** → `nil`\n  Store a value inside the event.\n\n* **`get(key: string)`** → `any`\n  Retrieve a stored value.\n\n* **`getAll()`** → `table\u003cstring, any\u003e`\n  Retrieve all stored values.\n\n* **`stopPropagation()`** → `nil`\n  Prevents further listeners from being executed.\n\n* **`isPropagationStopped()`** → `boolean`\n  Check if propagation has been stopped.\n\n---\n\n**📌 Example Usage:**\n\nLet’s say we want to modify the player’s paycheck based on different conditions across multiple resources.\nWe dispatch an event that can be listened to anywhere, allowing other resources to adjust the values before the final paycheck is applied\n```lua\n    --- Send paycheck to a player\n    --- @param player Player Player object\n    --- @param payment number Payment amount\n    sendPaycheck = function(player, payment)\n        local event = exports['ilo_eventdispatcher']:CreateEvent()\n        event:set('player', player)\n        event:set('payment', payment)\n\n        -- Dispatch paycheck event\n        exports['ilo_eventdispatcher']:DispatchEvent('qbx_core:sendPaycheck', event)\n\n        -- Get potentially modified payment value\n        payment = event:get('payment')\n\n        if payment \u003c= 0 then return end\n\n        player.Functions.AddMoney('bank', payment)\n        Notify(player.PlayerData.source, locale('info.received_paycheck', payment))\n    end\n```\nNow, you can listen for this event in any resource and modify the paycheck amount dynamically:\n```lua\n--- Example: Add extra payment if player is on shop duty\n--- @param event EventObject\nexports['ilo_eventdispatcher']:RegisterListener('qbx_core:sendPaycheck', function(event)\n    local currentPayment = event:get('payment')\n    --- @type Player\n    local player = event:get('player')\n\n    if player.PlayerData.source ~= nil then\n        local src = player.PlayerData.source\n\n        if IsShopDuty(src) then\n            currentPayment = currentPayment + config.payCheck\n\n            -- Update event payment value\n            event:set('payment', currentPayment)\n        end\n    end\nend)\n```\n\n---\n\n## Installation\n\n1. Add the file to your resource.\n2. Ensure it is properly loaded.\n3. Use the exported functions in your scripts.\n\n---\n\n## License\n\nThis project is released under the **MIT License**. You are free to use, modify, and distribute it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filoomilo%2Filo_eventdispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filoomilo%2Filo_eventdispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filoomilo%2Filo_eventdispatcher/lists"}