• 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.x] Crafting System

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
First of all, I didn't make the entire system by myself, I took some functions/ideas from other people who posted them here on OtLand (credits on the functions itself).
Special thanks to @Ninja for the help with the table config.

This system is/was based on TERA's crafting system (NA), this means that you CAN'T fail at crafting.
Gathering system isn't included atm, but I might add it later.

This should be the config on you map (Please IGNORE the map lol)


Some screens of the system:






Actions:
actions.xml

Code:
<action fromaid="50501" toaid="50506" script="craftsys.lua"/>
- 50501 is the first profession on the config file, and 50506 is the last one. You can add more if you want but need to add all the new professions ids in some files.


actions/scripts/craftsys.lua
Code:
function onUse(player, item, fromPosition, itemEx, toPosition)
   local found = 0
   local recipes = craftingProfessionsConfig[item.actionid].skillRecipes
   local modal = ModalWindow(item.actionid, ""..craftingProfessionsConfig[item.actionid].skillName.." (Crafting Skill: "..player:getCustomSkill(item.actionid).."/"..craftingProfessionsConfig.maxSkill..")", craftingProfessionsConfig[item.actionid].message)

   if item.itemid == 8046 and isInArray({50501, 50502, 50503, 50504, 50505, 50506}, item.actionid) then
     if getCreatureCondition(player, CONDITION_SPELLCOOLDOWN, 160) then --I don't really know how to use :getCreatureCondition, it never works for me.
       return player:sendCancelMessage("You are already crafting.")
     end

     if not player:isProfession(item.actionid) then
       return player:sendCancelMessage("You need to learn "..craftingProfessionsConfig[item.actionid].skillName.." before using this.")
     end

     for i = 1, #recipes do
       if player:getStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[i].storage) == 1 then
         modal:addChoice(i, capAll(getItemName(recipes[i].item))--[[.." ["..recipes[i].skill.."]"]])
       end
     end

     craftingProfessionsConfig.extraData[player:getId()] = {
       lastPos = Item(item.uid):getPosition()
     }

     if modal:getChoiceCount() ~= 0 then
       modal:addButton(1, "Create")
       modal:setDefaultEnterButton(1)
       modal:addButton(2, "Exit")
       modal:setDefaultEscapeButton(2)
       modal:addButton(3, "Materials")
       modal:sendToPlayer(player)
     else
       player:sendCancelMessage("You need to learn some "..craftingProfessionsConfig[item.actionid].skillName.." recipes first.")
     end
   elseif item.itemid == 1967 and item.actionid >= craftingProfessionsConfig.baseRecipeStorage then
     for i = 1, #recipes do
       if recipes[i].storage == tonumber(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_TEXT)) then
         found = i
       end
     end
     if found == 0 then return player:sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT) end
     if player:getStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[found].storage) == -1 then
       if player:getCustomSkill(item.actionid) >= recipes[found].skill then
         player:setStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[found].storage, 1)
         player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You learned how to make "..capAll(getItemName(recipes[found].item))..".")
         player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
         Item(item.uid):remove(1)
       else
         player:sendCancelMessage("You require "..recipes[found].skill.." crafting skill in "..craftingProfessionsConfig[item.actionid].skillName.." to learn this recipe.")
       end
     else
       player:sendCancelMessage("You have already learned this recipe.")
     end
   elseif item.itemid == 2217 and item.actionid >= craftingProfessionsConfig.baseRecipeStorage then
     if player:getStorageValue(item.actionid) == -1 then
       player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You have learned "..craftingProfessionsConfig[item.actionid].skillName..", then the book burned to ashes after learning it's secrets.")
       player:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
       player:setStorageValue(item.actionid, 10)
       Item(item.uid):remove(1)
     else
       player:sendCancelMessage("You already know "..craftingProfessionsConfig[item.actionid].skillName..".")
     end
   end
   return true
