#mod_development
1 messages · Page 195 of 1
MyTrait:addXPBoost(Perks.Doctor, 4) adds 4 lvls, guessing its just MyTrait:removeXPBoost(Perks.Doctor, 4) to get rid of 4?
i don't think there's a remove method
how do you reopen the command bar when you close it
the debug window? the ~ key
Try MyTrait:getXPBoostMap():remove(Perks.Doctor)
is there a way to cap someone to a certain level of a skill or do i just have to detect them gaining a lvl to remove it
ZombRand(1, 2) wouldnt work if it didnt
so try that i guess
ZombRand(1,2) doesn't work
1 is included, 100 is not
traditionally with rng functions the upper limit is exclusive
just wait till you see my mod, nothing is traditional
how do i stop this from happening, seems odd
it happens completely randomly
is it just a glitchy system?
I have no clue how to mod, but I'm willing to figure it out. How complicated would it be to make a submod for EHE and They Knew (and Antizin submod) to allow the medicines to appear in medical airdrops?
If it's not as complicated as I think it is, I'd like to put something like this together.
how do i check if there's a player in a certain area? its not the client itself. this relies on someone else NOT being there before getting executed
you can loop through the player list and check if anyone's within that coordinate range
if it's going to be somewhere away from the player you should do it on the server because the client player list won't include players that client hasn't been in render range of at least once in that session
if there a built-in function that gives me the player list?
getOnlinePlayers()
iirc it returns nil in singleplayer, so if your code runs in sp too you need handling for that
Thank you for your help
one more question, if i do it on the server. is it the same process, at least when calling functions? So if i made functionA() on the server, can i call it on the client side by doing it normally? functionA()
As simple as modifying the vehicle distro for the loot boxes or modifying the recipe functions in opening the boxes.
no, they're entirely separate, you need to use client/server commands to transmit information
functionA will technically exist on the client (assuming it's just in the server folder and you haven't used a client check to stop the file from running) but calling it just calls it on the client
oh damn, that will be a big headache to figure it out, but thank you.
one last question(i promise), how vast is the render range? what i want to do isn't technically far from the player. its very close to them and they can even see it i think.
i can DM you the area if you want to see it.
you mean the loaded squares around player?
i don't really know, i guess so?
i can't draw a radius, but i tested in four directions N-S and W-E, roughly upto 90 tiles to be on safe side. I think it goes a bit further to 93 or 97. If you wanna test your self, start accessing tiles and increment a counter as long as the next square isnt nil. Print the counter var to console.
larger walls would block getting adjacent squares
to visualize it better, add broken glass to each square you access
that answers my question, thank you.
the area im talking is about half of that.
ZombRand(1,2) +1 ?
this would always return 2
ZombRand(0,2) +1 ?
yeah, that would return 1 or 2
You only need 2 arguments if you want the number to be in between 2 things and the min isn't 0
-
Why can't I rotate the tiles I built? Even if you picked up the object, and then start to place it by holding the mouse button, the object can no longer be rotated, it will remain in the same position. Which parameter is responsible for this?
-
And for some reason, the capacity of containers prescribed by me is ignored. Does this mean that the game engine prioritizes tile properties instead of mine?
Thx for your help
There's no way to "quantify" it, you'd have to dig in.
Hi guys.
I'm Trying to make a set of sub mods that change the carry capacity and weight reduction of different bags, One sub mod would change the properties of backpacks, another sub mod would change the properties of handheld containers, but i noticed that both of those things are on the same script on the main game files.
I'm wondering if its possible to modify the same file multiple times through scrips so that the changes can be added on top or will one of them overwrite the other entirely?
Lol, i kept testing and my mods ain't doing a thing at all. I have no idea what's going on
I tested a single one of them and nothing is changing
OMFG I'm so stupid, I had the folder structure wrong, that was the issue the whole time
🫂
how would I activate a function as soon as I load into the world?
is it once every save or once every load on start?
every load on start
i think try event OnCreatePlayer, i used it once and seemed to be triggered on each load.
actually OnGameStart might be a better fit
Im looking for some info on Timed Actions, how can i make one? Is there a mod i can refer to ? What if i wanted to override a Timed Action from base game?
OnGameStart is better, OnCreatePlayer will fire for every splitscreen character
So I backed up some mod files and changed some of the armor to include "Canhaveholes = false" but the same armor is still being damaged in testing. Any ideas?
if i want to set player's health i need to use getPlayer():getCharacter():setHealth(0.0)?
also if i want to add arguments to my command, what should i do?
command:
ISChat.allChatStreams[8] = {name = "addperk", command = "/addperk", tabID = 1};
sending command:
sendClientCommand("cmd", "addperk", {});```
Guys, would you say Lua is better than Scripts at modifying item values such as weight, capacity, etc.?
Gonna give it a try then. I've been banging my head against my desk for the past 2 days trying to make a mod that modifies Bag and Container values and it just wont work
I just need the Lua file alone for this or do i still need to create a script?
you wouldn't need a script
the syntax is just
local item = ScriptManager.instance:getItem("Base.Apple")
if item then
item:DoParam("Weight = 1.5")
end
any ideas?
I was trying to go through the ItemTweaker API but i don't know if that's too old already
TweakItem("Base.Bag_Schoolbag", "WeightReduction", "65") TweakItem("Base.Bag_Schoolbag", "Weight", "1.0") TweakItem("Base.Bag_Schoolbag", "Capacity", "15") TweakItem("Base.Bag_Schoolbag", "RunSpeedModifier", "1.0")
I think I'm gonna use your method instead
itemtweaker basically just does this with different syntax
unfortunately when it does it prints a message to the log, for every single parameter for every single item, and prints are basically one of the laggiest things you can do - some servers were recording twenty second shorter load times when they edited to remove the print
i question whether it was even necessary to have an api for this in the first place, but especially with the performance impact i wouldn't recommend it
So performance wise I'd be better off using the code you showed me right?
yeah
it's internally what itemtweaker does anyway, just without all the extra stuff that makes it lag
I know very little of this... so sorry for trying to be so reassuring.
An example would look something like this?
local item = ScriptManager.insance:getItem ("Base.Bag_Schoolbag") if item then item:DoParam("Weight = 1.0") item:DoParam("Weightreduction = 65") item:DoParam("Capacity = 15") end
without the space after getItem and there's a typo in instance, but yeah
nice, thanks bro
Sorry again. Is there something I need to type at the begining of the Lua file like calling libraries or some stuff that usually comes before editing the indivdual items?
no need, literally everything in vanilla zomboid is global
cool, thanks :)
so i tried to do this:
ISChat.allChatStreams[9] = {name = "kill", command = "/kill", tabID = 1, arguments = {"plr"}};
sendClientCommand("cmd", "kill", {plr});
and now i have error in this lines:
killcmd(data)
getSpecificPlayer(plrnick):getCharacter():setHealth(0.0)
full code:
print("addperk command called")
local plrnick = data[1]
local perk = data[2]
end
local function killcmd(data)
print("kill command called")
local plrnick = data[1]
getSpecificPlayer(plrnick):getCharacter():setHealth(0.0)
end
function mycmds(module, command, data)
if module == "cmd" and command == "addperk" then addperkcmd()
elseif module == "cmd" and command == "kill" then killcmd(data)
end
end
Events.OnClientCommand.Add(mycmds)```
nearly. there is still some exceptions. e.g. client command reception management.
in those cases they aren't even returned right
to my knowledge everything accessible is global
yeah, it's a pain to tweak
How do you add comments in the lua file so it doesn't count as programming?
double dash?
no, just ]] is enough to end the comment
you can modify things via lua instead, but yes instead of overriding a file (bad practice) just copy the stuff into your own file and only put the ones u want in it in it
now that i realize that was old im sure this was already gone over
:P
Thanks for replying anyway. I'm still working on it. I was just wondering if it would just modify the parts i place on each file or if one file would overwrite the other. But I figured it was better to do this through Lua instead
Do you have to use client, server or shared lua to trigger an animation ?
I'm working on an animation that needs to be shown on the screens of all nearby players, where should I trigger that ?
Hey everyone, does anybody know how to recompile java?
I'm trying to make a mod that allows to swap a player (or rather any characters) model at runtime
the problem is, It is not allowed by java
the issue was that the Reset(IsoGameCharacter) from ModelManager didn't take the values from HumanVisual, but from another function. I changed to try to tak the values from HumanVisual first, and if it fales from the other option
public void Reset(IsoGameCharacter gameCharacter) {
if (gameCharacter.legsSprite != null && gameCharacter.legsSprite.modelSlot != null) {
ModelSlot modelSlot = gameCharacter.legsSprite.modelSlot;
this.resetModelInstance(modelSlot.model, modelSlot);
for (int int1 = 0; int1 < modelSlot.sub.size(); ++int1) {
ModelInstance modelInstance = (ModelInstance)modelSlot.sub.get(int1);
if (modelInstance != gameCharacter.primaryHandModel && modelInstance != gameCharacter.secondaryHandModel && !modelSlot.attachedModels.contains(modelInstance)) {
this.resetModelInstanceRecurse(modelInstance, modelSlot);
}
}
this.derefModelInstances(gameCharacter.getReadyModelData());
gameCharacter.getReadyModelData().clear();
this.dressInRandomOutfit(gameCharacter);
Model model = gameCharacter.getHumanVisual().getModel(); //Modded By FedCap
if (model == null)
{
model = this.getBodyModel(gameCharacter);
}//Modded By FedCap
modelSlot.model = this.newInstance(model, gameCharacter, gameCharacter.getAnimationPlayer());
modelSlot.model.setOwner(modelSlot);
modelSlot.model.m_modelScript = gameCharacter.getHumanVisual().getModelScript(); //Modded By FedCap
if (modelSlot.model.m_modelScript == null)
{
modelSlot.model.m_modelScript = ScriptManager.instance.getModelScript(gameCharacter.isFemale() ? "FemaleBody" : "MaleBody");
}//Modded By FedCap
this.DoCharacterModelParts(gameCharacter, modelSlot);
}
}
Now, I just need to compile it and see if it works. does anybody know how to do that? @bronze yoke @sour island @weak sierra
you need to recompile the class it came from
only that class
but no, no idea really
i imgaine there's a compile button
someplace
do you guys know how can i make scenarios/challenges in pz?
for example the prison scenario, the cabin defence scenario.
any ideas??????
try to check the files of this mod https://steamcommunity.com/sharedfiles/filedetails/?id=2106657533
and where do I copy the file exactly?
(it comes from zombie.core.skinnedmodel.ModelManager.java)
once compiled?
u'd copy it over the original in the game folder
i hope u didn't labor under the assumption that the game allows u to mod the java

