Ради вашего удобства наш сайт использует cookies! Узнать больше! Мы используем cookies

VehicleSetFix — 42.17 Compatibility Patch

VehicleSetFix — 42.17 Compatibility Patch

⚠ Deprecation Notice

This mod no longer provides a reliable fix and should be removed from your mod list.

The two approaches that could intercept getVehicles():get(i) transparently both turned out to be incompatible with the game:

  • Patching IsoCell at the class level — not possible because IsoCell is not registered as a Lua-accessible table in 42.17.
  • Wrapping the getCell() global — breaks vanilla map interaction. Any i that passes getCell() as an argument to a Java constructor (building furniture, placing objects, constructing traps, etc.) receives a Lua proxy table instead of the expected IsoCell object, causing actions to consume materials without placing anything.

The only remaining approach — patching individual mod methods case by case — is not a sustainable solution and does not cover mods whose affected functions are defined as locals.

The correct fix is for each affected mod to update its iteration pattern from get(i) to iterator(). If a mod in your list is still crashing with "Object tried to call nil" on a getVehicles() call, contact the mod author and link them to this page.


Fixes vehicle mod crashes introduced by the 42.17 update.

The Problem

In version 42.17, Project Zomboid changed the internal return type of IsoCell.getVehicles() from ArrayList to Set. This silently breaks any mod written for 42.16 that iterates vehicles using the vehicles:get(i) pattern, since Set has no such method.

The result is an "Object tried to call nil" crash when interacting with vehicles — opening the radial menu, refueling, etc.

What This Mod Does

Intercepts getVehicles() calls and returns a proxy that adds get(index) support, without breaking mods already updated for 42.17 that use iterator().

No files from other mods are modified.

How It Works

The mod attempts three strategies in order, stopping at the first that succeeds.

Strategy 1 — IsoCell class table patch
Overrides IsoCell.getVehicles at the class level. Every call to getVehicles() from any mod, regardless of how the cell was obtained, returns the proxy. This is the safest and most complete approach. The console will log Strategy 1: patched IsoCell.getVehicles if successful.

Strategy 2 — getCell() global override
Falls back to wrapping the getCell() Lua global if the class table is not accessible. Covers mods that call getCell():getVehicles() directly (e.g. RV Interior server-side). Does not cover calls made via playerObj:getCell():getVehicles().

Strategy 3 — FindVehicleGas replacement
If strategies 1 and 2 are insufficient, replaces the FindVehicleGas global defined by PZK Car Pack with an iterator-based equivalent. Functionally identical to the original.

Impact on Correctly Updated Mods

Mods already written for 42.17 that use iterator() are not affected.

The proxy returned by the patched getVehicles() forwards all unknown method calls to the underlying Java Set via __index, so size(), iterator(), isEmpty(), contains() and any other Set method continue to work normally.

The one exception is pairs(vehicleList) — Lua 5.1 has no __pairs metamethod, so iterating the proxy with pairs() will not yield vehicles. However, pairs() was never a correct way to iterate a Java collection and no well-written 42.17 mod should rely on it.

Known Fixed Mods

  • PZK Vanilla Plus Car Pack — crash in FindVehicleGas when opening the vehicle menu
  • PROJECT RV Interior — crash on saves migrated from 42.16

Other mods affected by the same change are also covered automatically.

Compatibility

  • Requires 42.17+. On 42.16 the mod detects the original ArrayList and does nothing.
  • Compatible with multiplayer (client and server).
  • Should be loaded before the mods it fixes in the load order.
  • Does not affect existing saves.

For Mod Authors

If your mod iterates vehicles and broke in 42.17, the correct pattern is now:

local it = cell:getVehicles():iterator()
while it:hasNext() do
local vehicle = it:next()
-- ...
end

This mod is a temporary compatibility shim while affected mods are updated by their authors.


Workshop ID: 3711625535
Mod ID: VehicleSetFix

Рейтинг

Войдите, чтобы голосовать.
🏅 Нет оценок

Базовые теги:

Version:

Загрузить 141.3 KB