Project Zomboid – Client-Server Concept + Script Guide

Project Zomboid – Client-Server Concept + Script Guide 1 - steamlists.com
Project Zomboid – Client-Server Concept + Script Guide 1 - steamlists.com

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.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Trigger-Event Concept - 44596E5
 
 
 

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 - Client-Server Concept + Script Guide - Dev Environment - 6A4DA4C
 
(Project Zomboid Dedicated Server → Manage → Browse local files)
 
 
Edit the file “StartServer64_nosteam”.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - 159259A
 
(You can open the file with any other text editor)
 
 
Remove “-Xms16g” and change “-Xmx16g” to -Xmx3g. (Optional)
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - F72CB3A
 
(-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 - Client-Server Concept + Script Guide - Dev Environment - 775F051
 
(Project Zomboid → Manage → Browse local files)
 
 
Find the “ProjectZomboid64” and create a shortcut to your desktop.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - 8CEB6F0
 
(ProjectZomboid64 → Send To → Desktop (Create shortcut))
 
 
Go to desktop, find the newly created shortcut and then to properties.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - F1C68DA
 
(ProjectZomboid64 → Properties)
 
 
Add “-nosteam -debug” into the Target.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - 24A578E
 
(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.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - F073160
 
(servertest.ini → Mods=YourMod)
 
 
You can set yourself as admin writing on server console “grantadmin YourUserName”.
 
 
Project Zomboid - Client-Server Concept + Script Guide - Dev Environment - 2720A30
 
 
 

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

 
 
Project Zomboid - Client-Server Concept + Script Guide - Examples - 0AAC5AA
 
 
 

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.
 
 

Written by Dislaik

 
 
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!
 
 


Be the first to comment

Leave a Reply

Your email address will not be published.


*