- Joined
- May 4, 2010
- Messages
- 215
- Solutions
- 3
- Reaction score
- 185
Crafting Stations
In my case a forging script, but you can change the anvil id to be something else.
As I never released anything, I decided to release this script I made with the help of my best friend Henk, known by some as ChatGBT, edited from an initial movement script to an action script by @Xikini so it allows for experience gain if you have additional skills setup.
What does it do?
It allows players to immersefully and in an old-school way to forge weapons and armor, or any item they want.
This can also be made into an upgrading system or cooking station, the sky is the limit.
I've made it with the concept of how easy "creating bread" in Tibia is and followed up on that.
You can configure a recipe that players can stack upon an Anvil,
upon using a Blacksmith Hammer on the Anvil, the materials will transform into the item configured.
View attachment 2024-02-16 13-15-47.mp4
In my case a forging script, but you can change the anvil id to be something else.
As I never released anything, I decided to release this script I made with the help of my best friend Henk, known by some as ChatGBT, edited from an initial movement script to an action script by @Xikini so it allows for experience gain if you have additional skills setup.
What does it do?
It allows players to immersefully and in an old-school way to forge weapons and armor, or any item they want.
This can also be made into an upgrading system or cooking station, the sky is the limit.
I've made it with the concept of how easy "creating bread" in Tibia is and followed up on that.
You can configure a recipe that players can stack upon an Anvil,
upon using a Blacksmith Hammer on the Anvil, the materials will transform into the item configured.
View attachment 2024-02-16 13-15-47.mp4
actions.xml
Code:
<!-- Crafting Stations -->
<action itemid="2422" script="forging.lua"/>
actions/scripts/forging.lua
Lua:
local recipes = {
-- Ores to Bars
{
resultItemID = 49257, -- Brass Bar
requiredItems = {
{itemID = 49242, count = 2}, -- Copper Ore
{itemID = 49256, count = 1} -- Zinc Ore
}
}
}
local ANVIL_ID = 2555
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target then
return true
end
if not target:isItem() then
return true
end
local position = target:getPosition()
if position.x == CONTAINER_POSITION then
return true
end
local tile = Tile(position)
if not tile then
return false
end
local items = tile:getItems()
if items then
local hasAnvil = false
local bestMatchRecipe = nil
for _, itemOnTile in ipairs(items) do
if itemOnTile:getId() == ANVIL_ID then
hasAnvil = true
end
end
if hasAnvil then
for _, recipe in ipairs(recipes) do
local requiredItemsFound = true
for _, reqItem in ipairs(recipe.requiredItems) do
local foundCount = 0
for _, itemOnTile in ipairs(items) do
if itemOnTile:getId() == reqItem.itemID then
foundCount = foundCount + itemOnTile:getCount()
end
end
if foundCount < reqItem.count then
requiredItemsFound = false
break
end
end
if requiredItemsFound then
for _, reqItem in ipairs(recipe.requiredItems) do
local remainingCount = reqItem.count
for _, itemOnTile in ipairs(items) do
if itemOnTile:getId() == reqItem.itemID then
local countToRemove = math.min(remainingCount, itemOnTile:getCount())
itemOnTile:remove(countToRemove)
remainingCount = remainingCount - countToRemove
if remainingCount <= 0 then
break
end
end
end
end
Game.createItem(recipe.resultItemID, recipe.count or 1, toPosition)
toPosition:sendMagicEffect(CONST_ME_HITBYFIRE)
doPlayerAddSkillTry(player:getId(), SKILL_METALWORKING, 1) -- remove line if no skill
local formula = (getPlayerSkill(player:getId(), SKILL_METALWORKING) / 200) + (0.85 * math.random()) -- remove line if no skill
return true
end
end
end
end
return false
end
Last edited: