Skip to content

Instantly share code, notes, and snippets.

@grdlo
Last active July 26, 2022 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grdlo/04a945c5144a4f4ac5c19ce1728f0bb8 to your computer and use it in GitHub Desktop.
Save grdlo/04a945c5144a4f4ac5c19ce1728f0bb8 to your computer and use it in GitHub Desktop.
Custom import file for FiveM script. More information the first comment: https://gist.github.com/grdlo/04a945c5144a4f4ac5c19ce1728f0bb8?permalink_comment_id=4244975#gistcomment-4244975
---
--- This file is free to use anywhere.
--- You can use, edit, and distribuate this files as long as
--- the header credits is keep intact or at least with the current info
---
--- @author https://github.com/grdlo
--- @repository https://gist.github.com/grdlo/04a945c5144a4f4ac5c19ce1728f0bb8
--- @version 1.0.0
---
local scriptname = "<YourScriptNameHere>"
local library = {
server = {
"<YourFileToImport>"
},
shared = {
"<YourFileToImport>"
},
client = {
"<YourFileToImport>"
}
}
local function import(file)
load(LoadResourceFile(scriptname, file))()
end
local function foreach(filesArray, func)
for k, v in pairs(filesArray or {}) do func(v) end
end
(function()
foreach(library.shared, import)
if IsDuplicityVersion() then
foreach(library.server, import)
else
foreach(library.client, import)
end
end)()
@grdlo
Copy link
Author

grdlo commented Jul 26, 2022

How to use-it ?

1- Copy the fximport.lua file into the root directory of your script (this is the same folder of your fxmanifest.lua)
2- Open the fximport.lua file and edit the following variables :

  • scriptname: define a string here holding the current name of the script (wich will work as a library)
  • library.server: define an indexed array here holding the clients files to be loaded
  • library.shared: define an indexed array here holding the clients files to be loaded
  • library.client: define an indexed array here holding the clients files to be loaded

You can now load you Library Script in other script by adding the following line in the shared_scripts configuration method of the fxmanifest :

@<you-library-script-name>/fximport.lua

The fxmanifest.lua should look like something similar to that:

fx_version('cerulean')
games({ 'gta5' })

shared_scripts({
    "@<you-library-script-name>/fximport.lua",
    ...
})

server_scripts({
    ...
})

client_scripts({
    ...
})

If this gist was useful to you, don't forget the star

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment