• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.2] Simple Crafting System.

Nice script !!
Is working all at 90%
Just while clicking on Details it doesnt show the Windows , just like 3 seconds and disappear,
You need press Exit, and it shows the recipe, can be changed to show it directly while clicking on details ?
Any fix to that? Having same problem

regards
 
I believe I had the same issue.Are you sure you have the right itemID? Think that fixed it for me :)
Fixed that myself

Lua:
function capAll(str)
    local newStr = ""; wordSeparate = string.gmatch(str, "([^%s]+)")
    for v in wordSeparate do
        v = v:gsub("^%l", string.upper)
        if newStr ~= "" then
            newStr = newStr.." "..v
        else
            newStr = v
        end
    end
    return newStr
end
-- Main Crafting Window -- This is the modal window that is displayed first
    function Player:sendMainCraftWindow(config)
    local function buttonCallback(button, choice)
 
    -- Modal Window Functionallity
        if button.text == "Select" then
            self:sendVocCraftWindow(config, choice.id)
        end   
    end
 
    -- Modal window design
    local window = ModalWindow {
        title = config.mainTitleMsg, -- Title of the main craft modal window
        message = config.mainMsg.."\n\n" -- Message of the main craft modal window
    }
 
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Select", buttonCallback)
    window:addButton("Exit", buttonCallback)
 
    -- Add choices from the action script
    for i = 1, #config.system do
        window:addChoice(config.system[i].vocation)
    end
 
    -- Set what button is pressed when the player presses enter or escape.
    window:setDefaultEnterButton("Select")
    window:setDefaultEscapeButton("Exit")
 
    -- Send the window to player
    window:sendToPlayer(self)
end
-- End of the first modal window
 
 
 
-- This is the modal window that displays all avalible items for the chosen vocation.
function Player:sendVocCraftWindow(config, lastChoice)
    local function buttonCallback(button, choice)   
 
-- Modal Window Functionallity
        -- If the user presses the back button they will be redirected to the main window.
        if button.text == "Back" then
            self:sendMainCraftWindow(config)
        end
        -- If the user presses the details button they will be redirected to a text window with information about the item they want to craft.
        if button.text == "Details" then
        local item = config.system[lastChoice].items[choice.id].item
        local details = "In order to craft "..item.." you must collect the following items.\n\nRequired Items:"
 
            for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
            local reqItems = config.system[lastChoice].items[choice.id].reqItems[i].item
            local reqItemsCount = config.system[lastChoice].items[choice.id].reqItems[i].count
            local reqItemsOnPlayer = self:getItemCount(config.system[lastChoice].items[choice.id].reqItems[i].item)
                details = details.."\n- "..capAll(getItemName(reqItems).." ["..reqItemsOnPlayer.."/"..reqItemsCount.."]")
            end   
 
            self:showTextDialog(item, details)
        end
 
        -- if the player presses the craft button then begin checks.
        if button.text == "Craft" then
 
            -- Check if player has required items to craft the item. If they dont send needItems message.
            for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                if self:getItemCount(config.system[lastChoice].items[choice.id].reqItems[i].item) < config.system[lastChoice].items[choice.id].reqItems[i].count then
                    self:say(config.needItems..config.system[lastChoice].items[choice.id].item, TALKTYPE_MONSTER_SAY)
                    return false
                end
            end   
            -- Remove the required items and there count from the player.
            for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                self:removeItem(config.system[lastChoice].items[choice.id].reqItems[i].item, config.system[lastChoice].items[choice.id].reqItems[i].count)
            end               
        -- Send effect and give player item.
        self:addItem(config.system[lastChoice].items[choice.id].itemID)
        self:getPosition():sendMagicEffect(CONST_ME_FIREATTACK)
        end   
    end
 
    -- Modal window design
    local window = ModalWindow {
        title = config.craftTitle..config.system[lastChoice].vocation, -- The title of the vocation specific window
        message = config.craftMsg..config.system[lastChoice].vocation..".\n\n", -- The message of the vocation specific window
    }
 
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Back", buttonCallback)
    window:addButton("Exit")
    window:addButton("Details", buttonCallback)
    window:addButton("Craft", buttonCallback)
 
    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Craft")
    window:setDefaultEscapeButton("Exit")
 
    -- Add choices from the action script
    for i = 1, #config.system[lastChoice].items do
        window:addChoice(config.system[lastChoice].items[i].item)
    end
 
    -- Send the window to player
    window:sendToPlayer(self)
