AuthenticPeach / AuthenticZ

Clothing, item, and outfit distribution mod for the game Project Zomboid
1 stars 5 forks source link

AttachedWeaponDefinitions overwrites vanilla / other mods definitions. #1

Closed EngineOfDarkness closed 2 years ago

EngineOfDarkness commented 2 years ago

The way AttachedWeaponDefinitions in media/lua/shared/Definitions/ are implemented is suboptimal, because instead of adding to the Definitions, they are simply redefined.

This is not good for multiple reasons

For Example:

Vanilla

-- random weapon on police zombies holster
AttachedWeaponDefinitions.handgunHolster = {
    id = "handgunHolster",
    chance = 50,
    outfit = {"Police", "PoliceState", "PoliceRiot", "PrisonGuard", "PrivateMilitia"},
    weaponLocation =  {"Holster Right"},
    bloodLocations = nil,
    addHoles = false,
    daySurvived = 0,
    ensureItem = "Base.HolsterSimple",
    weapons = {
        "Base.Pistol",
        "Base.Pistol2",
        "Base.Pistol3",
        "Base.Revolver",
        "Base.Revolver_Long",
        "Base.Revolver_Short",
    },
}

Your Version https://github.com/AuthenticPeach/AuthenticZ/blob/e195d07c10dcf5fc98eca726a786f2baaa97f06f/Contents/mods/Authentic%20Z%20-%20Current/media/lua/shared/Definitions/xAuthenticZ_AttachedWeaponDefinitions.lua#L271-L288

The only change over vanilla are additional entries in outfit , yet the entire handgunHolster entry is redefined.

It would be more sensible for forward compatibility (pz-updates) and mod interoperability to do something like the following (I did not specifically test this, just quickly written it down for exemplary reasons)

table.insert(AuthenticZ_AttachedWeaponDefinitions["handgunHolster"].outfit, "AuthenticSurvivorHazardSuit")
table.insert(AuthenticZ_AttachedWeaponDefinitions["handgunHolster"].outfit, "AuthenticSecretService")
... etc

This is also loosely mentioned in the Zomboid Modding Guide https://github.com/FWolfe/Zomboid-Modding-Guide/blob/master/api/README.md#overwriting-vanilla-code (while that guide mostly talks about functions in the broader sense, this applies to lua tables as well)

I could also prepare a pull request, if desired.

AuthenticPeach commented 2 years ago

Yeah this is the one file I need to clean house on. I have not rewritten the file in nearly a year, so it uses outdated and overwriting methods that I am not using anymore. I will resolve this soon.