end
Creaturescripts:
creaturescripts.xml
Code:
<event type="modalwindow" name="craftingMW" script="crafting.lua"/>
creaturescripts/scripts/crafting.lua
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
   if not isInArray({50501, 50502, 50503, 50504, 50505, 50506}, modalWindowId) or buttonId == 2 then
     return false
   end
   local count = 0
   local recipes = craftingProfessionsConfig[modalWindowId].skillRecipes
   local str = ""..capAll(getItemName(recipes[choiceId].item)).."\n  Skill Needed: "..recipes[choiceId].skill.." - Point Cost: 1p\n\nMaterials:"
   if buttonId == 3 then
     for i = 1, #recipes[choiceId].mats do
       str = str.."\n- "..capAll(getItemName(recipes[choiceId].mats[i][1])).." ("..player:getItemCount(recipes[choiceId].mats[i][1]).."/"..recipes[choiceId].mats[i][2]..")"
     end
     if str ~= "" then
       player:showTextDialog(recipes[choiceId].item, str)
     end
     return true
   end
   for i = 1, #recipes[choiceId].mats do
     if player:getItemCount(recipes[choiceId].mats[i][1]) >= recipes[choiceId].mats[i][2] then
       count = count + 1
     end
   end
   if count == #recipes[choiceId].mats then
     local craftCD = Condition(CONDITION_SPELLCOOLDOWN)
     craftCD:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
     craftCD:setParameter(CONDITION_PARAM_SUBID, 160)
     craftCD:setParameter(CONDITION_PARAM_TICKS, recipes[choiceId].time * 1000)
     player:addCondition(craftCD)
     player:allowMovement(false)
     player:say("Crafting...", TALKTYPE_MONSTER_SAY)
     local itemPos = craftingProfessionsConfig.extraData[player:getId()].lastPos
     function sendAnimation(times) --This needs to be improved
       itemPos:sendMagicEffect(CONST_ME_BLOCKHIT)
       if times == 0 then
         return true
       end
       addEvent(sendAnimation, 1000, times - 1)
     end
     sendAnimation(recipes[choiceId].time)
     for i = 1, count do
       player:removeItem(recipes[choiceId].mats[i][1], recipes[choiceId].mats[i][2])
     end
     addEvent(function(id)
       local player = Player(id)
       if player then
         local craftedItem = player:addItem(recipes[choiceId].item, 1)
         if craftedItem then
           player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You've successfully crafted "..craftedItem:getArticle().." "..capAll(craftedItem:getName())..".")
           craftedItem:setAttribute(ITEM_ATTRIBUTE_NAME, "crafted "..craftedItem:getName())
           player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
           --doWriteLogFile("data/logs/craf.log", player:getName() .." crafted the following item: ".. craftedItem:getName() .." [".. craftedItem:getId() .."].")
           if craftedItem:getType():getDescription() ~= "" then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, craftedItem:getType():getDescription().."\nCrafted by "..player:getName()..".")
           else
             craftedItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Crafted by "..player:getName()..".")
           end
           if craftedItem:getType():getAttack() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.attack ~= nil then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_ATTACK, craftedItem:getType():getAttack() + recipes[choiceId].attr.attack)
           end
           if craftedItem:getType():getDefense() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.defense ~= nil then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_DEFENSE, craftedItem:getType():getDefense() + recipes[choiceId].attr.defense)
           end
           if craftedItem:getType():getExtraDefense() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.extradefense ~= nil then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, craftedItem:getType():getExtraDefense() + recipes[choiceId].attr.extradefense)
           end
           if craftedItem:getType():getArmor() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.armor ~= nil then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_ARMOR, craftedItem:getType():getArmor() + recipes[choiceId].attr.armor)
           end
           if craftedItem:getType():getHitChance() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.hitchance ~= nil then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_HITCHANCE, craftedItem:getType():getHitChance() + recipes[choiceId].attr.hitchance)
           end
           if craftedItem:getType():getShootRange() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.shootrange ~= nil then
             craftedItem:setAttribute(ITEM_ATTRIBUTE_SHOOTRANGE, craftedItem:getType():getShootRange() + recipes[choiceId].attr.shootrange)
           end
         end
         skillGain = (recipes[choiceId].difficulty / 10)
         for i = 1, skillGain do
           player:addCustomSkillTry(craftingProfessionsConfig[modalWindowId].skillName, modalWindowId)
         end
         player:allowMovement(true)
       end
     end, recipes[choiceId].time * 1000, player:getId())
   else
     player:sendCancelMessage("You don't have all the materials to craft this item.")
   end
   return true