end

For anybody that had the same problem
 
Any fix to that? Having same problem

regards
The fix is Easy,
The part on lib where is “recipe” before the end tag remove self:sendVocCraftWindow(config, lastChoice)
This make a loop while clicking on recipe it comes again to te list category.
 
 
Last edited:
In Case its not important you want to see the picture of the item crafted and you wish a Button 'Back' while looking the recipe,

add on "Details" at the final:

Remove this:
Lua:
self:showTextDialog(item, details)

Replace:
Lua:
local window = ModalWindow {
                title = "Recipe",
                message = details,
            }
            window:addButton("Go Back", function() self:sendVocCraftWindow(config, lastChoice) end)
            window:sendToPlayer(self)

It will replace the "Book" view to a Modal Windows, then it add's a button "Go Back" to the category.
Doing that the problem is you lose the picture of the item view on recipe.
Of course, one day when we reach higher lua you will be able to add pictures on modal windows.
 
In Case its not important you want to see the picture of the item crafted and you wish a Button 'Back' while looking the recipe,

add on "Details" at the final:

Remove this:
Lua:
self:showTextDialog(item, details)

Replace:
Lua:
local window = ModalWindow {
                title = "Recipe",
                message = details,
            }
            window:addButton("Go Back", function() self:sendVocCraftWindow(config, lastChoice) end)
            window:sendToPlayer(self)

It will replace the "Book" view to a Modal Windows, then it add's a button "Go Back" to the category.
Doing that the problem is you lose the picture of the item view on recipe.
Of course, one day when we reach higher lua you will be able to add pictures on modal windows.
technically i was already thinking about it you could use opcodes to open container that is 1x1 width and height and displays item that does not respond to :hover or click etc :)
 
Hello,

Wasn't going to release this because there is already a couple but open source right?
Like always it is using @Non Sequitur modal window system which can be found HERE

You will have to install that in order to be able to use this system.

Pictures

Main Screen
365ab70c051a18c7b3f7128e9416f6c3.png


Selection Screen
37c6bbd309818c4e1522a19c5a5b9cbe.png


Item Selection Screen (Please note pressing ok brings you back to the selection screen.)
6e831aac3ecb4735bb7c7bca9cdb22f0.png

Why use this?
Much cleaner then all the other crafting systems.. easy configurable and you just need to add the action script and the lib files. There is no need to register the scripts on login.lua or add creaturescripts!

Information on the system
It has an easy config section for you to customize it how you would like it! You just need to fill out the config table found in the action script (pictured below)
Code:
-- Window Config
   mainTitleMsg = "Crafting System", -- Main window title
   mainMsg = "Welcome to the crafting system. Please choose a vocation to begin.", -- Main window message

   craftTitle = "Crafting System: ", -- Title of the crafting screen after player picks of vocation
   craftMsg = "Here is a list of all items that can be crafted for the ", -- Message on the crafting screen after player picks of vocation
-- End Window Config

-- Player Notifications Config
   needItems = "You do not have all the required items to make ", -- This is the message the player recieves if he does not have all required items

-- Crafting Config
   system = {
  [1] = {vocation = "Master Sorcerer", -- This is the category can be anything.
       items = {
         [1] = {item = "Shadow's Sceptre", -- item name (THIS MUST BE EXACT OR IT WILL NOT WORK!)
             itemID = 25249, -- item to be made
             reqItems = { -- items and the amounts in order to craft.
                 [1] = {item = 25224, count = 50}, -- Silver Tokens
                 [2] = {item = 9969, count = 1}, -- Black Skull
                 [3] = {item = 5904, count = 30}, -- Magic Sulphur
                 [4] = {item = 7451, count = 1}, -- Shadow Sceptre
                 [5] = {item = 22396, count = 50}, -- Cluster of Solace
               },
             },

Installation

1)
Install the modal window helper HERE

2) Register the script in /data/actions/actions.xml by adding this line (Replacing "ITEMID" with the item you want to use:
Code:
    <action itemid="ITEMID" script="crafting.lua"/>
3) Create a new text document in /data/actions/scripts and name it "crafting.lua" and paste the following:
local config = {-- Window Config mainTitleMsg = "Crafting System", -- Main w - Pastebin.com (http://pastebin.com/dF2Qp7wx)
4) Add the following line to your global.lua:
Code:
dofile('data/lib/crafting.lua')
5) Create a new text document in /data/lib/ and name it "crafting.lua" and paste the following:
-- Main Crafting Window -- This is the modal window that is displayed first fu - Pastebin.com (http://pastebin.com/5QwAviAP)

Enjoy =)
Will this work in revscripts? I do not know where to add this.

1694796226722.png
 
Will this work in revscripts? I do not know where to add this.

View attachment 78433

add onTop of the script
Lua:
action = Action()

change
Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
to
Lua:
function action.onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)

