Project Zomboid

Project Zomboid

Eggon's Modding Utils
 This topic has been pinned, so it's probably important
Eggon  [developer] 3 Oct, 2021 @ 2:40am
Guide: Events
Introduction
The mod is work in progress and I will try to improve the contents (in particular the events) overtime.

All events offered by this mod work on a similar principle: a relevant PZ's core function is stored in a new variable and the original reference (name) is overwritten by this mod's function that triggers the event, in some cases performs some minimal follow-up logic and re-calls the original PZ function.

This means that if IndieStone significantly change the core function, it will break the game and you need to be aware of it when using this mod. However, I think the probability of them doing this in such a destructive way is relatively low.

Nonetheless, in order to minimize the risk (and to improve performance) each of the events needs to be enabled before you use them. Enable just the events that you will be using.
Last edited by Eggon; 29 Oct, 2021 @ 3:30am
< >
Showing 1-9 of 9 comments
Eggon  [developer] 3 Oct, 2021 @ 2:46am 
Enabling events

In order to enable a particular event place the following code into a file in lua/client directory:

if EggonsMU then EggonsMU.config.enableEvent("OnHotbarItemAttach") end

The example uses OnHotbarItemAttach. Use the name of relevant event.
Last edited by Eggon; 10 Nov, 2021 @ 8:03am
Eggon  [developer] 3 Oct, 2021 @ 3:07am 
OnHotbarItemAttach event

Event triggers when item is attached to a hotbar, but also during hotbar refreshes, so it will be triggered before game starts, but also in some other cases, like when a backpack is equipped. A series of unattach/attach events might be triggered, but the an 'attach' will be triggered as last. It is definitely not optimal, but at this moment I don't know how to circumvent it. The event is triggered rarely enough to not have impact on performance even if slightly unoptimal.

The handler fnction receives the following parameters:
1) item - item being attached
2) slot - hotbar slot it is being attached to
3) slotIndex - index of the hotbar slot
4) slotDef
5) doAnim - will animation be performed. Generally the technical, 'refresh', triggers will have this value as false.

Enabling function: EggonsMU.config.enableEvent("OnHotbarItemAttach")
Last edited by Eggon; 14 Oct, 2021 @ 4:48am
Eggon  [developer] 3 Oct, 2021 @ 3:11am 
OnHotbarItemUnattach event

Event triggers when item is unattached from the hotbar, but also during hotbar refreshes, so it will be triggered before game starts, but also in some other cases, like when a backpack is equipped. A series of unattach/attach events might be triggered, but in case of the refresh actions an 'attach' will be triggered as last. If an item is really removed from the hotbar, the 'unattach' event will trigger as last, but it might trigger more than once. It is definitely not optimal, but at this moment I don't know how to circumvent it. The event is triggered rarely enough to not have impact on performance even if slightly unoptimal.

The handler fnction receives the following parameters:
1) item - item being unattached

Enabling function: EggonsMU.config.enableEvent("OnHotbarItemUnattach")
Last edited by Eggon; 14 Oct, 2021 @ 4:48am
Eggon  [developer] 8 Oct, 2021 @ 9:50am 
OnBeforeItemTransfer event

The handler function receives a single argument consisting of the following properties:

1) eventData = {
    character,
    item, -- item being transferred
    srcContainer, -- source container
    destContainer, -- destination container, can be replaced by a different one
    cancel, -- set true to cancel action
}

Example of use:
function OnBeforeItemTransferHandler (eventData) eventData.cancel = true -- will cancel the event eventData.destContainer = yourContainer -- will replace destination container with a different one end Events.OnBeforeItemTransfer.Add(OnBeforeItemTransferHandler)

Enabling function: EggonsMU.config.enableEvent("OnBeforeItemTransfer")
Last edited by Eggon; 10 Nov, 2021 @ 8:04am
Eggon  [developer] 8 Oct, 2021 @ 9:59am 
OnAfterItemTransfer event

The handler function receives the following arguments:
    1 .character,
    2. item, -- item being transferred
    3. srcContainer, -- source container
    4. destContainer, -- destination container

Enabling function: EggonsMU.config.enableEvent("OnAfterItemTransfer")
Last edited by Eggon; 14 Oct, 2021 @ 4:49am
Eggon  [developer] 14 Oct, 2021 @ 4:56am 
OnBeforeFirstInventoryTooltipDisplay event

This event triggers once only when inventory tooltip is displayed for the first time for a particular item (A). If mouse is moved over another item (B) it will trigger again for that new item (B) and if mouse is moved over item A again - it will trigger for item A. However, if tooltip for item (A) is displayed and mouse is moved outside of inventory (tooltip disappears) and then moved again onto the same item (A), the event will not trigger again despite the tooltip being displayed.

The handler function receives the following arguments:
    1. item, -- item being hovered over
    2. ISToolTipInv_instance, -- instance of ISToolTipInv

Enabling function: EggonsMU.config.enableEvent("OnBeforeFirstInventoryTooltipDisplay")
Last edited by Eggon; 10 Nov, 2021 @ 8:08am
Eggon  [developer] 15 Nov, 2021 @ 7:02am 
OnDisplayContainerContents event
OnDisplayInventoryContainerContents event
OnDisplayLootContainerContents event

These events trigger when new container gets activated in the inventory panes. It does not work with 'floor'.
OnDisplayContainerContents - triggers when either inventory or loot container gets activated
OnDisplayInventoryContainerContents - triggers for inventory containers only
OnDisplayLootContainerContents - triggers for loot containers only

The handler function receives the following arguments:
    1. ItemsContainer, -- container being activated
Enabling functions:
EggonsMU.enableEvent.OnDisplayContainerContents()
EggonsMU.enableEvent.OnDisplayLootContainerContents()
EggonsMU.enableEvent.OnDisplayInventoryContainerContents()
Last edited by Eggon; 15 Nov, 2021 @ 7:03am
Eggon  [developer] 15 Nov, 2021 @ 7:05am 
U+274B
[U+274B]
:U+274B:
🗜
Last edited by Eggon; 15 Nov, 2021 @ 7:06am
HapiHapiHapi 30 Jul, 2023 @ 12:45am 
Where can I find the Lua/client directory?
< >
Showing 1-9 of 9 comments
Per page: 1530 50