end
 
Last edited:
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
Config part:
data/craftsystem.lua
Code:
function Player.isProfession(self, storage)
   if self:getStorageValue(storage) >= 1 then
     return true
   end
end
craftingProfessionsConfig = {
   [50501] = {
     skillName = "Blacksmithing",
     skillRecipes = {
       [1] = {item = 2400, skill = 10, storage = 101, mats = {{2554, 1}, {2120, 1}}, time = 5, difficulty = 20},
       [2] = {item = 2432, skill = 15, storage = 102, mats = {{2148, 10}, {10608, 10}}, time = 5, difficulty = 20},
       [3] = {item = 2178, skill = 20, storage = 103, mats = {{2177, 1}, {1295, 1}, {2146, 3}}, time = 5, difficulty = 40},
       [4] = {item = 5944, skill = 20, storage = 104, mats = {{2177, 1}, {1295, 1}, {2150, 3}}, time = 5, difficulty = 40},
       [5] = {item = 2363, skill = 25, storage = 105, mats = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, time = 5, difficulty = 50},
       [6] = {item = 10092, skill = 30, storage = 106, mats = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, time = 5, difficulty = 60},
       [7] = {item = 4864, skill = 35, storage = 107, mats = {{4850, 1}, {2913, 1}, {2144, 1}}, time = 5, difficulty = 40}
     },
     message = "Crafting allows you to create anything from potions to bombs to weapons of the highest caliber. The materials used in crafting can be obtained through gathering and through drops in dungeons and the open world.\n\n"
   },
   [50502] = {
     skillName = "Alchemy",
     skillRecipes = { --Based on Shinmaru/Soul4Soul Alchemy's System
       [1] = {item = 8474, skill = 10, storage = 201, mats = {{2007, 1}, {2795, 1}, {2760, 1}}, time = 5, difficulty = 20},
       [2] = {item = 2152, skill = 15, storage = 202, mats = {{2148, 10}, {10608, 2}}, time = 5, difficulty = 20},
       [3] = {item = 2178, skill = 20, storage = 203, mats = {{2177, 1}, {1295, 1}, {2146, 3}}, time = 5, difficulty = 40},
       [4] = {item = 5944, skill = 20, storage = 204, mats = {{2177, 1}, {1295, 1}, {2150, 3}}, time = 5, difficulty = 40},
       [5] = {item = 2363, skill = 25, storage = 205, mats = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, time = 5, difficulty = 50},
       [6] = {item = 10092, skill = 30, storage = 206, mats = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, time = 5, difficulty = 60},
       [7] = {item = 4864, skill = 35, storage = 207, mats = {{4850, 1}, {2913, 1}, {2144, 1}}, time = 5, difficulty = 40},
       [8] = {item = 2276, skill = 40, storage = 208, mats = {{10558, 1}, {2260, 1}, {10554, 1}, {2151, 1}, {5951, 1}, {2265, 1}}, time = 5, difficulty = 40},
       [9] = {item = 2160, skill = 45, storage = 209, mats = {{2152, 1}, {2145, 1}, {2146, 1}, {2800, 1}}, time = 5, difficulty = 30},
       [10] = {item = 11201, skill = 45, storage = 210, mats = {{2759, 1}, {10565, 1}, {2803, 1}, {2692, 1}}, time = 5, difficulty = 40},
       [11] = {item = 5892, skill = 5, storage = 211, mats = {{5468, 1}, {2393, 1}}, time = 5, difficulty = 50},
       [12] = {item = 5887, skill = 5, storage = 212, mats = {{5468, 1}, {2487, 1}}, time = 5, difficulty = 50},
       [13] = {item = 5888, skill = 5, storage = 213, mats = {{5468, 1}, {2462, 1}}, time = 5, difficulty = 50},
       [14] = {item = 5889, skill = 5, storage = 214, mats = {{5468, 1}, {2516, 1}}, time = 5, difficulty = 50},
       [15] = {item = 5891, skill = 10, storage = 215, mats = {{2195, 1}, {4265, 1}, {2151, 1}}, time = 5, difficulty = 40},
       [16] = {item = 5884, skill = 10, storage = 216, mats = {{2498, 1}, {2498, 1}, {2913, 1}, {5865, 1}}, time = 5, difficulty = 40},
       [17] = {item = 5885, skill = 10, storage = 217, mats = {{2475, 1}, {2475, 1}, {2475, 1}, {2475, 1}, {2015, 1}, {5865, 1}}, time = 5, difficulty = 40},
       [18] = {item = 7439, skill = 60, storage = 218, mats = {{6558, 1}, {2007, 1}, {4993, 1}, {5480, 1}, {2796, 1}}, time = 5, difficulty = 30},
       [19] = {item = 7440, skill = 60, storage = 219, mats = {{6558, 1}, {2007, 1}, {4992, 1}, {3955, 1}, {7250, 1}}, time = 5, difficulty = 30},
       [20] = {item = 7443, skill = 60, storage = 220, mats = {{6558, 1}, {2007, 1}, {4994, 1}, {2193, 1}, {2031, 1}}, time = 5, difficulty = 30},
       [21] = {item = 7140, skill = 65, storage = 221, mats = {{7141, 1}, {2015, 1}, {5014, 1}, {2235, 1}, {7439, 1}, {7440, 1}, {7443, 1}, {4845, 1}}, time = 5, difficulty = 60},
       [22] = {item = 9971, skill = 70, storage = 222, mats = {{10552, 1}, {2157, 1}, {2159, 1}, {5906, 1}}, time = 5, difficulty = 50},
       [23] = {item = 2284, skill = 75, storage = 223, mats = {{10523, 1}, {2260, 1}, {10554, 1}, {2151, 1}, {2273, 1}}, time = 5, difficulty = 30},
       [24] = {item = 11387, skill = 80, storage = 224, mats = {{2805, 1}, {2798, 1}, {8582, 1}}, time = 5, difficulty = 70},
       [25] = {item = 8980, skill = 90, storage = 225, mats = {{5941, 1}, {10559, 1}, {2194, 1}, {2377, 1}}, time = 5, difficulty = 80},
       [26] = {item = 2184, skill = 90, storage = 226, mats = {{9942, 1}, {9941, 1}, {9980, 1}, {2445, 1}}, time = 5, difficulty = 80},
       [27] = {item = 2352, skill = 90, storage = 227, mats = {{2177, 1}, {2160, 1}, {2544, 1}, {2544, 1}, {2802, 1}}, time = 5, difficulty = 80},
       [28] = {item = 9969, skill = 100, storage = 228, mats = {{5741, 1}, {2229, 1}, {5669, 1}, {5809, 1}, {2143, 1}}, time = 5, difficulty = 90},
       [29] = {item = 9006, skill = 110, storage = 229, mats = {{8859, 1}, {2289, 1}, {2807, 1}, {10556, 1}, {2545, 1}, {5879, 1}}, time = 5, difficulty = 100},
       [30] = {item = 2348, skill = 120, storage = 230, mats = {{2153, 1}, {2154, 1}, {2155, 1}, {2156, 1}, {2158, 1}, {2260, 1}, {2260, 1}, {2600, 1}}, time = 5, difficulty = 100}
     },
     message = "Crafting allows you to create ~"
   },
   [50503] = {
     skillName = "Inscription",
     skillRecipes = {
       [1] = {item = 2400, skill = 10, storage = 301, mats = {{2554, 1}, {2120, 1}}, time = 5, difficulty = 20, attr = {attack = 10,  defense = 10}},
       [2] = {item = 2432, skill = 15, storage = 302, mats = {{2148, 10}, {10608, 10}}, time = 5, difficulty = 20},
       [3] = {item = 2178, skill = 20, storage = 303, mats = {{2177, 1}, {1295, 1}, {2146, 3}}, time = 5, difficulty = 40},
       [4] = {item = 5944, skill = 20, storage = 304, mats = {{2177, 1}, {1295, 1}, {2150, 3}}, time = 5, difficulty = 40},
       [5] = {item = 2363, skill = 25, storage = 305, mats = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, time = 5, difficulty = 50},
       [6] = {item = 10092, skill = 30, storage = 306, mats = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, time = 5, difficulty = 60},
       [7] = {item = 4864, skill = 35, storage = 307, mats = {{4850, 1}, {2913, 1}, {2144, 1}}, time = 5, difficulty = 40}
     },
     message = "Crafting allows you to create ~"
   },
   [50504] = {
     skillName = "Tailoring",
     skillRecipes = {
       [1] = {item = 2400, skill = 10, storage = 401, mats = {{2554, 1}, {2120, 1}}, time = 5, difficulty = 20},
       [2] = {item = 2432, skill = 15, storage = 402, mats = {{2148, 10}, {10608, 10}}, time = 5, difficulty = 20},
       [3] = {item = 2178, skill = 20, storage = 403, mats = {{2177, 1}, {1295, 1}, {2146, 3}}, time = 5, difficulty = 40},
       [4] = {item = 5944, skill = 20, storage = 404, mats = {{2177, 1}, {1295, 1}, {2150, 3}}, time = 5, difficulty = 40},
       [5] = {item = 2363, skill = 25, storage = 405, mats = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, time = 5, difficulty = 50},
       [6] = {item = 10092, skill = 30, storage = 406, mats = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, time = 5, difficulty = 60},
       [7] = {item = 4864, skill = 35, storage = 407, mats = {{4850, 1}, {2913, 1}, {2144, 1}}, time = 5, difficulty = 40}
     },
     message = "Crafting allows you to create ~"
   },
   [50505] = {
     skillName = "Leatherworking",
     skillRecipes = {
       [1] = {item = 2400, skill = 10, storage = 501, mats = {{2554, 1}, {2120, 1}}, time = 5, difficulty = 20},
       [2] = {item = 2432, skill = 15, storage = 502, mats = {{2148, 10}, {10608, 10}}, time = 5, difficulty = 20},
       [3] = {item = 2178, skill = 20, storage = 503, mats = {{2177, 1}, {1295, 1}, {2146, 3}}, time = 5, difficulty = 40},
       [4] = {item = 5944, skill = 20, storage = 504, mats = {{2177, 1}, {1295, 1}, {2150, 3}}, time = 5, difficulty = 40},
       [5] = {item = 2363, skill = 25, storage = 505, mats = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, time = 5, difficulty = 50},
       [6] = {item = 10092, skill = 30, storage = 506, mats = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, time = 5, difficulty = 60},
       [7] = {item = 4864, skill = 35, storage = 507, mats = {{4850, 1}, {2913, 1}, {2144, 1}}, time = 5, difficulty = 40}
     },
     message = "Crafting allows you to create ~"
   },
   [50506] = {
     skillName = "Engineering",
     skillRecipes = {
       [1] = {item = 2400, skill = 10, storage = 601, mats = {{2554, 1}, {2120, 1}}, time = 5, difficulty = 20},
       [2] = {item = 2432, skill = 15, storage = 602, mats = {{2148, 10}, {10608, 10}}, time = 5, difficulty = 20},
       [3] = {item = 2178, skill = 20, storage = 603, mats = {{2177, 1}, {1295, 1}, {2146, 3}}, time = 5, difficulty = 40},
       [4] = {item = 5944, skill = 20, storage = 604, mats = {{2177, 1}, {1295, 1}, {2150, 3}}, time = 5, difficulty = 40},
       [5] = {item = 2363, skill = 25, storage = 605, mats = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, time = 5, difficulty = 50},
       [6] = {item = 10092, skill = 30, storage = 606, mats = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, time = 5, difficulty = 60},
       [7] = {item = 4864, skill = 35, storage = 607, mats = {{4850, 1}, {2913, 1}, {2144, 1}}, time = 5, difficulty = 40}
     },
     message = "Crafting allows you to create ~"
   },
   maxSkill = 200,
   baseRecipeStorage = 50500,
   extraData = {},
}
 
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
Inside the same file of above post (craftsystem.lua)
Code:
--[CustomSkill]-- By: Athern
function Player.getCustomSkill(self, storage)
    return self:getStorageValue(storage)
