Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es_extended) Dynamic Modules #1557

Closed
wants to merge 3 commits into from

Conversation

Zykem
Copy link
Contributor

@Zykem Zykem commented Dec 21, 2024

This PR introduces a dynamic module system to the ESX Framework. The key features and purposes of this system are as follows:

  • Dynamic Module Loading: Allows loading of modules dynamically from specified paths and resources.
  • Client and Server Support: Supports both client side and server side module loading with valid handling to prevent cross-loading.
  • Enhanced Flexibility: Enables developers to load custom modules from different resources, enhancing the flexibility and modularity of the ESX Framework.

Motivation

The dynamic module system aims to improve the modularity and flexibility of the ESX Framework, allowing developers to extend and customize the framework more efficiently. This system is particularly useful for code that does not need to run within the ESX Core but inside the resource that requires it. For example:

  • Blips: es_extended does not need to store blips created by other resources.
  • Peds: Custom peds can be managed by specific resources.
  • KVP database wrapper: Resource-dependent database wrappers can be loaded dynamically.

Usage isntructions

  • Define your modules in the specified path and ensure they are included in fxmanifest.lua file using the files directive
  • Use the ESX.LoadModule function to load modules dynamically by specifying the module name, optional path and optional resource name.
    ^ You can either return a table in the module and use it like i provided down below with the "db" module, or you can use it like in the blip module, just creating glboal functions.

Example

Although you can find an example in client/dynamicModules/blip.lua, i will provide another one:

Expandable code, just showing what it could be used for

local module = {}

module.saveToDb = function(key, value)
    SetResourceKvp(key, value) 
end

module.getFromDb = function(key)
    return GetResourceKvpString(key)
end

return module
-- Loading the module assuming the module is inside es_extended/server/dynamicModules/kvp.lua
local db = ESX.LoadModule('kvp')
db.saveToDb('exampleKey, 'exampleValue')

local exampleValue = db.getFromDb('exampleKey')

Loading a module that is in a different resource

-- this module would have to be in esx_testing/modules/testModule.lua
ESX.LoadModule('testModule', 'modules', 'esx_testing')

@Mycroft-Studios
Copy link
Member

Please check dev branch before PRing, this already exists there

@Zykem Zykem deleted the clean-dynamic-modules branch December 21, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Recycle Bin
Development

Successfully merging this pull request may close these issues.

2 participants