like with a workshop mod
cuz it very dont
TIS man
they don't want us to have the power, hehe
any java mods on the workshop include the files someplace useless and have instructions to copy them manually
:/
and the server doesnt check them at all so ppl can cheat
kinda sucks
excellent
ut
i do not know how to compile java 🙃
something about javac --class-path [path to root installation directory] -d [output directory] [path to source file], but have no idea really
can't you also cheat with lua mods ?
I gather they have a checksum for the servers
so you would be kicked if it didn't match
(for lua, not javaclass)
I mean, can't I hook a function to the event onPlayerJoin (dont know the name) and give the player in question an M16 if his name is Ultraviolet ?
how would the server check if its true or false if the code runs on serverside ?
I mean, it would be the server who's giving me the item.
yes, but when you join, if you modified your lua, it wouldn't match the checksum with the server
No I mean
it will require you to get the mod or be kicked
if you modified your java.class then yeah,
lets say that I'm a comissioned modder
you would cheat
and I'm making mods for a specific server
what's keeping me back from adding the aforementioned "cheat script" to the lua ?
usually no
unless they dont turn on the checksum thing
oh i've explained it better in my last messages
it does a checksum of the file
server and client end stuff is all distributed to both
so it has to match or u dont get in
im not saying if I modify luas on my computer, but what if I'm the modder
aww
u have to trust a mod to install it 
guess ppl need to be awake
by the way does anybody know of a mod that makes you dodge attacks from behind ?
Mmmm nope, just a mod that removes stunlock, and also lower rear attack vulnerability in the vanilla sandox options but not dodge them
Guys. How do you make patches for items added by other mods? Do you need some special code or just add those items into the list on your lua file and place it after the required mod in the load order?
Example: Change the amount of bullets inside an ammo box from Firearms B41 and then change how many of those mod bullets can be stacked when using the Inventory TETRIS mod
'cause I think I know how to change them if they were vanilla items, but I'm not sure if you have to do something different if they are mod added items
you can add the condition: is the mod loaded e.g. ```lua
local modInfoTK = getModInfoByID("TheyKnew")
if not modInfoTK or not isModActive(modInfoTK) then
return--handle : compat not required
end
cool, thanks!
And then it's just a matter of modifying individual items as if I was working with vanilla, right?
yeah but as you do not know how the other mod will evolve check item different from nil before any action
gotcha
well, I keep getting compiler errors in java
and I haven't even changed the code I got from the decompiler 
use different version java?
I'm using Java SDK 17.0.13
that seems right, game uses azul 17.
Evening guys. How do you edit mod added recipes using lua commands?
Got these surgical mask boxes added by the SUSCEPTIBLE TRAIT mod. By default when you open a box, there's 100 of them. I want to nerf it down to 20
im so close to getting it to work
but can't doittttt
PZArrayUtil.sort(this.m_lightsTemp, Lambda.comparator(movingObject, (var0,movingObjectx,lightSourceArrayx)->{
float iterator = lightSourceArrayx.DistTo(var0.x, var0.y);
float lightSource = lightSourceArrayx.DistTo(movingObjectx.x, movingObjectx.y);
if (iterator > lightSource) {
return 1;
} else {
return iterator < lightSource ? -1 : 0;
}
}));
THIS GODDAMNED LINE OF CODE BREAKS IT
C:\Users\Feder\IdeaProjects\FedCap\build\generated\sources\zomboid\zombie\core\skinnedmodel\ModelManager.java:1074: error: cannot find symbol
float var30 = var2x.DistTo(var0.x, var0.y);
^
symbol: variable x
location: variable var0 of type Object
C:\Users\Feder\IdeaProjects\FedCap\build\generated\sources\zomboid\zombie\core\skinnedmodel\ModelManager.java:1074: error: cannot find symbol
float var30 = var2x.DistTo(var0.x, var0.y);
^
symbol: variable y
location: variable var0 of type Object
C:\Users\Feder\IdeaProjects\FedCap\build\generated\sources\zomboid\zombie\core\skinnedmodel\ModelManager.java:1075: error: cannot find symbol
float var40 = var2x.DistTo(var1x.x, var1x.y);
^
symbol: variable x
location: variable var1x of type Object
C:\Users\Feder\IdeaProjects\FedCap\build\generated\sources\zomboid\zombie\core\skinnedmodel\ModelManager.java:1075: error: cannot find symbol
float var40 = var2x.DistTo(var1x.x, var1x.y);
It cannot find the symbols because it doesn't realize they are supposed to be IsoMovingObject
Sorry it's a bit off topic but... how do you paste code in discord to make it show with coloured text and stuff?
you can write lua
```lua
your code
```
thanks
it just changes the keyword highlighting
I know, but it makes it easier to read for others 👍
Congrats!
most fixes been minor things
but this last thing
may be bad
real bad
PZArrayUtil.sort(this.m_lightsTemp, Lambda.comparator( var1, (IsoMovingObject var0, IsoMovingObject var1x, IsoMovingObject var2x) -> {
float var30 = var2x.DistTo((int)var0.x, (int)var0.y);
float var40 = var2x.DistTo((int)var1x.x, (int)var1x.y);
if (var30 > var40) {
return 1;
} else {
return var30 < var40 ? -1 : 0;
}
}));
essentially
I forced all three objects to be IsoMovingObjects
problem is
I dont know what Type they'll be
I also tried with IsoGridSquare, but didn't work
Too advanced 4 me. I barely know how to change item stats in lua 😅
I'm struggling with editing recipes added by another mod. Can't even imagine the kind of challenges that come with working with something like this
Does anybody know if combat animations are hardcoded ?
I mean, I can see building animations and everything else but I can't see attack anims or animation that plays when you get bitten in Lua
we can override the whole combat and add whatever animation so you can override combat animations. that said existing ones are called from java.
ohh alright thank you
under IsoPlayer
WeaponType weaponType = WeaponType.getWeaponType((IsoGameCharacter)this);
if (!GameClient.bClient || this.isLocalPlayer()) {
this.setAttackType((String)PZArrayUtil.pickRandom(weaponType.possibleAttack));
}
i guess this is from java ?
I think I figured some things out, thanks for the help.
mod statistics tracking website should be live in a few days
so mod creators can track their mods and totals
I'm using this one currently https://thejaviertc.github.io/steam-workshop-stats/fetch-user
Website made for see all stats from a Steam User in every game
dang i didn't even know this existed
very similar to what i made
I think my UI is a little better though
Hello! Does anyone have a backup of Dislaik's animation guide?
https://web.archive.org/web/20230404001952/https://steamcommunity.com/sharedfiles/filedetails/?id=2867805604 not rechecked recently : takes a long time to load
Thank you! It works!
A similar question, what should I do for my animation to trigger ? Apparently PlayAnim(string) only works for idle anims, so I made a custom TimedAction but when I try to call my anim with the proper "condition" in the xml file it just plays a generic "raise hands" animation.
maybe i should check this as well
look at Jump mod for an exemple of TimedAction animation (there are many others). the string used must be the KeyString of the XML, the XML refers to the .x or .fbx.
thank youu
do animation files have to be in .x ?
I cannot think of anything other than that, anim file plays perfectly in blender but for some reason console says "anim cannot be found"
or its the annoying file configuration, i think it doesn't see the anim clips because there is no "Bob" folder
So still trying to change the "Canhaveholes" value. How can I get the lua to add the code in-between the existing code. I saw advice to use table.insert but it didn't work.
what code are you trying to insert ?
clothing:setCanHaveHoles(true) ?
Trying to set to false. I just checked the steamapps workshop folder and for some reason the mod there wasn't updated to the changes I had made. Testing it now. Will update once I'm positive whether it works or not.
Is it possible for you to open the code to the public to make other types of card collections?
Did some stress testing, and the armor that's supposed to be immune is still getting holes
Should I paste the lua file to be read?
The mod is designed to accomodate add-on mods.
As an example this is how Uno is added:
--- For anyone looking to make a sub-mod:
---First require this file so that the cataloger module can be called on.
local applyItemDetails = require "gameNight - applyItemDetails"
--- Examples of defining a table
-- this example is overly complicated as it pieces together a table for the sake of typing up a large list
-- technically you just need a table of strings corresponding to textures/names for items
--- UNO
-- (19) Red, Blue, Green, Yellow – 0, 1 to 9 (2x)
-- (8) Skip, Reverse, Draw2 – 2 cards of each color
-- (8) Black – 4 Wild cards and 4 Wild Draw 4 cards
local unoCards = {}
unoCards.cards = {"Red 0","Green 0","Blue 0","Yellow 0","Wild","Wild","Wild","Wild","Wild Draw 4","Wild Draw 4","Wild Draw 4","Wild Draw 4"}
unoCards.suites = {"Red","Green","Blue","Yellow"}
unoCards.values = {"1","2","3","4","5","6","7","8","9","Skip","Reverse","Draw 2"}
for i=1, 2 do --Two sets of 1-9, 0s are single
for _,s in pairs(unoCards.suites) do
for _,v in pairs(unoCards.values) do
table.insert(unoCards.cards, s.." "..v)
end
end
end
applyItemDetails.addDeck("UnoCards", unoCards.cards)
- item script for 1 item, model, and textures
Most of the work would be on visuals
Converted the Lua code to txt:
Morning guys.
Can anyone tell me how to edit recipes added by other mods in Lua?
Or is it just easier to do it with scripts?
Is suites rather than suits intentional?
No, I assumed there's was an e there
I could see it, words of French origin are wacky sometimes (no offense, French)
I assumed it was French too 🤔
It is, and it's actually a doublet with suite 😄
I have an odd request - I need images of what some may call bad comments on steam - could you guys go to this old mod of mine and just post the most obtuse and inane comments. Basically along the lines of "mod no work??" "stop updating so much!" etc.
https://steamcommunity.com/sharedfiles/filedetails/?id=2356478970
Dibs on "mod no work??"
Going to make a graphic on my workshop pages to redirect people off steam and onto github
Not my proudest use of a couple hours
So... I was trying to edit recipes added by a mod. But now they display as 2 independent recipes despite having used the Override:true, command
I'm stuck
Vanilla stuff calls in for Base.item instances
If I wanted to edit stuff added by mods, should I be typing ModID.item instead?
what matters is the module in the script file
mods might not use a module name that matches their mod id, they might use multiple modules, and in most cases they just use base
So all the code is present, how do I get the lua file to run upon starting the game. The lua file is written in notepad btw.
There's a whole file structure involved to a mod - you should check out the template files (although they're a bit outdated/old)
I imported the base items into my script just as the mod did. When testing, the recipes are duplicated, each with their own amounts despite having used the ovrride command
in notepad yo 🥹
What's the best way to test if your mod will work in MP quickly? Can running local co-op work or do I need to rope someone into helping me?
hi, so, im trying to use a client command in a mod, as follows:
function Commands.knockPlayerOut(playerName)
local playersList = getOnlinePlayers();
for i=1,playersList:size() do
local playerItem = playersList:get(i-1)
if playerItem:getUsername() == playerName then
local playerIndex = playerItem:getPlayerNum()
ISTimedActionQueue.clear(playerItem)
--ISTimedActionQueue.add(Knockout_TimedAction:new(playerItem, playerIndex))
break
end
end
end```
The command is sent using:
```lua
local function forceKnockout(button, args)
local playerName = Knockout.selectedItem
sendClientCommand('RealKnockouts', 'knockPlayerOut', {playerName})
end```
Unfortunately, this returns an error of
```lua
ERROR: General , 1694371213145> 21,360,901> ExceptionLogger.logException> Exception thrown java.lang.RuntimeException: attempted index: clear of non-table: null at KahluaThread.tableget line:1689.```
I have multiple tests and made sure there are no problems with the parameter I am passing to the command, so not sure what's going on here
looks like you tried to use ISTimedActionQueue on server side. did you put it under server or shared subfolders ?
TimedActions are client side.
erm nope. I thought it doesn't matter in terms of folder structure?
client does matter
I do not understand you
it's only client that does anything special, otherwise it's just load order
server runs on clients but client doesn't run on servers
so -- It should work correctly if I move the timed action file to the server folder?
What I meant was that I thought the folders didn't have any actual functionality rather than organisation
the timed action queue is a client object
ok, everything does not run everywhere. see Albion's answer for the details.
you need to send the client a message to start the action
on the client only the local players' queues exist, on the server no queues exist at all
aah
👀
yay
so how does one exactly send a command from the server to the client to reset a queue/start a timed action?
basically the same way you're sending a command to the server
btw, you can send the target's onlineid and get the player object from getPlayerByOnlineID
searching with username is slower and iirc usernames aren't even guaranteed unique on steam servers
local player = getPlayerByOnlineID(id)
sendServerCommand(player, command, module, args) -- if you want to support splitscreen args should include the online id, since the receiving client won't know which specific local player it's targeted for
Alright, will give that a go. Appreciate the time and help!
Not sure If I am implementing it correctly (haven't gotten to the PlayerID yet), but:
local Commands = {}
function Commands.knockPlayerOut(playerName)
print("test")
local playersList = getOnlinePlayers();
for i=1,playersList:size() do
local playerItem = playersList:get(i-1)
if playerItem:getUsername() == playerName then
local playerIndex = playerItem:getPlayerNum()
ISTimedActionQueue.clear(playerItem)
ISTimedActionQueue.add(Knockout_TimedAction:new(playerItem, playerIndex))
break
end
end
end
local function OnServerCommand(module, command, player, args)
if module == 'RealKnockouts' then
Commands[command](args[1])
end
end
Events.OnServerCommand.Add(OnServerCommand)```
This basically doesn't do anything except printing ping pong statement
how do you call InventoryItemFactory? i'm trying to add & remove items to player's inventory
all of its methods are static so you can call them directly e.g. InventoryItemFactory.CreateItem("Base.Apple")
but that's not a necessary step in adding items to a player's inventory
if you're just going to add it to the inventory afterwards you can just call AddItem("Base.Apple") on that inventory object
function remove_arena_weapon()
local player = getPlayer();
local inventory = player:getInventory();
local item = 'Base.HandAxe'
for item in ipairs(inventory) do
print("PlsMan")
if item:getFullType() == 'Base.HandAxe' then
itemUser:RemoveItem(item);
end
end
end
I'm trying to remove certain items (hand axe as placeholder) from player inventory. This doesn't do anything, Can anyone help?
@bronze yoke any idea why arendameth is having these ping pong printing issues
.
OnServerCommand handlers only have three arguments
String module, String command, table args
shouldn't you be using inventory:Remove(item)?
oh i see, thanks!
Dunno, hard to find the right method since i know very little
What i'm trying to do is, Iterate over the player's inventory and remove any of the specific items i add to a table.
RemoveItem doesn't seem to exist
its np you get it by practise. Over one year here and still have barely any grip on the methods lol
i pulled it from here if it helps https://zomboid-javadoc.com/41.65/zombie/inventory/ItemUser.html
oh, weird, never seen this class
btw that's a pretty outdated version of the docs, use this one instead https://projectzomboid.com/modding
they're static so you would call it as ItemUser.RemoveItem(item), but not really sure what this does or if it's even exposed
i'll cross that bridge when i get there, i need to first figure out why it doesn't iterate over the player's inventory
time for a lot of head bashing, i heard it works wonders.
oh, well that's because ipairs is used to iterate over lua tables
inventory is a java object
you'd want to get the item list from the inventory object and then iterate over that as an array
it still keeps ping ponging with nothing more done :')
can i send the sending code?
um what
where are you sending the command
local function forceKnockout(button, args)
local player = Knockout.selectedItem
sendServerCommand('RealKnockouts', 'knockPlayerOut', {player})
end```
oh, are you just trying to send a server command from the client?
what Im trying to achieve is, have a player remotely activate a timed action on another player
you can't do that - the only way to send a command to another client is to send a command to the server which then sends a command to that client
Figured that out, which is what I have been trying to achieve past 2 hours or so with no luck 
so basically, use SendClientCommand from player one
-- then what?
sendClientCommand from the sending client, then a client command handler on the server sends a servercommand to the target
Sounds simple enough. Thanks!
======
Still working on this issues guys. Maybe you know what I'm doing wrong. (Sorry to interrupt)
This screenshot here is from the orignal mods adding some recipies to add boxes containing surgical masks, but when you open them it gives you 50
I wanted to change the amount of masks to 20. I wrote another script using the override command
module Susceptible { imports { Base } recipe Open Box of Face Masks { destroy MaskBox_Blue, Result:Hat_SurgicalMask_Blue=20, Time:5.0, Category:Misc, Sound:PutItemInBag, OnCreate:OpenMaskBoxBlue Override:true, } recipe Put Face Masks in Box { Hat_SurgicalMask_Blue=20, EmptyMaskBox_Blue, Result:MaskBox_Blue, Time:5.0, Category:Misc, Sound:PutItemInBag, Override:true, }
However, when I test the mod out. the game gives me both the original recipe from the mod AND the one from my file. I thought it was supposed to replace it. I dont't get it
i think stuff like override is handled when the game reads that line, so maybe try putting it at the start of the recipes instead of the end
I'll give it a try, thanks
but still inside the brackets or the line above "Recipe"?
inside the brackets
Sup! does anyone know if there is any way to handle the network class zombie.network.DiscordBot?
!rank
🚫 whitetailwolves, that command is disabled in this channel.
So, i have this code to actually teleport a player with a command, but can't make it work, any advise?
local Commands = {};
Commands.Test = {};
local function onClientCommand_Test(module, command, player, args)
if Commands[module] and Commands[module][command] then
Commands[module][command](player, args);
end
end
Events.OnClientCommand.Add(onClientCommand_Test)
Commands.Test.Teleport = function(player)
player:setX(11746)
player:setY(923)
player:setZ(3834)
player:setLx(player:getX())
player:setLy(player:getY())
player:setLz(player:getZ())
end
Using it like this:
sendClientCommand("Test", "Teleport", {player})
You can't send 'player' as client command argument.
Should use something like onlineID
sendClientCommand("Test", "Teleport", {player:getOnlineID()})
Sure, will try, thanks
I'm afraid it didn't work.
The name of the script file doesn't have to be the same as the original, does it?
I do use player as argument when sending to my print command tho, so should work.
But even doing it as you said, does not work. Weird thing is, there is no error xD
That's because the function do not use the argument you sent.
If you want player to teleport, send Server Command to the player you want to teleport
if Commands[module] and Commands[module][command] then
sendServerCommand(player, module, command, {})
end
end
Events.OnClientCommand.Add(onClientCommand_Test)```
Teleport the player on client side
I'm asking just in case, did you load your script after the original mod?
no, it will cause problems if it is actually
Hello its me again, does anybody know of a way to get the closest zombie to the player in an efficient way ?
I've tried "getVeryCloseEnemyList()" and also "getClosestZombieDist()" but none of them worked
I am about to give up, I made one recipe for a modded item which works flawlessly, I can also still change it a bit, but another recipe I added below never gets loaded despite being identical in structure. I even copied a working recipe from another mod and that one also somehow does not work when it is in mine
Can I see the file
I've also been bothered by it for a long time
Just shut off the PC since its late. I can show it to you tomorrow tho!
Sure, would like to help.
yes
What I can say my second recipe that doesn't work is a replacement for crafting vinegar. I wanted to test it first so I took the same structure from my first already working recipe and just replaced the single input item to Stone and the result to Vinegar. Still, it won't show up :/
Anyway, night night yall
now, why?
So I was able to find a version of Lua for my computer and when I run the script it keeps trying to define to lua file itself but gets a nil value. How to I make the script execute upon game startup and not search for a value for the lua file.
There's alot to unpack in what you said... but you don't need to 'find' a version of Lua for modding. The file is ran upload Lua load yes, if you're calling anything it will run during load otherwise it is defined to be called later.
To have stuff occur you mostly have to use game events which are defined by the devs - for game start there are a few depending on what you need.
Anyone make a container that has loot inside of it in the distro?
I'm using FirstAidKit as an example - and I don't seem to net any loot
Never messed with distros as they seem to be super flakey - and sure enough
are you spawning it or testing natural spawns? i think spawned containers are always empty
natural
did some whacky stuff to replace the vanilla game items with my boxes
in the distro
but it doesnt seem to fill the containers
chance for items are 9999
the format is SuburbsDistributions.itemType right?
Backgammon?
I feel like I get the whole SuburbsDistributions vs other one mixed up
interesting that loot zed doesnt have an option for bags
I need a Hero PLZ
https://steamcommunity.com/sharedfiles/filedetails/?id=2959205557
Hey everyone, huge update 2.0 for I Hate Stuart Little is now live. Hope y'all will check it out and enjoy it. There's lots of new features and improvements all around 🙂
Please, I'm so close to making it work flawlessly. has anybody experienced this issue with any mod before?
does anybody know which lua and classes are part of the Info Window (specifically the place where it renders the player)?
Figured out the issue @bronze yoke
I was inserting tables with no keys
Seems like the 9999 chance works
nice! it's just a roll against that number so in theory as long as it's high enough to compensate for loot settings any high number should be 100%
I prefer to slip into the vanilla distros when I can
Hate seeing the loot tables getting overwhelmed
This is spectacular.
Everybody's favorite family mouse loves you back. 😛
❤️ ❤️
Thank you very much!
i hjate him
what did he do to deserve this
Still calling him a rat despite him canonically being a mouse ||(or a mouse-looking human, in the original work)||, shame
is there a way to reload textures of your own mod ingame?
so when you changed them you dont need to restart the game everytime?
Hey guys! Did any of you tried sending messages to Discord through webhooks? Maybe using openUrl()?
Hey modders, I need advice on making a moveable item. I see my custom tiles in the debug tile picker so my texture pack is added correctly, but how do I make an inventory item become placeable and use those tiles?
Could anyone give any advice for adding a non-binary option to the character creation screen? How do the models work with gender? Do the male and female character models have unique meshes for every kind of clothes, and will I then need to make new models for every single clothing item?
If anyone complains about this idea than I will slap you with a fish
i mean, what would a non-binary option actually do? the game never refers to you by pronouns as far as i'm aware, i'm pretty sure it's effectively just a body type selector
if you're suggesting a more androgynous body type... yes that is exactly the case, good luck
this would be it, yeah
fuc
well, it’s something to do
you'd also need to java mod
oh yeah and a lot of it is just the explicit mention of “male” vs “female” (words I don’t like that much in the context anyways) for character creation, which is tiny and not that big but y’know even the smallest things can screw up immersion
the renderer picks the character model based on an 'is female' boolean, and lua can't change it at all
literally perfect - dont change a thing
I figured the moveable thing out, though now I'm curious if it's possible to prevent a moveable from being placed on the floor - either the isTableTop property on the tile does nothing or I'm stupid
start from romania and go all the way to china, every country plays backgammon
i'd recommend you inspecting the moveables.txt in the game's scripts folder
Does anybody know how to convert an object's position local to another object ?
I want to know if a zombie is in front of or behind the player
i don't know the mathematical formula for it neither lol, maybe i should search for a mathematical solution
For relative position I believe all you'd need is subtraction, but for determining “in front of or behind” you'll also have to consider the direction the player is facing
exactly, I was actually modding in Gmod lua and it had a entity:toWorld(vec) function in which you entered a local vector inside and it converted that local vector to a global one taking the entity's rotation into consideration
However, I don't know if there is a similar function in Zomboid, so my best bet is to replicate it in a function by myself but i don't know the name of the concept.
Can anyone help a noob out? You can DM me if you don't wana blow chat up.
isn't floor just a big table?
seems like it
Ola i need help
can somebody make a mod where i can butcher and cook zomboids so i can provide food for my friends
I remember someone telling me to inserting functions while in-game
through lua console
how was that ? I think it was something like Events.Event.Add(func) but just inside the lua console window ?
anyone know what is called when entering this screen?
or can i at least call something similar
Could someone explain this to me?:
lua -e "io.stdout:setvbuf 'no'" "Armor_Durability.lua"
You can run Lua in the console in game yes - but this is code that's held in the session and then gone after. It can be useful for testing.
I've never seen such a message before, where do you see this?
You can tweak the vanilla Lua files to get more familiar with Lua
If you want to package your changes as a mod you need to format the files as in the mod template
Are you working in an IDE, notepad++, vscode?
I saw it appear in the debug menu after hitting go to run the file and check for errors.
Debug menu being the F11 error window?
I was using Notepad but am using Lua now
The interface
Windows has a version of lua that is an app. It looks like a command window
I don't know what that looks like, but it sounds like you are better off using notepad++ and a Lua extension 😅
I personally use IntelliJ for modding - but I understand if that's overkill/daunting
I had originally made the Lua file in notepad. But none if the scripts I had wanted it to change were being edited.
(VSC on top!)
My setup is IntelliJ + EmmyLua plugin + CAPSID (outdated annotater for PZ)
would calling applySettings() do something close?
I don't want to be rude, but it feels like you're misunderstanding how the files work - or maybe I'm misunderstanding your explanations.
@faint kestrel
Most things you write for lua will not work in PZ, same applies in reverse.
I probably am tbh. Still new to this
You made a Lua file in notepad and had it where? In the install directory/media/Lua/subDirectory?
Nope, been trying to make a mod to edit the scripts for another mod. (Don't want to copy, tweak, and re-upload someone else's work)
Ah, so you're patching script items with Lua
Yes
Fun times. Watch out for Item.Type. it's the item's subclass. Use Item.FullName
hi, is ProceduralDistributions the method that adds loot to zombie corpses?
I wrote it to enter a new line of code on a given line. If I want a particular clothing item to not break I make it add "Canhaveholes = false"
But when I check the file the script isn't changed
Don't think about editing the files. You can't do that
You can modify the items after they're loaded from the file as scripting.Item objects
So if I want the lua file to modify a txt script it needs to occur once they appear in-game?
You cannot modify the txt file. You can however, modify the data loaded from the file after it's loaded
Okay
ScriptManager lets you get Scripting Objects
I had ScriptManager entered in the lua file but it kept trying to attribute a value to it and spat out nil
ScriptManager.instance is the reference to the... instance
ScriptManager.instance:getItem(String name) is how you can get your item
Thank you. I kept looking for a good tutorial but none actually just said how to do this
I recommend loading the lua file in media/lua/shared
That is where I put it in the mod folder
yes
I meant that as in yes, that's where it already was
Okay
declaration: package: zombie.scripting.objects, class: Item
This is your home now
Thanks for your help
Question: if I want to add custom tiles to the game, I will have to pack them into a .pack file?
Welp, I've had my first taste of modding and now I will subject myself to more: I am going to attempt to make a tweak for Brita's.
More specifically I'm making a tweak for Gunfighter, not Brita's itself.
Time to figure out how to make a mod require another mod...
is there a pinned post or something that shows how to add loot to zombies?
@faint kestrel Not wrong here, but getScriptManager() gets the instance.
Also I wasn't aware what you're trying to do - that's somewhat advanced for just starting out.
You can safely overwrite scripts by using the same ID type and writing overwrite=true -- this is done as a .txt
But you'd need to include the entire script that way -- otherwise doParam and script manager are the way to go about changing 1 thing
Hey, I wrote a script that detects jarred foods based on the crafting recipe as my first project
And complexity doesn't equal scope
Yeah but there seems to be issues with approach
Might also be a good idea to open up ItenTweaker as an example
You can study how mods are structured
- it does what you want - although I don't know if it was ever updated to be in shared as opposed to only client
I just set up a new lua file using ScriptManager.Instance:getItem("Base.'item_name'") and doParam(canHaveHoles = false) this doesn't turn up any errors but "attempt to index global 'ScriptManager' (a nil value)" does appear when I press 'run'
Do param takes a string
I would use getScriptManager() instead of using the instance like that
ItemName shouldn't have quotes if that indicates you're using them
Is that the exact error?
What do you mean by run?
There is a button called 'run program' if something is missing or doesn't work it gives feedback
That error isn't how PZ would declare that issue - and by saying run - I assume you're compiling the Lua file in your editor? That won't do anything to the game, and won't impact a session already running.
Okay, good to know
You have to reload the Lua in game, you can do this in debug mode
Or simply restart the game
Should I remove quotations from just the Item ID or the Parameters too?
getScriptManager():getItem(itemName) is there a way to get every item?
You might be able to use tags
Yes, you use getAllItems
Both doParam and getItem take strings as their argument/variable
should of seen that one coming ngl, guessing it returns a table?
ArrayList actually
so i have to itterate over it?
It's an exposed java ArrayList - so any exposed methods work
You can iterate over it using size and get
Contains works where applicable
ahh okie, so a simple i, v in pairs will work to itterate over it to get all values
Should the lua file work on game startup itself or do I need a line of code so it will run?
I've tried Event.OnGameBoot and os.execute
Everytime the game shows 'Reloading Lua', all the files are executed, and if your mod is active, it executes your files too.
os.execute don't work in Zomboid iirc
Using OnGameBoot you can define a function to run
Remember that the file is executed, but every function you declare will only be declared. If you want the content of a function to run, you need to call it somewhere in your file
No, that works for lua tables. To iterate over a ArrayList, it's similar to this
for i=0, myList:size()-1 do
Your code...
end
If you want to get the value it is in now, you use myList():get(i) and handle it as you want
Hmm, seems the item tweaker API should be able to handle what I'm attempting to do, assuming it can adjust modded items and modded values. Still gotta make it require the base mod though.
Ah now here's an issue, I've no clue how to format the file organisation, I know item tweaker API mods need to be lua but I've no clue whether to just put them in the mod's lua folder raw or in another folder...
I guess we'll just raw dog it and see what happens
If I want the lua file to change in game parameters for select items on startup and run the whole file, what would that look like in code?
just put the file in lua/client/, lua/shared/ or lua/server/
files execute upon lua loading/reloading, you don't need to do anything special
It's already there
But he did just say functions need to be defined and called
functions that you define need to be called to run
if your code isn't in a function it runs when the file executes
I have the following code written repeatedly with different Item names
local scriptItem = ScriptManager.instance:getItem(Base.Armor_Dozer)
if scriptItem then
scriptItem:doParam(canHaveHoles = false)
end
I looked for many tutorials online if this is written wrong
Well, you need to put the name in quotes
pass a string
Same with the contents of doParam
Earlier I was told I didn't need to...
They were wrong
DoParam should be capitalised too
stuff outside of quotes are markings. Inside are string literals
Does 'false' need quotes too?
Yes, the entire thing in quotes
Okay, all string names have quotes and all doParam(s) were changed to DoParam
Should the fie start with Event.OnGameBoot.Add(ScriptManager)?
No, it should not.
As albion said, if you did not put anything inside functions, it will execute when Lua gets loaded, you don't need Events for that
I just don't know for sure if the Item Scripts are loaded before Lua is...
they are
So yeah, just writing all those lines on the file should work
Okay, I removed that code. Hopefully this works
Reloading lua...
Starting new world, clothing degradation: normal
Loading...
Loaded in, going to stress test armor
Mod didn't appear in Steam folder, retrying
Mod is now in folder
Resetting lua again to be sure
steam folder?
that's only for mods installed from the workshop
local mod development isn't done from there
I have it in both locations local files and Steam to make sure it's everywhere it needs to be
i would not recommend doing this or you'll have to update all versions every time you change something
Hey, does anyone know if there is any way to take screenshots?
Mod didn't work armor got a hole torn..

Is this a trick question?
Not tricky, im doing an anti cheat, it's working great. But would like to add some way to look at the user game screen if he tries to apply god mode (example)
@atomic crow
I've seen takeScreenshot method, and TakeScreenshot, but couldn't make them work correctly. If anyone tried before, would be helpful
I’m pretty sure both of those save locally rather than to a server side source.
I can show the anti cheat code if necessary, very simple but effective.
Yeah but
Couldn't I take the screenshot and then upload it?
If you’re the one on the receiving end of the anti cheat sure, but if someone’s actually suspected of cheating it wouldn’t be hard to hide any wrongdoing
Maybe uploading it through a discord webhook?
we don't really have access to stuff like that
We can't send messages through a Discord webhook or we can't upload a screenshot?
I've been experimenting with JNI modding, external is easier. But I wasn't people to use some kind of launcher to enter the server, would like to make it as a mod.
Sadly, internal (mod) makes it harder since you only have what the games wants you to use
as a lua mod?
Yes
a lua anticheat seems a little pointless, any cheater can just read the source and disable your anti-cheat pretty easily
Yeah, with JNI ive done that before
But, that's not my point at all
Even if it can be hooked and disabled
Would like to add an extra layer
i don't really believe it's possible, if the screenshot ends up in a folder lua can access (which feels unlikely to me) you can read the image file and send the entire raw data as a client command but i can't imagine the network performance is acceptable on that
Hmm, uh, are there any repercussions to an item having negative encumbrance?
Because I have accidentally achieved this somehow
Uhm, thanks for the info
no, it behaves sort of how you'd expect (reduces the used space in the container) but it's been specifically announced that in b42 this will not be supported anymore and will break things
And, have you tried sending messages to Discord through the server integration? (I think this is impossible but I'm unsure)
Ah, okay so I'll have to update my mod when that happens, until then I'm fine with this though.
never tried, but it never looked like something that was really exposed to modding (or even maintained at all)
As far as my knowledge goes, it reads the /all chat and sends it to a discord channel
Yep, thanks. Been trying to use it (couldn't), when I failed I tried to send messages through a discord webhook but failed too since I can't do any POST with the game API
Yeah, that's what it does, but would be good if we (as modders) can access the "sendMessage" function
Imagine sending your server logs through it.
Yeah...
We wanted to make a bot that sends the active player list and current weather and time to discord
Not possible without writing to a file
Trying to do it without mods?
Yeah
But you have to write a mod that saves the info you want to a file first
Can't even send it over a loopback ethernet connection
Couldn't you mod the host java client and then expose the information? I'm unsure if that could work, but in local you can mod your client and enter any server
yeah there's no java validity checks or anything
I don't know any Java, so I can't make a java mod. It is possible to write a Lua mod that writes to a file
And then an external program can handle the rest
Right now I'm trying to figure out how to make a barrel be able to be filled with liquid
Yeah but if you wasn't to add mods to the server, that's not an option
Without mods, my players can have maxed out panic reduction Day 1 since it's bugged
And can't patch holes in their damn backs
Dumping the info to a text file and having a discord bot pick it up isn't that crazy of an approach
You'd need the bot and server to be hosted on the same machine or able to access the file though
But he does not want to use mods
Or connect to the host
It's not crazy. what is crazy is that it's the only approach you can do
Oh well... then it's not a supported feature 😅
Im working on a render pipeline remake mod (Java) that’ll allow for real-time per-pixel lighting, improved graphical fidelity (SSAO, SSR, SSS) and dynamic shadows
Yeah, twitch integration is no better
Actually that's a lie - there's two ways to do that
is there any sort of HTTP interface in PZ Lua?
Nope
yikes you’re out of luck for lua then
Lua isn't really the place to make render engine changes tbh
Not sure why the lua file didn't work. Wondering if the game overwrites the changes made to the armor. Or the changes just aren't being made
nah all my stuff is Java
Where is the Lua file?
Are you spawning in an instance of the armor after you load the mod
Because editing the scripts files, changes won't apply to existing items
I have the armor saved to a character preset and worn after starting a new solo game
The file path?
And you start the new game each time?
Yes
Yes, being you were using an Editor and hitting run - I just want to confirm it's in the right place to be loaded
Wait, where is the weather thing saved? Isn't there any db or something?
Client manager has all the data
Uh... If you want to read the save file of a running game, be my guest
Climate*
Hey, do you know of any mods that implement tiles with custom behavior?
Peeling info out of a save for weather 🤔
I have it made in the local zomboid workshop folder, and upload the changed mod to Steam. When subscribing the lua file goes where steam puts other mods
Is that saved... where?
Custom how?
You know how generators and composters and campfires have custom behaviors attached to them? They're done internally via Java. You can do stuff via Lua, but it's uncharted territory for me
There are two ways to get this info - have the server print the info using Lua to a file -- or you have to scrape through the world saves...
a lot of it is lua
I want to have a tile that the player interacts with to do something not doable in vanilla
they use lua global objects
I mean, my stores mod does stuff
well generators don't, there's stubs for them so either they used to or were planned to
Is... Is that necessary? I saw FuelAPI doesn't use the global objects
I know, I know
I know there's enough stuff
I just... Need more examples to make my own
it depends
That's all there would be to it, can you give an example?
assume those are used so that the tiles process while no players are arouind?
fuelapi doesn't use global objects because it really doesn't need to, it just needs to keep track of a number
The best approach to that is to have it calculate the time difference
So it updates when interacting - unless there's a visual component over time -- then you'd have to actually check it more often
I can look at how it’s done when I’m home
when possible yeah
Well, I do want to store a number on one tile... The other I will want to put items in via a context menu, and have it produce something after a time
You can generate context menus on the fly
Yes, I have made a context menu
rain barrels are fully lua afaik, the purpose of using a global object there is because they need to fill while it's raining, not just based on time
So I should... Analyze Rain barrel code harder?
The stuff in java is holdovers afaik
not quite sure if traps and campfires make full usage of it actually, not sure what they do that can't just be done with time since last loaded
I mean, if they had made them now it would probably all be lua
Yeah, and sadly a lot of the mechanics date back to sprite-based game
many items are built off of templates in Java
I can't really do Java mods, but... If you know how, I would like to get acquainted
IsoObjects are really open ended and exposed - you can do virtually anything you want
I do Java mods :) but there is possible a method exposed that’ll get you what yu want
What bug?
Mind if we do DMs?
Does DoParam: work if the value isn't defined in the item script?
Javadoc Project Zomboid Modding API declaration: package: zombie.iso.objects, class: IsoCompost
VOIP not working due to some security changes in 41.78.12
I just want to undo that change to make VOIP work again... But I can't get a file to compile
i'm kind of shocked they left it in that state
I don't believe so, and if it does it would get added to ModData
They did...
i know they had to pick a time to just focus on the future, but that seems like a crazy significant issue to me
VOIP is broken?
Yes
Since?
last year
Last it worked was 41.78.7
you can't hear players on radio who haven't been within your cell at least once that session
Hmm, I could have sworn I've seen streams with VOIP on ... but idk
Ooh the radio thing
because of the security improvements
Ah, that would explain it
Because... I think it's a client side change
Clients simply clear their list of players occasionally now
Simple solution, make everyone an admin while mic activity is detected 🤓

So if DoParam: doesn't work without the variable already be present in the script, how can I add that from a lua file?
Unless something went wrong with decompilation, I have ~40 files in differences
you only need to get one class file to compile and replace the .class
Hey, mind if we chat in DMs? I can send some links
Yeah I couldn't do that
i'd be somewhat surprised if it were an exclusively client side change, changing the client isn't really a good way to enforce security, especially when there's no client validity checks
^
Again... about 40 files difference
it’s likely more complex than you think
it does work without the variable already being in the script
also it’s wayyy more than 40 files
But the server side change we found ddin't do it
Okay, so the question becomes if the lua script is correct. Why does select armor still break when canHaveHoles = false?
Well... Again, I tried decompiling both versions and comparing them directly
could be something erroring, could be the file isn't loading, idk
check the log for errors, throw a print into your file to make sure it's actually being executed
and what’d you find?
sophie, mind if we take this to DMs? I don't want to share links to code
Eh I will later, sorry I got work to do
Okay... I just don't want to lose you
lua: Armor_Durability - original.lua:1: attempt to index global 'ScriptManager' (a nil value)
[C]: ?
You can copy the whole Script entry of that Item, then edit it on your own. (Add your tags etc.)
Add your edited .txt to the media\scripts folder and make sure your mod loads after the other (if you are changing a mod item)
You don't need Lua if you just want to change some items
all i'll say is if it really does turn out to be a client-only change, reverting it will only re-introduce the awful hacking exploits that justified breaking it in the first place
I could but then it would just be a slightly tweaked re-upload of someone else's work. Which I don't want to do
Well, if you use Lua, you are doing the exact same thing (just in a different path)
The ending is the same, you are editing someone else's work
It is editing. But if I went with the other option I would be taking the whole file instead of adding 1 value to each item.
You don't need to take the whole file, just the item you want to change
The .txt you will make don't need to be the same as the exact same as the original
doing it through lua is preferable as it doesn't introduce compatibility issues on nearly the same scale
Inside the scripts, there are lots of entries for each item, you just need to copy the entries of the items you want to change
I agree
But, if he's getting problems with it, maybe will be easier with scripts
I personally would just use ItemTweakerAPI
is this output from your lua program? this doesn't look like a zomboid log
Yes, but it's the only error, so I don't know why else it wouldn't be working.
it's the only error because it stops running when it reaches an error
...
ScriptManager is nil because your program is for writing standalone lua programs and scriptmanager is from pz
running it in your program will not accurately test it as a mod
I know this, but it didn't have the desired outcome in the game.
I've tested it each time I've made a change to the file
You didn't got any errors when loading the Lua?
You can check it better by putting a print(something) in your file, if it works, that will get printed to the console.txt file
You can put it maybe on the end of the file, if it prints, means that all your lines got executed without errors
I always put a tag to find easier with Ctrl+F, something like 'MODTEST: '
Okay starting up game. I just have to reload lua to see the mod file in console.txt?
Yeah, if the print works, after reloading Lua you can check if it appears in the console.txt
What file path is console.txt under?
Users\YourUsername\Zomboid
You said that you was uploading to the workshop every change.
If you want, there a mods folder under \Zomboid for local mods, you can put your mod there to test without needing upload
But you'll need to unsub from the workshop
Cannot find "Data_Value_Changed"
What is that?
The tag I chose
Is it possible to somehow tie animation time to skill level, trait or something like that? For example, so that the animation of a character getting up from the ground will only speed up if he has a certain trait or a certain level of fitness skill
Did you put it inside quotes?
print() excepts strings, if you put without quotes, it's looking for a variable
If the variable don't exist you get that error
Retrying
It was inside quotes
Well, if the print is returning a error, at least it is running
Means that every line above it got executed correctly
No error, the filename didn't appear
Filename?
The lua
The console.txt doesn't print a filename
It prints literally what you put inside it's bracket
It shows all other filepaths
Like print("I like apples") will print a line in the console.txt with the text "I like apples"
console.txt is the whole log of Project Zomboid, it gets reset everytime the game opens
changed it to print("APPLES")
You need to either edit a vanilla file or have a mod with your lua in it, where is your lua file located?
In the Steam workshop folder, and the Zomboid Workshop folder
In an appropriate file folder structure?
Yes, same file structures as other mods installed
Is your mod showing up in the mod menu?
You should only have it in 1 place
Can you take a screenshot of your mod's folder directory with the file path at the top visible?
you can blur or write over your username if you wouldnt want that shared
Also, just to clarify - you dont need to compile lua if that's what you're trying to do in that program. For the most part lua is plaint text.
I am getting the impression you have prior experience programming?
file path is
ThisPC > C:\ > Users > username > Zomboid > Workshop > Armor_Durability_Patch > Contents > mods > lua > Armor_Durability - original.lua
you need a sub directory under lua
client or server or shared
oh yeah that too 😅
the file structure for workshop is partly the steam conent package - everything in the mods/ folder is the actual modules the game can read
So ...mods>shared>lua>shared>Armor_Durability.lua?
I actually found out the game doesn't like non-folders in the mod folder
Not sure what you experienced
I made a copy of the modTemplate folder to explain that the workshop package can house multiple modules (sub-mods / optional mods in some cases)
There's a rather large learning curve so some of the terms because multiple things use the same term
Doesn't help there's two ModTemplate folders
Yes but everything after that is wrong
What should be in contents?
a folder named mods
Yes, have that
I should rename the folder in mods to ModTemplate?
your lua files need to be inside of one of the 3 sub directories in the lua folder, in the media folder, of one of your mods
The images above showcase the folder structure - I renamed the workshoppackage folder for the sake of readability
It may seem complicated but the structure is to allow for multiple mods under the same workshop package
Are you familiar with programming prior to this?
Idk if that question was read/answered
Okay, I changed the structure, it is now
PC > C:\ > users > username > Zomboid > Workshop > Armor_Durability_Patch > Contents > mods > ModTemplate > media > lua > shared > Armor_Durability.lua
I did some html coding but that was a long time ago. Just got into lua
That looks right - you can rename the modtemplate to w.e.
You should see your mod appear in the menu
if the mod.info is correct
Game is booting, once it's done I'll close it and check the logs.
It has appeared in the mods tab of the game. Just didn't work.
I can't imagine that being the case given the folders were not in the right place
No clue
Did you change the mod.info stuff?
if you have the original modTemplate still present they may overwrite
It's place or what's written?
or well conflict
what is written, you should give it a new ID
So you're expecting to see your mod as modtemplate?
Ah ok
And when you try to test it - you boot up the game and then?
check the logs?
Yep
Is it enabled?
The logs?
the mod
Game is still booting
Yes, but have you been going into the mod menu to activate the mod?
Yes
And you see the lua reload after?
Yes
But your print of apples doesnt appear?
That was a recent change, but no
If the file isnt large can you paste it here?
discord can format code if you use
```lua
code
Is it possible to somehow tie animation time to skill level, trait or something like that? For example, so that the animation of a character getting up from the ground will only speed up if he has a certain trait or a certain level of fitness skill
Yes, but messing with animation xmls like that is not well documented
Console.txt says "attempted index: getItem of non-table: null"
Could you please tell me some information about this that you know, or maybe you know a mod that does something similar?
There's a method for IsoGameCharacter called SetVariable() that sets vriables for xmls to read and interact with
You can see this being done with some vanilla files
I've only sparingly used it to make unique seating animations in cars work, to make sprinting zombies incapable of tripping, and disabling trees from damaging you
If combat helps swing speed you could check the attack animations
the vanilla file might already do what you'd like
Maybe the problem is here
this is good - this is an actual pz error - but it also means you're not getting scriptmanagr properly
If this is the current code, you should do getScriptManager()
Also, if you're just leaving it in the lua - if it runs on load before the scriptmanager is loaded in - there won't be an instance of it ready
You have to hook your functions on exposed events
Where would I add that?
So maybe .OnGameStart:getScriptManager()
local function MYFUNC()
---code
end
Events.OnGameBoot.Add(MYFUNC)
Are you familiar with what functions are?
If you just have calls made in the lua file outside of functions the game will attempt to make those calls when the lua is loaded
You can make a local variable like local ScriptManager = getScriptManager() on the start of your code
Then you can replace every ScriptManager.instance to ScriptManager
But as @sour island said, maybe the script manager will not have a instance yet
If that's the case, you will need functions and Events also as he said
If you need some basic knowledge of how tables and variables work in Zomboid's Lua, there's this very good guide by FenrisWolf
https://github.com/FWolfe/Zomboid-Modding-Guide/blob/master/api/README.md
I added lua_load as the function
the script manager is available before lua loads
all scripts are read before lua
Then he probably has a typo
you can sit in any direction now
Just curious
no problem 😄
thanks for the advice
You're syntax is busted
On line 4
Armor_Durability - original.lua:4: '<name>' expected near `:`
file name : line : cause
you probably have a : where it's not supposed to be
maybe a space before it
Should the code be ScriptManager.getItem?
is ScriptManager a variable you're defining?
otherwise it should be getScriptManager() as the object
exposed methods are called using :
ScriptManager.instance is acceptable too
getScriptManager():getItem(TYPE)
Yes, but I think using the intended getters is "cleaner"
Current Code
local scriptItem = ScriptManager.getItem("Base.Armor_Dozer")
if scriptItem then
scriptItem:DoParam("canHaveHoles = false")
you have to call the getter for script manager or use the class.instance
ok, then it should still be :getItem()
What does the function look like that this code is in?
lua local function lua_load()
I don't know why I wrote lua, it's not in the code
can you paste the entire function?
local function lua_load()
local ScriptManager = getScriptManager()print("APPLES")
end
Events.OnGameBoot.Add(lua_load)
there's suposed to be a linebreak there, between () and print
so where is this:
if scriptItem then
scriptItem:DoParam("canHaveHoles = false")
?
That is after local ScriptManager = getScriptManager()
Line 4 was local scriptItem = ScriptManager.getItem("Base.Armor_Dozer"), it looks like ".:" was left in the code after I removed "Instance" from each line. So each line should now have a colon instead of a period between ScriptManager and getItem?
Hey guys! I'm new here.
I've been diving into PZ modding a bit deeper lately, and I was wondering if there is more info somewhere about ModData, or maybe mods I could look at to see how it's used.
I've been able to use it successfully for my needs with items, but I also need to store some data on the player (or globally somewhere that persists when closing the game). For some reason modData that I add on the player does not seem to persist.
yes
modData is just a lua table - but it can only save simple data native to lua - strings, numbers, booleans, and tables of the above.
If the data isn't being saved to the player you're probably using a direct reference
you can get non-object mod data with ModData.getOrCreate("unique string key") which behaves basically the same but isn't attached to a specific object
Just checked and the console.txt looks promising
no errors following the lua file
found tag:APPLES in the txt file
Ok that one uses Global ModData I guess.
Same rules apply though - you can't save direct references to objects
This what I've been using to test persistence on the player:
`function OnLoadTest()
if getSpecificPlayer(0):getModData()["toto"] ~= nil then
print("OnLoadTest = ", getSpecificPlayer(0):getModData()["toto"] )
else
print("OnLoadTest = toto does not exist")
end
end
function OnSaveTest()
getSpecificPlayer(0):getModData()["toto"] = "TOTO"
end
Events.EveryOneMinute.Add(OnLoadTest)
Events.OnSave.Add(OnSaveTest)`
that should be persistent
I tried different variations of that and it never retrieves the data.
Not sure about the onsave event
i would guess that onsave fires either after character destruction or after moddata is saved
unfortunately my documentation on it was very non-specific 😅
I also tried storing with Events.OnPlayerUpdate but same results.
So you just see "OnLoadTest = toto does not exist" ?
Ok thanks, at least now I know that it's supposed to persist on the player. 😄
Yeah exactly
For context. I'm making a small mod that adds a small batteries charger tile with a container. And when it's on an electrified tile, it charges the batteries inside.
So I need to persist a list of all chargers that are currently placed in the world.
Yes it's in the client folder.
yeah, onsave is after characters save, so it shouldn't actually work on that event - not sure why it doesn't work on update though
Ok, I'll try again with update.
Oh by the way, there's no way to add a custom update function on a tile object or a container by any chance?
Currently my planned approach is to store a list of all chargers and on Events.EveryOneMinute or every 10 minutes update the charging of all batteries in those chargers.
I'm all ears! 😄
if these objects don't need to react to things in real time, you can simulate time passed when the player reaches them - if they do, you have to use global objects, which are one of the most annoying systems, there's no documentation and almost nobody has any experience using them
also as mentioned with a prior concept - its better to update the object when it's interacted with - and store a time last seen to calucate the differences
however with power things can be a bit tricky
That's what I did initially but it was problematic to manage electricity outages. Like knowing how long the generator was off to substract that time period.
well, even vanilla doesn't account for this
shutoff day and time is stored I think
well - it's predetermined when the world is generated I think
oh - you mean a genie - yeah nvm,
I already use that in the condition to know if there is elctricty on a tile.
Yeah a gene
You'd have to track alot for that to work
having it simulated in realtime wouldn't be any easier tbh
stuff gets unloaded if you're far away
Ok, I can bring down my expectations a bit. I felt like I was close to a solution, but maybe it's overkill and a bit too taxing on perfs.
Do items persist their modData?
item:getModData().BatLastTime = curTime item:getModData().BatLastCharge = item:getUsedDelta()
yep
It's doable - just, if you leave the cell the tracking will have to be simulated anyway
all moddata is persistent, that's its purpose (except in some niche cases where it wasn't working, but i'm not sure there's many of those left...?)