end
function Player.addCustomSkill(self, skillName, storage)
    local skillStorage = math.max(10, self:getStorageValue(storage))
    local skillTries =  math.max(0, self:getStorageValue(storage + 1))
    self:setStorageValue(storage, skillStorage + 1)
    self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You advanced to " .. string.lower(skillName) .. " level "..self:getCustomSkill(storage)..".")
    self:setStorageValue(storage + 1, 0)
end
function Player.addCustomSkillTry(self, skillName, storage)
    local skillStorage = math.max(10, self:getStorageValue(storage))
    local skillTries =  math.max(0, self:getStorageValue(storage + 1))
    self:setStorageValue(storage + 1, skillTries + 1)
    if skillTries > math.floor(20 * math.pow(1.1, (skillStorage - 11)) / 10) then
        self:addCustomSkill(skillName, storage)
    end
end
function Player.getCustomSkillPercent(self, storage)
    local skillStorage = math.max(10, self:getStorageValue(storage))
    local skillTries =  math.max(0, self:getStorageValue(storage + 1))
    local triesNeeded = math.floor(20 * math.pow(1.1, (skillStorage - 11)) / 10)
    local percent = math.floor(100 * (1 - skillTries / triesNeeded))
    if percent > 1 and percent <= 100 then
        return percent
    else
        percent = 1
        return percent
    end
