Entry point of the Craft plugin, which lets players craft items from blueprints at crafting stations.

Sets the cwCraft global alias and defines cwCraft:PlayerCanCraft with its checks for materials, tools, attributes, custom requirements and a one second cooldown. The Craft::CraftItem Cable message looks the blueprint up by ID in cw.blueprints, makes sure the player is able to act and still stands at a station of the blueprint's craftplace class, runs the checks and crafts it.

Summary

Hooks

Called after all map entities have been initialized; loads the saved crafting stations.
Spawns the crafting stations saved for the current map, frozen in place.
Checks whether a player can craft a blueprint right now.
Checks whether the local player may see a blueprint in the craft menu.
Crafts a blueprint for a player without checking whether they may.
Checks whether a player meets a blueprint's attribute requirements.
Checks whether a player carries every material in a blueprint's recipe.
Checks whether a player carries every tool a blueprint requires.
Called when the local player gains an item; refreshes the item counts of the open craft menu.
Called when the local player loses an item; refreshes the item counts of the open craft menu.
Checks whether a player passes a blueprint's custom requirement callbacks.
Called after Catwork saves its data; saves the crafting stations.
Saves the class, position and angles of every crafting station on the map.

Hooks

cwCraft:ClockworkInitPostEntity()

server gamemodes/cwhl2rp/plugins/craft/plugin/sv_hooks.lua:96

Implements hook ClockworkInitPostEntity

Called after all map entities have been initialized; loads the saved crafting stations.

Spawns the crafting stations saved for the current map, frozen in place.

cwCraft:PlayerCanCraft(player, bpTable)

shared gamemodes/cwhl2rp/plugins/craft/plugin/sh_plugin.lua:21

Checks whether a player can craft a blueprint right now.

Runs the material, tool, attribute and custom requirement checks in that order, then the one second cooldown set after each craft. The first failing check decides the error.

Parameters

Returns

  • Boolean Whether the player can craft it
  • String Language key of the reason when they cannot

cwCraft:PlayerCanSeeCraft(bpTable)

client gamemodes/cwhl2rp/plugins/craft/plugin/cl_hooks.lua:14

Checks whether the local player may see a blueprint in the craft menu.

Attribute requirements are bucketed at 25, 50 and 75: a blueprint is hidden while the player's attribute is below the highest of those thresholds its requirement reaches.

Parameters

  • bpTable Map The blueprint; its reqatt list holds { attributeID, minimum } pairs

Returns

  • Boolean Whether the blueprint is listed

cwCraft:PlayerCraftItem(player, bpTable)

server gamemodes/cwhl2rp/plugins/craft/plugin/sv_hooks.lua:14

Crafts a blueprint for a player without checking whether they may.

Takes the recipe's materials, gives the resulting items (dropping them in front of the player when the inventory is full), progresses the blueprint's updatt attributes and notifies the player. Call cwCraft:PlayerCanCraft first.

Parameters

  • player Player The player who crafts
  • bpTable Map The blueprint to craft

cwCraft:PlayerHasAttributes(player, bpTable)

shared gamemodes/cwhl2rp/plugins/craft/plugin/sh_plugin.lua:92

Checks whether a player meets a blueprint's attribute requirements.

Parameters

  • player Player The player to check
  • bpTable Map The blueprint; its reqatt list holds { attributeID, minimum } pairs

Returns

  • Boolean Whether every listed attribute is at least its minimum

cwCraft:PlayerHasMaterials(player, bpTable)

shared gamemodes/cwhl2rp/plugins/craft/plugin/sh_plugin.lua:49

Checks whether a player carries every material in a blueprint's recipe.

Parameters

  • player Player The player to check
  • bpTable Map The blueprint; its recipe list holds { itemID, amount } pairs

Returns

  • Boolean Whether the inventory holds enough of each material

cwCraft:PlayerHasTools(player, bpTable)

shared gamemodes/cwhl2rp/plugins/craft/plugin/sh_plugin.lua:72

Checks whether a player carries every tool a blueprint requires.

Tools are not consumed by crafting.

Parameters

  • player Player The player to check
  • bpTable Map The blueprint; its required list holds { itemID, amount } pairs

Returns

  • Boolean Whether the inventory holds enough of each tool

cwCraft:PlayerItemGiven(itemTable)

client gamemodes/cwhl2rp/plugins/craft/plugin/cl_hooks.lua:44

Implements hook PlayerItemGiven

Called when the local player gains an item; refreshes the item counts of the open craft menu.

Parameters

  • itemTable

cwCraft:PlayerItemTaken(itemTable)

client gamemodes/cwhl2rp/plugins/craft/plugin/cl_hooks.lua:49

Implements hook PlayerItemTaken

Called when the local player loses an item; refreshes the item counts of the open craft menu.

Parameters

  • itemTable

cwCraft:PlayerMeetsRequirements(player, bpTable)

shared gamemodes/cwhl2rp/plugins/craft/plugin/sh_plugin.lua:114

Checks whether a player passes a blueprint's custom requirement callbacks.

Each entry of the blueprint's requirements list is called with the player and must return true to pass; its second return value is the text the craft menu shows for it.

Parameters

  • player Player The player to check
  • bpTable Map The blueprint

Returns

  • Boolean Whether every callback passed

Implements hook PostSaveData

Called after Catwork saves its data; saves the crafting stations.

Saves the class, position and angles of every crafting station on the map.

Stations are entities with IsCraft set; the data goes to plugins/craft/<map>.

Defined in