add to end of the script
Lua:
action:id(Your_Item_Id)
action:register()

Next time check any simple revscript action how its build up then you will see its nothing hard to change a script from normal action to revscript action
 
Last edited:
I know this is an old thread by now, but I was wondering if its possible to display the item description for the item you want to crafts, within in "Details" window? So if you add a item description in item.xml it displays that description somewhere on the "Details" window in the crafting system?

Hope someone can provide me with some info about this.

Thanks :)
 
I know this is an old thread by now, but I was wondering if its possible to display the item description for the item you want to crafts, within in "Details" window? So if you add a item description in item.xml it displays that description somewhere on the "Details" window in the crafting system?

Hope someone can provide me with some info about this.

Thanks :)
It is automatically set to display the names of the items and quantities, etc. It's already done. All you need to do is install everything until you must notice this comment and make the changes, and you're good to go. Everything is functioning as you wanted it to.
\/
In Case its not important you want to see the picture of the item crafted and you wish a Button 'Back' while looking the recipe,

add on "Details" at the final:

Remove this:
Lua:
self:showTextDialog(item, details)

Replace:
Lua:
local window = ModalWindow {
                title = "Recipe",
                message = details,
            }
            window:addButton("Go Back", function() self:sendVocCraftWindow(config, lastChoice) end)
            window:sendToPlayer(self)

It will replace the "Book" view to a Modal Windows, then it add's a button "Go Back" to the category.
Doing that the problem is you lose the picture of the item view on recipe.
Of course, one day when we reach higher lua you will be able to add pictures on modal windows.
 
It is automatically set to display the names of the items and quantities, etc. It's already done. All you need to do is install everything until you must notice this comment and make the changes, and you're good to go. Everything is functioning as you wanted it to.
\/
Thank you for your answer :)

Iam not sure if it made sense what I said, but what I meant was that I want the "Details" window to show the item description aswell as the name of the item and the required items to craft.

This part of the item:

XML:
<item id="26735" name="seal of the shieldmaiden">
    <attribute key="weight" value="900" />
   [B] <attribute key="description" value="+2 shielding, +15 hp, -25 mp" />[/B]
    </item>

So that the player actually know more about the item they are going to craft.
If possible, it would also be nice if it could provide the player with all the info about the item that is written in items.xml, so that the player knows the stats of an item, the weight and the description.

Ps, I like how the text was displayed in the script you provided, but can you include the image of the item aswell?


- Erik
 
Thank you for your answer :)

Iam not sure if it made sense what I said, but what I meant was that I want the "Details" window to show the item description aswell as the name of the item and the required items to craft.

This part of the item:

XML:
<item id="26735" name="seal of the shieldmaiden">
    <attribute key="weight" value="900" />
   [B] <attribute key="description" value="+2 shielding, +15 hp, -25 mp" />[/B]
    </item>

So that the player actually know more about the item they are going to craft.
If possible, it would also be nice if it could provide the player with all the info about the item that is written in items.xml, so that the player knows the stats of an item, the weight and the description.

Ps, I like how the text was displayed in the script you provided, but can you include the image of the item aswell?


- Erik
I managed to install it from this link here, which displays a simple image and information about the item. However, it's still possible to add a description of the item if you'd like to understand more.


 
Thank you again for your answer :)

Yes I kinda have this working now, but I want to make it so that people can see the "Items Attributes" when clicking on the "Details" button, like in this example:

item attribute.png


XML:
<attribute key="description" value="Spell: Bear Claw. This spells targets a single enemy in front on you. It does initial damage calculated by this formula: (player:getLevel() / 5) + (skill * attack * 0.08) + 17, and bleed damage calculated by this formula: (creature:getLevel() / 3) + (skill * 0.4) + 8." />

This will give the player information to make a choice of which item they want to "craft", so they can make a decision based on good information.
 
Last edited:
Thank you again for your answer :)