end
--[/CustomSkill]--
Open data/global.lua and paste this on the first line
Code:
dofile("data/craftsystem.lua")
Well that's all I guess, now I'll explain a little how the config file works.
Code:
[50501] = { --Profession id, used as profession storage aswell.
     skillName = "Blacksmithing", --Profession name.
     skillRecipes = { --This is where the recipes are listed.
       --[recipeid] = {new item to be created, crafting skill needed, materials needed = {{itemid, count}, {itemid, count}}, time need to craft, difficulty = 10-100, (optinal) attr = {{attack}, {defense}}}
       [1] = {item = 2400, skill = 10, storage = 101, mats = {{2554, 1}, {2120, 1}}, time = 5, difficulty = 20},
     },
     message = "Crafting allows you to create anything from potions to bombs to weapons of the highest caliber. The materials used in crafting can be obtained through gathering and through drops in dungeons and the open world.\n\n" --Message showed on the Modal Window.
   },
@EDIT: I forgot to mention 2 things: The learning books needs to be item id 2217 with action id equal to the profession id. The recipes needs to be item id 1967 with action id equal to the profession id and with the text of the storage.

Here is a little example from a looting script
Code:
local item = player:addItem(1967, 1)
local rndm = math.random(50501, 50506)
local rndm2 = math.random(1, #craftingProfessionsConfig[rndm].skillRecipes)

item:setAttribute(ITEM_ATTRIBUTE_TEXT, craftingProfessionsConfig[rndm].skillRecipes[rndm2].storage)
item:setAttribute(ITEM_ATTRIBUTE_NAME, getItemName(craftingProfessionsConfig[rndm].skillRecipes[rndm2].item).." ("..craftingProfessionsConfig[rndm].skillName.." Recipe)")
item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, rndm)
Please tell me if you find any bug or something.
 
