-
Notifications
You must be signed in to change notification settings - Fork 1
BasicClientExample
JabDoesThings edited this page Nov 17, 2024
·
3 revisions
-- Import the library as a module.
local ModLoader = require 'asledgehammer/modloader/ModLoader';
-- (To keep all prints clean and contextual)
local info = function(msg)
print('[' .. module .. '] :: ' .. msg);
end
--- @param module string The module folder.
--- @param path string The path in the module to the file.
--- @param result 0 | 1
- ModLoader.RESULT_FILE_NOT_FOUND
- ModLoader.RESULT_SUCCESS
--- @param data string | nil The data retrieved from the server.
local callback = function(module, path, result, data)
-- Handle non-installed / missing result.
if result == ModLoader.RESULT_FILE_NOT_FOUND then
info('File not installed on server. Ignoring..');
return;
end
-- Handle data here. (Example is Lua code)
loadstring(data)();
end;
--- @type boolean
---
--- If true, the server will cache the file so when
--- called again it'll be ready.
local cache = true;
-- Request the file:
-- ~/Zomboid/Lua/ModLoader/mods/FoobarExample/Foobar_Client.lua
ModLoader:requestServerFile('FoobarExample', 'Foobar_Client.lua', cache, callback);