Hey there! In this guide, I’ll explain the client-server concepts and how they work in Project Zomboid. This guide is mainly aimed to modders who want to update their creations so that they work correctly in MP.
Client-Server Concept
Client
A client is a computer or a program that, as part of its operation, relies on sending a request to another program or a computer hardware or software that accesses a service made available by a server.
For example, Multiplayer video games may run as a client on each computer. The term “client” may also be applied to computers or devices that run the client software or users that use the client software.
Server
A server is a computer or a program that provides functionality for other programs or devices, called “clients”. Servers can provide various functionalities, often called “services”, such as sharing data or resources among multiple clients, or performing computation for a client.
Trigger-Event Concept
Trigger
A trigger is usually a function that is executed when some event occurs.
Event
An event is a fragment of code that is executed when a trigger refers to it.
Triggers and Events
Triggering Events
Triggering Server Events
To trigger a server event from inside a client script.
sendClientCommand(IsoPlayer, string, string, KahluaTable) -- or sendClientCommand(string, string, KahluaTable)
Apparently IsoPlayer will always be the source player, otherwise the event will not be triggered.
Triggering Client Events
To trigger a client event from inside a server script.
sendServerCommand(IsoPlayer, string, string, KahluaTable) -- or sendServerCommand(string, string, KahluaTable)
Listening Events
Listening Server Events
To listening a server event.
local Commands = {}; local onClientCommand = function(module, command, player, args) if Commands[module] and Commands[module][command] then Commands[module][command](player, args) end end Events.OnClientCommand.Add(onClientCommand)
Listening Client Events
To listening a client event.
local Commands = {}; local onServerCommand = function(module, command, args) if Commands[module] and Commands[module][command] then Commands[module][command](args) end end Events.OnServerCommand.Add(onServerCommand)
Dev Environment
Now that we know the concepts and the functions that we need to use, we need to create our dev environment to apply what we have learned.
Create the Server
Download “Project Zomboid Dedicated Server”, you can find it enabling the tools checkbox of your steam library.
Go to local files of “Project Zomboid Dedicated Server”.
(Project Zomboid Dedicated Server → Manage → Browse local files)
Edit the file “StartServer64_nosteam”.
(You can open the file with any other text editor)
Remove “-Xms16g” and change “-Xmx16g” to -Xmx3g. (Optional)
(-Xms is the initial memory allocation and -Xmx is the maximum memory allocation, due this is a test server, not as much allocated memory space is required)
Create the Clients
Go to local files of “Project Zomboid”.
(Project Zomboid → Manage → Browse local files)
Find the “ProjectZomboid64” and create a shortcut to your desktop.
(ProjectZomboid64 → Send To → Desktop (Create shortcut))
Go to desktop, find the newly created shortcut and then to properties.
(ProjectZomboid64 → Properties)
Add “-nosteam -debug” into the Target.
(Shortcut → Target → Add “-nosteam -debug”)
Dev environment is ready! To perform tests on a mod, they must be placed in the following folder C:\Users\YourPCName\Zomboid\mods and add them in the server config file …\Zomboid\Server.
(servertest.ini → Mods=YourMod)
You can set yourself as admin writing on server console “grantadmin YourUserName”.
Examples
A print from Client to Server
- Client.lua
local onKeyPressed = function(key) local source = getPlayer(); if not source then return end if key == Keyboard.KEY_SPACE then local sourceId = source:getOnlineID(); source:Say("I'm the player with ID " .. sourceId); sendClientCommand("Test", "SimplePrint", { playerId = sourceId }); end end Events.OnKeyPressed.Add(onKeyPressed);
- Server.lua
local Commands = {}; Commands.Test = {}; Commands.Test.SimplePrint = function(player, args) print("Player with ID " .. args.playerId .. "# Triggered this event."); if player:getOnlineID() == args.playerId then print("Yep, they are the same player.") end end local onClientCommand = function(module, command, player, args) if Commands[module] and Commands[module][command] then Commands[module][command](player, args); end end Events.OnClientCommand.Add(onClientCommand);
A print from Client to Server
F.A.Q.
- Why my mod isn’t load to the server?
Check if path and names are correct, also check that the name and its id are correct.
I hope you enjoy the Guide we share about Project Zomboid – Client-Server Concept + Script Guide; if you think we forget to add or we should add more information, please let us know via commenting below! See you soon!
- All Project Zomboid Posts List
Leave a Reply