• 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!

Lua Creating a cooking skill in lua TFS 1.3

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys, I have this script that I use for cooking and I would like to implement a skill on it, however I don't have the knowledge to implement in the TFS neither on the client, so I would like some help to create this skill inside the script below. The skill would increase everytime you cook something. Each recipe would give a different amount of skill experience. To create some difficult recipes the player would need to have a certain amount of skill. Also I would like for the player to check his cooking skill somehow.

Lua:
local config = {
-- Configuracao da Janela Modal
    mainTitleMsg = "Cooking System", -- TITUTLO DA JANELA QUE ABRE
    mainMsg = "Welcome to the cooking system. Please choose a type of food to begin.", -- MENSAGEM DA JANELA
 
    craftTitle = "Cooking System: ", -- Titulo da tela de craft apos o player selecionar a vocacao destinada dos items
    craftMsg = "Here is a list of all items that can be cooked", -- Mensagem na tela de craft após escolhas do jogador de vocação
-- Fim da config Janela Modal
 
-- Notificacoes ao player
    needItems = "You do not have all the required items to make ", -- Mensagem que aparece quando o player tenta craftar e nao tem todos os items
 
-- Configuracoes de Crafting
    system = {
    [1] = {vocation = "Salt", -- Isto e apenas uma categoria, nao influencia em nada
            items = {
                [1] = {item = "Fried Fish Fillet", -- item name (O NOME TEM QUE SER EXATO, SENAO NAO FUNCIONA!)
                        itemID = 7756, -- ID do item que sera feito, tem que ser compativel com o nome acima
                        reqItems = { -- items e quantidade dos items necessarios para craftar
                                [1] = {item = 5921, count = 1}, -- heaven blossom
                                [2] = {item = 27905, count = 2}, -- Small Fish
                            },
                        },
                  
                [2] = {item = "Consecrated Beef",
                        itemID = 7748,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [3] = {item = "Roasted Meat",
                        itemID = 7755,   
                        reqItems = {
                                [1] = {item = 7754, count = 1}, -- Raw Meat
                                [2] = {item = 11245, count = 1}, -- bunch of ripe rice
                            },
                        },
                  
                [4] = {item = "Delicatessen Salad",
                        itemID = 7750,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [5] = {item = "Tropical Marinated Tiger",
                        itemID = 7764,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [6] = {item = "Stockfish",
                        itemID = 7757,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [7] = {item = "Salmon Fillet",
                        itemID = 7763,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [8] = {item = "Shark Steak",
                        itemID = 7771,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [9] = {item = "Fish With Troll",
                        itemID = 7858,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [10] = {item = "Grilled Common Fish Without Head",
                        itemID = 7856,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [11] = {item = "Grilled Common Fish With Head",
                        itemID = 7857,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [12] = {item = "Fish and Octopus",
                        itemID = 7777,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [13] = {item = "Uncommon Fish With Troll",
                        itemID = 7855,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [14] = {item = "Uncommon Fish Soup",
                        itemID = 7774,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [15] = {item = "Grilled Uncommon Fish Without Head",
                        itemID = 7776,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [16] = {item = "Grilled Uncommon Fish With Head",
                        itemID = 7854,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [17] = {item = "Uncommon Shark Steak",
                        itemID = 7775,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [18] = {item = "Uncommon Fish And Octopus",
                        itemID = 7772,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [19] = {item = "Uncommon Octopus in a Plate",
                        itemID = 7862,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [20] = {item = "Rare Fish With Troll",
                        itemID = 7770,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [21] = {item = "Common Fish Soup",
                        itemID = 7766,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [22] = {item = "Grilled Rare Fish Without Head",
                        itemID = 7768,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [23] = {item = "Grilled Rare Fish With Head",
                        itemID = 7769,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [24] = {item = "Rare Shark Steak",
                        itemID = 7767,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [25] = {item = "Rare Octopus in a Plate",
                        itemID = 7765,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [26] = {item = "Deepsea Fish With Troll",
                        itemID = 7747,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [27] = {item = "Deepsea Fish Soup",
                        itemID = 7861,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [28] = {item = "Grilled Deepsea Fish Without Head",
                        itemID = 7745,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [29] = {item = "Grilled Deepsea Fish With Head",
                        itemID = 7746,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [30] = {item = "Deepsea Shark Steak",
                        itemID = 7773,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [31] = {item = "Deepsea Fish And Octopus",
                        itemID = 7859,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                  
                [32] = {item = "Deepsea Octopus in a Plate",
                        itemID = 7860,   
                        reqItems = {
                                [1] = {item = 2671, count = 2}, -- ham
                                [2] = {item = 2684, count = 1}, -- carrot
                                [3] = {item = 2741, count = 2}, -- moon flower
                            },
                        },
                     },
                },
                
    [2] = {vocation = "Sweet",
            items = {
                [1] = {item = "Blueberry Cupcake",
                        itemID = 7744,
                        reqItems = {
                                [1] = {item = 8839, count = 1}, -- plum
                                [2] = {item = 2677, count = 5}, -- blueberries
                                [3] = {item = 5467, count = 2}, -- bunch of sugar cane
                                [4] = {item = 7245, count = 1}, -- piece of cactus
                                [5] = {item = 2796, count = 1}, -- green mushroom
                            },
                        },
                  
                [2] = {item = "Strawberry Cupcake",
                        itemID = 7758,   
                        reqItems = {
                                [1] = {item = 2680, count = 1}, -- strawberry
                                [2] = {item = 8840, count = 1}, -- raspberry
                                [3] = {item = 5467, count = 2}, -- bunch of sugar cane
                                [4] = {item = 7245, count = 1}, -- piece of cactus
                                [5] = {item = 27924, count = 1}, -- Rare Red Mushroom
                            },
                        },
                  
                [3] = {item = "Lemon Cupcake",
                        itemID = 7752,   
                        reqItems = {
                                [1] = {item = 8841, count = 1}, -- lemon
                                [2] = {item = 27918, count = 1}, -- Hot Mushroom
                                [3] = {item = 5467, count = 2}, -- bunch of sugar cane
                                [4] = {item = 7245, count = 1}, -- piece of cactus
                                [5] = {item = 2795, count = 1}, -- fire mushroom
                                [6] = {item = 27927, count = 1}, -- Strange Mushroom
                            },
                        },
                  
                [4] = {item = "Meringue Cake",
                        itemID = 7753,   
                        reqItems = {
                                [1] = {item = 28014, count = 1}, -- Forbidden Fruit
                                [2] = {item = 27913, count = 1}, -- Venomous Mushroom
                                [3] = {item = 5467, count = 2}, -- bunch of sugar cane
                                [4] = {item = 7245, count = 1}, -- piece of cactus
                            },
                        },
                     },
                },                           
            },
                
        }
        
              
local player = Player(cid)
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)

        player:sendMainCraftWindow(config)

    return true
end
 
Interesting, however I would like not to deal with client neither source edit. My Client is heavly edited and I'm afraid if I add anything new I might corrupt something. That's why I would like to add it throw .lua
 
View attachment 68478
View attachment 68479
Looks like you didn't even saw the code.
I'm sorry when I saw the client folder I imagine that it envolved source edit. Your script is just like what I need, however I'm with a little problem, can you help me solve it?

Icarai has logged in.

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/login.lua:eek:nLogin
data/lib/core/player.lua:84: attempt to index local 'json' (a boolean value)
stack traceback:
[C]: in function '__index'
data/lib/core/player.lua:84: in function 'sendExtendedOpcode'
data/lib/custom/cooking.lua:37: in function 'sendData'
data/creaturescripts/scripts/login.lua:32: in function <data/creaturescripts/scripts/login.lua:1>
Icarai has logged out.
That error happen when I try to enter the server.

data/lib/core/player:
Lua:
local foodCondition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
local json = require('data/lib/core/json')

function Player.feed(self, food)
    local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition then
        condition:setTicks(condition:getTicks() + (food * 1000))
    else
        local vocation = self:getVocation()
        if not vocation then
            return nil
        end

        foodCondition:setTicks(food * 1000)
        foodCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, vocation:getHealthGainAmount())
        foodCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, vocation:getHealthGainTicks() * 1000)
        foodCondition:setParameter(CONDITION_PARAM_MANAGAIN, vocation:getManaGainAmount())
        foodCondition:setParameter(CONDITION_PARAM_MANATICKS, vocation:getManaGainTicks() * 1000)

        self:addCondition(foodCondition)
    end
    return true
end

function Player.getClosestFreePosition(self, position, extended)
    if self:getGroup():getAccess() and self:getAccountType() >= ACCOUNT_TYPE_GOD then
        return position
    end
    return Creature.getClosestFreePosition(self, position, extended)
end

function Player.getDepotItems(self, depotId)
    return self:getDepotChest(depotId, true):getItemHoldingCount()
end

function Player.hasFlag(self, flag)
    return self:getGroup():hasFlag(flag)
end

function Player.getLossPercent(self)
    local blessings = 0
    local lossPercent = {
        [0] = 100,
        [1] = 70,
        [2] = 45,
        [3] = 25,
        [4] = 10,
        [5] = 0
    }

    for i = 1, 5 do
        if self:hasBlessing(i) then
            blessings = blessings + 1
        end
    end
    return lossPercent[blessings]
end

function Player.isPremium(self)
    return self:getPremiumDays() > 0 or configManager.getBoolean(configKeys.FREE_PREMIUM)
end

function Player.sendCancelMessage(self, message)
    if type(message) == "number" then
        message = Game.getReturnMessage(message)
    end
    return self:sendTextMessage(MESSAGE_STATUS_SMALL, message)
end

function Player.isUsingOtClient(self)
    return self:getClient().os >= CLIENTOS_OTCLIENT_LINUX
end

function Player.sendExtendedOpcode(self, opcode, buffer, json)
    if not self:isUsingOtClient() then
        return false
    end

    local networkMessage = NetworkMessage()
    networkMessage:addByte(0x32)
    networkMessage:addByte(opcode)

    if (json) then
        networkMessage:addString(json.encode(buffer))
    else
        networkMessage:addString(buffer)
    end

    networkMessage:sendToPlayer(self)
    networkMessage:delete()
    return true
end

APPLY_SKILL_MULTIPLIER = true
local addSkillTriesFunc = Player.addSkillTries
function Player.addSkillTries(...)
    APPLY_SKILL_MULTIPLIER = false
    local ret = addSkillTriesFunc(...)
    APPLY_SKILL_MULTIPLIER = true
    return ret
end

local addManaSpentFunc = Player.addManaSpent
function Player.addManaSpent(...)
    APPLY_SKILL_MULTIPLIER = false
    local ret = addManaSpentFunc(...)
    APPLY_SKILL_MULTIPLIER = true
    return ret
end

function Player.depositMoney(self, amount)
   if not self:removeMoney(amount) then
       return false
   end

   self:setBankBalance(self:getBankBalance() + amount)
   return true
end

function Player.withdrawMoney(self, amount)
   local balance = self:getBankBalance()
   if amount > balance or not self:addMoney(amount) then
       return false
   end

   self:setBankBalance(balance - amount)
   return true
end

function Player.transferMoneyTo(self, target, amount)
   local balance = self:getBankBalance()
   if amount > balance then
       return false
   end

   local targetPlayer = Player(target)
   if targetPlayer then
       targetPlayer:setBankBalance(targetPlayer:getBankBalance() + amount)
   else
       if not playerExists(target) then
           return false
       end
       db.query("UPDATE `players` SET `balance` = `balance` + '" .. amount .. "' WHERE `name` = " .. db.escapeString(target))
   end

   self:setBankBalance(self:getBankBalance() - amount)
   return true
end
 
This error means that server was unable to load json file (probably require returned a boolean value - false in your case). Check that you have placed file in the right place and try again.
Everything seems to be in the right place.
Post automatically merged:

Everything seems to be in the right place.
Maybe it's a different TFS or Client version?
 
Last edited:
Back
Top