Yes I kinda have this working now, but I want to make it so that people can see the "Items Attributes" when clicking on the "Details" button, like in this example:

View attachment 81768


XML:
<attribute key="description" value="Spell: Bear Claw. This spells targets a single enemy in front on you. It does initial damage calculated by this formula: (player:getLevel() / 5) + (skill * attack * 0.08) + 17, and bleed damage calculated by this formula: (creature:getLevel() / 3) + (skill * 0.4) + 8." />

This will give the player information to make a choice of which item they want to "craft", so they can make a decision based on good information.
Is possible.

But inside of the modal windows and not outside, near the picture.

You need get all the values in order to show for example the correct abilities with correct name.
Since in order to get Item Attributes you need use: ItemType, then here you can get the Attack, Defense, Abilities, HitChance, etc.

Abilities means, Skill, absorb.... And here is that you need create a for loop for each ability in order to show it, but also add the correct name for each one ( here i leave it to you the code how i have done this, don't have time to finish it ).


1706802177053.png

So here it shows that grand Sanguine Crossbow has 10 attack ( true in my case ), then abilities 4 for example is the Skill Dist, as other ones are sword/club...

After this code:
Lua:
for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                local reqItems = config.system[lastChoice].items[choice.id].reqItems[i].item
                local reqItemsCount = config.system[lastChoice].items[choice.id].reqItems[i].count
                local reqItemsOnPlayer = self:getItemCount(reqItems)
                details = details .. "\n- " .. capAll(getItemName(reqItems) .. " { " .. reqItemsOnPlayer .. "/" .. reqItemsCount .. " }")
            end


add this one ( that show item description ):
Code:
local itemId = config.system[lastChoice].items[choice.id].itemID
local itemType = ItemType(itemId)

if itemType then
    local attributes = {
        "Attack",
    }
    for _, attributeName in ipairs(attributes) do
        local attributeValue = itemType:getAttack()
        local attributeValue2 = itemType:getDefense()
        local attributeValue3 = itemType:getAbilities()
        local skills = attributeValue3.skills
        if attributeValue or attributeValue2 or attributeValue3 then
            details = details .. "\n- Attack: " .. attributeValue
            details = details .. "\n- Defense" .. attributeValue2
            for i = 1, 5 do
                local skillValue = skills[i]
            details = details .. "\n- Abilities" .. skillValue
            end
        end
    end
end

the local attributes, leave it with the Attack ,

AttributeValue, first one is getAttack , for weapons
AttributeValue2, in order to getDefense,
AttributeValue3, is Abilities, but here we called only about Skills since, abilities has much more information, such as absorb, Mana, Health, Stats, Special Skills (crit..), etc.
 
Is possible.

But inside of the modal windows and not outside, near the picture.

You need get all the values in order to show for example the correct abilities with correct name.
Since in order to get Item Attributes you need use: ItemType, then here you can get the Attack, Defense, Abilities, HitChance, etc.

Abilities means, Skill, absorb.... And here is that you need create a for loop for each ability in order to show it, but also add the correct name for each one ( here i leave it to you the code how i have done this, don't have time to finish it ).


View attachment 81793

So here it shows that grand Sanguine Crossbow has 10 attack ( true in my case ), then abilities 4 for example is the Skill Dist, as other ones are sword/club...

After this code:
Lua:
for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                local reqItems = config.system[lastChoice].items[choice.id].reqItems[i].item
                local reqItemsCount = config.system[lastChoice].items[choice.id].reqItems[i].count
                local reqItemsOnPlayer = self:getItemCount(reqItems)
                details = details .. "\n- " .. capAll(getItemName(reqItems) .. " { " .. reqItemsOnPlayer .. "/" .. reqItemsCount .. " }")
            end


add this one ( that show item description ):
Code:
local itemId = config.system[lastChoice].items[choice.id].itemID
local itemType = ItemType(itemId)

if itemType then
    local attributes = {
        "Attack",
    }
    for _, attributeName in ipairs(attributes) do
        local attributeValue = itemType:getAttack()
        local attributeValue2 = itemType:getDefense()
        local attributeValue3 = itemType:getAbilities()
        local skills = attributeValue3.skills
        if attributeValue or attributeValue2 or attributeValue3 then
            details = details .. "\n- Attack: " .. attributeValue
            details = details .. "\n- Defense" .. attributeValue2
            for i = 1, 5 do
                local skillValue = skills[i]
            details = details .. "\n- Abilities" .. skillValue
            end
        end
    end
end

the local attributes, leave it with the Attack ,

AttributeValue, first one is getAttack , for weapons
AttributeValue2, in order to getDefense,
AttributeValue3, is Abilities, but here we called only about Skills since, abilities has much more information, such as absorb, Mana, Health, Stats, Special Skills (crit..), etc.
Thank you SO much my friend. I will test this <3
 
Is possible.

But inside of the modal windows and not outside, near the picture.

You need get all the values in order to show for example the correct abilities with correct name.
Since in order to get Item Attributes you need use: ItemType, then here you can get the Attack, Defense, Abilities, HitChance, etc.

Abilities means, Skill, absorb.... And here is that you need create a for loop for each ability in order to show it, but also add the correct name for each one ( here i leave it to you the code how i have done this, don't have time to finish it ).


View attachment 81793

So here it shows that grand Sanguine Crossbow has 10 attack ( true in my case ), then abilities 4 for example is the Skill Dist, as other ones are sword/club...

After this code:
Lua:
for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                local reqItems = config.system[lastChoice].items[choice.id].reqItems[i].item
                local reqItemsCount = config.system[lastChoice].items[choice.id].reqItems[i].count
                local reqItemsOnPlayer = self:getItemCount(reqItems)
                details = details .. "\n- " .. capAll(getItemName(reqItems) .. " { " .. reqItemsOnPlayer .. "/" .. reqItemsCount .. " }")
            end


add this one ( that show item description ):
Code:
local itemId = config.system[lastChoice].items[choice.id].itemID
local itemType = ItemType(itemId)

if itemType then
    local attributes = {
        "Attack",
    }
    for _, attributeName in ipairs(attributes) do
        local attributeValue = itemType:getAttack()
        local attributeValue2 = itemType:getDefense()
        local attributeValue3 = itemType:getAbilities()
        local skills = attributeValue3.skills
        if attributeValue or attributeValue2 or attributeValue3 then
            details = details .. "\n- Attack: " .. attributeValue
            details = details .. "\n- Defense" .. attributeValue2
            for i = 1, 5 do
                local skillValue = skills[i]
            details = details .. "\n- Abilities" .. skillValue
            end
        end
    end
end

the local attributes, leave it with the Attack ,

AttributeValue, first one is getAttack , for weapons
AttributeValue2, in order to getDefense,
AttributeValue3, is Abilities, but here we called only about Skills since, abilities has much more information, such as absorb, Mana, Health, Stats, Special Skills (crit..), etc.
Hi there my friend. First off, thank you for putting time into helping me :)

Second, Not sure if i made it clear, but what I want is for the item Description to show aswell.

Example:

XML:
<item id="27090" name="spellbook 1">
        <attribute key="weight" value="320" />
        <attribute key="description" value="Death Touch: This spell touches a single target with the range of 1. Freezes enemy and add death damage to target" />
        <attribute key="showcount" value="0" />
    </item>

This needs to show inside the Details window:

XML:
<attribute key="description" value="Death Touch: This spell touches a single target with the range of 1. Freezes enemy and add death damage to target" />


Is this possible?
 
Hi there my friend. First off, thank you for putting time into helping me :)

Second, Not sure if i made it clear, but what I want is for the item Description to show aswell.

Example:

XML:
<item id="27090" name="spellbook 1">
        <attribute key="weight" value="320" />
        <attribute key="description" value="Death Touch: This spell touches a single target with the range of 1. Freezes enemy and add death damage to target" />
        <attribute key="showcount" value="0" />
    </item>

This needs to show inside the Details window:

XML:
<attribute key="description" value="Death Touch: This spell touches a single target with the range of 1. Freezes enemy and add death damage to target" />


Is this possible?


I give you the tip how to do it,

Now if you search you find itemType:getDescription, this one obtains Description from an item:
Lua:
int LuaScriptInterface::luaItemTypeGetDescription(lua_State* L)
{
    // itemType:getDescription()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        pushString(L, itemType->description);
    } else {
        lua_pushnil(L);
    }
    return 1;
}

So now you know you can do it something like this:
Code:
local itemId = config.system[lastChoice].items[choice.id].itemID
local itemType = ItemType(itemId)

if itemType then
    local attributeValue = itemType:getDescription()
    if attributeValue then
        details = details .."\n- Description:" .. attributeValue
    end
end
 
Back
Top