Last edited:

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,321
Best answers
0
Reaction score
578
Location
Sweden
Perfect, saved me loads of time!
Thanks alot!

Kind Regards,
Eldin.
 
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
As you can see, with the actual examples you can make a magic sword with a shovel and a rope... So if someone could make some not-stupid recipes, professions and gathering examples that would be awesome.
 

Codinablack

Dreamer
Joined
Dec 26, 2013
Messages
1,217
Best answers
4
Reaction score
376
As you can see, with the actual examples you can make a magic sword with a shovel and a rope... So if someone could make some not-stupid recipes, professions and gathering examples that would be awesome.
When I get the time I will definitely use this and make an awesome custom system, idk about for re-release, but it will be put to good use here....

Just from looking at the picture, I see you have the required items to craft what you want, then I see the crafted item and the required items still there in same backpack. The items didn't get removed (i.e. Magic sword, but rope and shovel are still there)

--I don't really know how to use :getCreatureCondition, it never works for me.
To use it correctly on that line it would be player:getCondition()

It probably doesn't work because you may have tried player:getCreatureCondition()
 
Last edited by a moderator:

Codinablack

Dreamer
Joined
Dec 26, 2013
Messages
1,217
Best answers
4
Reaction score
376
With the current tiles.lua for tfs.1.1 this will not work, it won't allow you to step on that tile. You can add this like
Code:
if item.actionid == 6000 then return end
after this line
Code:
if item.actionid >= 1000 then
as a quick work around, but it needs a better fix than this obviously...

