|
Project Zomboid Lua Docs 29123
Unofficial documentation for Project Zomboid's Lua
|
Called when successfully crafting the recipe.
Parameters
| Name | Type | Notes |
|---|---|---|
| recipeData | CraftRecipeData | |
| character | IsoGameCharacter or nil | Character crafting the recipe. Recipes crafted by a workstation wil pass nil. |
Called when failing to craft the recipe, either because it was cancelled or the conditions are no longer met.
Parameters
| Name | Type | Notes |
|---|---|---|
| recipeData | CraftRecipeData |
Called at the start of crafting the recipe. For recipes crafted in hand or build recipes, called immediately before finishing the recipe. For recipes crafted by crafting stations, called when a character initiates the crafting.
Parameters
| Name | Type | Notes |
|---|---|---|
| recipeData | CraftRecipeData | |
| character | IsoGameCharacter or nil | Character crafting the recipe. Recipes crafted by a workstation will pass nil. |
Determines whether an item can be used in the recipe.
Parameters
| Name | Type | Notes |
|---|---|---|
| item | InventoryItem | Item to test. |
Returns
| Name | Type | Notes |
|---|---|---|
| test | boolean | Whether to allow the item in the recipe. |
Called every tick while crafting the recipe.
Parameters
| Name | Type | Notes |
|---|---|---|
| recipeData | CraftRecipeData |
Used by the getBest methods in ItemContainer. These methods will sort all matches using this function, and return the item in first place.
Parameters
| Name | Type | Notes |
|---|---|---|
| a | InventoryItem | The first item being tested. |
| b | InventoryItem | The second item being tested. |
Returns
| Name | Type | Notes |
|---|---|---|
| number | This should be positive if a should be prioritised over b, and negative if b should be prioritised. |
Used by the -Eval methods in ItemContainer. These methods will only consider items that this function returns true for.
Parameters
| Name | Type | Notes |
|---|---|---|
| item | InventoryItem | The item being tested. |
Returns
| Name | Type | Notes |
|---|---|---|
| allowItem | boolean | Whether the item is a valid match. |
Called when checking if an item is allowed inside a container with this function assigned. The container's OnlyAcceptCategory will be checked first if it has one.
Parameters
| Name | Type | Notes |
|---|---|---|
| container | ItemContainer | The container the item is being added to |
| item | InventoryItem | The item being added to the container |
Returns
| Name | Type | Notes |
|---|---|---|
| acceptItem | boolean | Whether to allow the item in the container |
Called when the item is cooked. Not called if the item has a ReplaceOnCooked as the item is destroyed. OnCooked functions cannot be inside tables or the game will not find them.
Parameters
| Name | Type | Notes |
|---|---|---|
| item | InventoryItem | The item being cooked |
Called when the item is first created, before it is placed into its container. Generally used to initialise items.
Parameters
| Name | Type | Notes |
|---|---|---|
| item | InventoryItem | The item being created |
Called when a player eats the item. Called on the client eating the item only.
Parameters
| Name | Type | Notes |
|---|---|---|
| item | InventoryItem | The item being eaten |
| character | IsoGameCharacter | The character eating the item |
| amount | number | The fraction of the item that was eaten. |
Called by the recipe manager for every recipe source after the lua/server/ folder loads. The ArrayList should be filled with Item objects to include as part of the recipe source.
Parameters
| Name | Type | Notes |
|---|---|---|
| outItems | ArrayList<Item> | An empty ArrayList to be filled with items. |
Called when checking if a character is able to perform the recipe - before showing the option to craft it, and every tick during crafting.
Parameters
| Name | Type | Notes |
|---|---|---|
| recipe | Recipe | The recipe being checked |
| character | IsoGameCharacter | The character the recipe is being checked for |
| item | InventoryItem or nil | The item the player right clicked to see this recipe. Null when checking whether to show the recipe in the crafting menu, but will be checked with the item set during crafting. |
Returns
| Name | Type | Notes |
|---|---|---|
| canPerform | boolean | Whether to allow the character to craft the recipe |
Called after crafting the recipe.
Parameters
| Name | Type | Notes |
|---|---|---|
| sources | ArrayList<InventoryItem> | The items used to craft the recipe |
| result | InventoryItem | The item crafted by the recipe. Passed even if RemoveResultItem is set |
| character | IsoGameCharacter | The character who crafted the recipe |
| item | InventoryItem | The item used in the crafting action. This is either the item that was right clicked to start the crafting, or the first source item if it was crafted from the recipe menu. |
| isPrimaryHandItem | boolean | True if item is equipped in the player's primary hand |
| isSecondaryHandItem | boolean | True if item is equipped in the player's secondary hand |
Called after crafting the recipe.
Parameters
| Name | Type | Notes |
|---|---|---|
| recipe | Recipe | The recipe that was crafted |
| sources | ArrayList<InventoryItem> | The items used to craft the recipe |
| result | InventoryItem | The item crafted by the recipe. Passed even if RemoveResultItem is set |
| character | IsoGameCharacter | The character who crafted the recipe |
Called when checking if an item is allowed to be used in a recipe.
Parameters
| Name | Type | Notes |
|---|---|---|
| item | InventoryItem | The item being checked |
| result | Recipe.Result | The result of the recipe |
Returns
| Name | Type | Notes |
|---|---|---|
| test | boolean | Whether to allow the item into the recipe |
Called after the part is successfully installed.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part that was installed |
Called when testing if the part can be installed.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being tested |
| character | IsoGameCharacter | The character using the part |
Returns
| Name | Type | Notes |
|---|---|---|
| test | boolean | Whether the part can be installed |
Called after the part is successfully uninstalled.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part that was uninstalled |
| item | InventoryItem | The item that was removed |
Called when testing if the part can be uninstalled.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being tested |
| character | IsoGameCharacter | The character using the part |
Returns
| Name | Type | Notes |
|---|---|---|
| test | boolean | Whether the part can be uninstalled |
Called every tick while the engine is running. If any part returns false the engine will immediately shut off.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being checked |
Returns
| Name | Type | Notes |
|---|---|---|
| working | boolean | Whether the engine should be working |
Called every tick while a player is in the driver's seat and able to drive. If any part returns false the player will not be able to control the vehicle.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being checked |
Returns
| Name | Type | Notes |
|---|---|---|
| operable | boolean | Whether the vehicle is operable |
Called when the part is spawned for the first time.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being created |
Called every time the part loads in or is reset.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being initialised |
Called regularly to update the part, targeting a rate of every half an in-game minute (1.25 seconds on 1 hour days).
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being updated |
| deltaMinutes | number | The number of minutes since the last update |
Called when a character interacts with the vehicle while in the part's area.
Parameters
| Name | Type | Notes |
|---|---|---|
| vehicle | BaseVehicle | The vehicle the part belongs to |
| part | VehiclePart | The part being used |
| character | IsoGameCharacter | The character using the part |