Skip to content

Latest commit

 

History

History
141 lines (116 loc) · 6.26 KB

README.md

File metadata and controls

141 lines (116 loc) · 6.26 KB

Assistant in writing and fixing mods | Помощник в написании и исправлении модов для сервера "What If...?" (Project Zomboid)

(EN) Requirements:


To begin with, we will use the project for generating PZ jar sources https://github.com/Konijima/PZ-Libraries.
Following the instructions, we obtain two jar files that we need: zdoc-lua.jar (.lua) and zomboid.jar (.classes) - containing the required version of lua and java from PZ.
Note: these files need to be recompiled when PZ is updated!
These files should be placed in the lib folder of the project and replace any existing ones if necessary.

The sources of the mods themselves should be placed in the src/main/resources/mods/ folder.
Next, we need to specify the path to the mod script that we want to modify in the configuration file: config.properties (src/main/resources/config.properties).
For example: SCRIPT=mods/mod_folder/media/lua/server/script_name.lua

Execute gradle build, then gradle run (to launch the code check).

gradle_cut.png

Example:

Let's run the lua from the Prisoner mod, specifying the path in config.properties:
SCRIPT=mods/Prisonner/media/lua/server/BP_Moddata_Server.lua

We get the following log:

00:15:24.209 [main] ERROR org.wirp.ScriptRunner -- Error running script file: 
org.luaj.vm2.LuaError: @C:\Users\User\IdeaProjects\wirp\build\resources\main\mods\Prisonner\media\lua\server\BP_Moddata_Server.lua:2 attempt to call nil
	at org.luaj.vm2.LuaValue.checkmetatag(Unknown Source)
	at org.luaj.vm2.LuaValue.callmt(Unknown Source)
	at org.luaj.vm2.LuaValue.call(Unknown Source)
	at org.luaj.vm2.LuaClosure.execute(Unknown Source)
	at org.luaj.vm2.LuaClosure.call(Unknown Source)
	at org.wirp.ScriptRunner.loadLuaFile(ScriptRunner.java:42)
	at org.wirp.ScriptRunner.main(ScriptRunner.java:29)

The program ran, but we received a message that the script is not working correctly.
This does not mean that the script does not work, let's shorten the contents of the script to:

if isClient() then return; end;

playerdataServer = {};
playerdataServer.Verbose = false
--[[--======== Players ========--
]]--

The error was due to the code using the function isClient(), which determines whether the player is a client.
The project has a file: src/main/resources/mods/Mock.lua, which will help us make a mock of this function call.
Let's make the following changes to it and try to run it:

function isClient()
    return false
end

local mockEvents = {}

function mockEvents.OnClientCommand_Add(callback)
    print("Mock method called with callback!\n", callback)
end

Events = {
    OnClientCommand = {
        Add = mockEvents.OnClientCommand_Add
    }
}

(РУС) Требования:


Для начала воспользуемся проектом для генерации jar исходников PZ https://github.com/Konijima/PZ-Libraries.
По инструкции получаем нужные нам два jar файла: zdoc-lua.jar (.lua) и zomboid.jar (.classes) — , содержащие lua и java из нужной нам верссии PZ.
При обновлении PZ их нужно перекомпилировать!
Эти файлы требуется переложить в папку lib проекта, если надо — заменить имеющиеся.

Исходники самих модов кладутся в папку src/main/resources/mods/
Далее нужно прописать путь к скрипту мода, который мы хотим изменять, в настроечном файле: config.properties (src/main/resources/config.properties).
Например: SCRIPT=mods/*папка_с_модом*/media/lua/server/*название_скрипта*.lua

Выполнить gradle build, потом — gradle run (запуск проверки кода)

gradle_cut.png

Пример

Запустим lua из мода Prisoner, указав путь в config.properties:
SCRIPT=mods/Prisonner/media/lua/server/BP_Moddata_Server.lua

Получим лог:

00:15:24.209 [main] ERROR org.wirp.ScriptRunner -- Error running script file: 
org.luaj.vm2.LuaError: @C:\Users\User\IdeaProjects\wirp\build\resources\main\mods\Prisonner\media\lua\server\BP_Moddata_Server.lua:2 attempt to call nil
	at org.luaj.vm2.LuaValue.checkmetatag(Unknown Source)
	at org.luaj.vm2.LuaValue.callmt(Unknown Source)
	at org.luaj.vm2.LuaValue.call(Unknown Source)
	at org.luaj.vm2.LuaClosure.execute(Unknown Source)
	at org.luaj.vm2.LuaClosure.call(Unknown Source)
	at org.wirp.ScriptRunner.loadLuaFile(ScriptRunner.java:42)
	at org.wirp.ScriptRunner.main(ScriptRunner.java:29)

Программа отработала, но мы получили сообщение, что скрипт неисправен.
Это не означает, что скрипт не работает, давайте сократим содержимое скрипта до:

if isClient() then return; end;

playerdataServer = {};
playerdataServer.Verbose = false
--[[--======== Players ========--
]]--

Ошибка заключалась в том, что код использует функцию isClient(), которая определает является ли игрок клиентом.
В проекте есть файл: src/main/resources/mods/Mock.lua, который поможет нам сделать заглушку на данном вызове функции.
Внесем в него следующие правки и попробуем запустить:

function isClient()
    return false
end

local mockEvents = {}

function mockEvents.OnClientCommand_Add(callback)
    print("Mock method called with callback!\n", callback)
end

Events = {
    OnClientCommand = {
        Add = mockEvents.OnClientCommand_Add
    }
}