movements/scripts/tiles.lua

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/craftsys.lua:onUse
data/actions/scripts/craftsys.lua:45: attempt to call global 'capAll' (a nil val
ue)
stack traceback:
        [C]: in function 'capAll'
        data/actions/scripts/craftsys.lua:45: in function <data/actions/scripts/
craftsys.lua:1>

Lua Script Error: [Action Interface]
data/actions/scripts/craftsys.lua:onUse
data/actions/scripts/craftsys.lua:17: attempt to call global 'capAll' (a nil val
ue)
stack traceback:
        [C]: in function 'capAll'
        data/actions/scripts/craftsys.lua:17: in function <data/actions/scripts/
craftsys.lua:1>
When I used a recipe to learn, I clicked on the scroll and the text said "101" that was for the magic sword recipe in blacksmithing. Now when I click on it again, it says I have already learned it, but when I try to click on the anvil with it returns that error in console. Previously it told me I had to learn a recipe first, so I know I got everything set up, but apparently capAll was something else left out of the library perhaps?
 
Last edited by a moderator:

LuckyM

Ett är Ett
Joined
Jun 13, 2009
Messages
1,390
Best answers
0
Reaction score
147
Location
Sweden
Should add this to my global server :) would be awesome :)
 
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
Just from looking at the picture, I see you have the required items to craft what you want, then I see the crafted item and the required items still there in same backpack. The items didn't get removed (i.e. Magic sword, but rope and shovel are still there)
That was just for the picture.
About the capAll is just a wrapper for capitalize all the words inside, you can add it or just delete that function.
Code:
function capAll(str)
    return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end))
end
 

Codinablack

Dreamer
Joined
Dec 26, 2013
Messages
1,217
Best answers
4
Reaction score
376
Added in the fix for the nil value, now my character has one learned recipe and nothing is working for him.

Whenever I click on materials, it closes the window and doesn't show an error in console log. Same when I click create. The character has learned blacksmithing magic sword recipe, and that is the only thing that shows up. However it doesn't show materials or creates. I have both a rope and shovel and made sure they were id's 2554 and 2120. I believe since everything looks correct, and no error shows up. The problem is with the count perhaps? Everything else looks like it should work perfectly. My only problems are when it says



