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
Hooks
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:21Checks 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
- player Player The player who wants to craft
- bpTable Map The blueprint, as returned by
cw.blueprints:FindByID
Returns
- Boolean Whether the player can craft it
- String Language key of the reason when they cannot
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
reqattlist holds{ attributeID, minimum }pairs
Returns
- Boolean Whether the blueprint is listed
cwCraft:PlayerCraftItem(player, bpTable)
server gamemodes/cwhl2rp/plugins/craft/plugin/sv_hooks.lua:14Crafts 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:92Checks whether a player meets a blueprint's attribute requirements.
Parameters
- player Player The player to check
- bpTable Map The blueprint; its
reqattlist 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:49Checks whether a player carries every material in a blueprint's recipe.
Parameters
- player Player The player to check
- bpTable Map The blueprint; its
recipelist 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:72Checks 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
requiredlist holds{ itemID, amount }pairs
Returns
- Boolean Whether the inventory holds enough of each tool
Implements hook PlayerItemGiven
Called when the local player gains an item; refreshes the item counts of the open craft menu.
Parameters
- itemTable
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:114Checks 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>.