Code:
   if buttonId == 3 then
     for i = 1, #recipes[choiceId].mats do


///////////AND//////////

  for i = 1, #recipes[choiceId].mats do
     if player:getItemCount(recipes[choiceId].mats[i][1]) >= recipes[choiceId].mats[i][2] then
       count = count + 1
     end
   end
   if count == #recipes[choiceId].mats then
     local craftCD = Condition(CONDITION_SPELLCOOLDOWN)
 
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
Added in the fix for the nil value, now my character has one learned recipe and nothing is working for him.

Whenever I click on materials, it closes the window and doesn't show an error in console log. Same when I click create. The character has learned blacksmithing magic sword recipe, and that is the only thing that shows up. However it doesn't show materials or creates. I have both a rope and shovel and made sure they were id's 2554 and 2120. I believe since everything looks correct, and no error shows up. The problem is with the count perhaps? Everything else looks like it should work perfectly. My only problems are when it says



Code:
   if buttonId == 3 then
     for i = 1, #recipes[choiceId].mats do


///////////AND//////////

  for i = 1, #recipes[choiceId].mats do
     if player:getItemCount(recipes[choiceId].mats[i][1]) >= recipes[choiceId].mats[i][2] then
       count = count + 1
     end
   end
   if count == #recipes[choiceId].mats then
     local craftCD = Condition(CONDITION_SPELLCOOLDOWN)
Did you registered the modalwindow event to the player? I forgot to mention that part. Because if the count part were wrong it would send a cancel message or something.
 

Codinablack

Dreamer
Joined
Dec 26, 2013
Messages
1,217
Best answers
4
Reaction score
376
Did you registered the modalwindow event to the player? I forgot to mention that part. Because if the count part were wrong it would send a cancel message or something.
LOL! I am such a noob, registered in creaturesevents and login and working now for the material list, but after I try to craft, cooldown appears, but it fails, I get error in console for nil value for 'allowMovement'
 
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
LOL! I am such a noob, registered in creaturesevents and login and working now for the material list, but after I try to craft, cooldown appears, but it fails, I get error in console for nil value for 'allowMovement'
Damn, I'll need to update all my previous post with all the functions then, but you can find allowMovement here
 

Codinablack

Dreamer
Joined
Dec 26, 2013
Messages
1,217
Best answers
4
Reaction score
376
Damn, I'll need to update all my previous post with all the functions then, but you can find allowMovement here
Maybe you should mention the other things: How tiles.lua needs fix or you can't step on that tile for the system. And include the capAll function.

Thanks a million! Found the functions for allowmovement and script too. Added those and now it works perfectly! This is a great system! Thank you very much for this!
 

Codinablack

Dreamer
Joined
Dec 26, 2013
Messages
1,217
Best answers
4
Reaction score
376
@Colors which part of this code is the part that makes it show the sprite id like that for the item about to be crafted?
 
OP
Colors

Colors

Joined
Mar 22, 2013
Messages
935
Best answers
3
Reaction score
251
@Colors which part of this code is the part that makes it show the sprite id like that for the item about to be crafted?
creaturescripts/scripts/crafting.lua
Code:
        if str ~= "" then
            player:showTextDialog(recipes[choiceId].item, str)
        end
First param is the item id (called from the lib)
 

951357

New Member
Joined
Nov 27, 2008
Messages
30
Best answers
0
Reaction score
0
Location
Brazil
That was just for the picture.
About the capAll is just a wrapper for capitalize all the words inside, you can add it or just delete that function.
Code:
function capAll(str)
    return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end))
end
Colors,

If the string is 'filled jalapeño peppers' this function returns 'Filled JalapeñO Peppers'

I made a function that returns 'Filled Jalapeño Peppers', if you know a smaller code than I wrote, please tell us! :)

Code:
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
 
Last edited:
Top