• 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 TFS 1.3 Craft mount with itens in backpack

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys,

I would like a script that when the player for example:
  • uses a pirate map with 5 wood + 3 rust remover + 10 nails in the backpack the player will receive a tin lizzard mount;
  • uses a old piece of paper with 5 bat wing + 4 rust remover + 10 nails in the backpack the player will receive a uniwheel mount;
 
Solution
X
LUA:
local craft = {
    -- itemid --------------- {itemid, amount}
    [1111] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111}, -- check mounts.xml for mount id
    [2222] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111},
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index = craft(item:getId())
    if not index then
        return true
    end
    if player:hasMount(index.rewardMount) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You've already received this mount previously.")
        return true
    end
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i][1]) <...
LUA:
local craft = {
    -- itemid --------------- {itemid, amount}
    [1111] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111}, -- check mounts.xml for mount id
    [2222] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111},
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index = craft(item:getId())
    if not index then
        return true
    end
    if player:hasMount(index.rewardMount) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You've already received this mount previously.")
        return true
    end
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i][1]) < index.requiredItems[i][2] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have the required items.")
            return true
        end
    end
    for i = 1, #index.requiredItems do
        player:removeItem(index.requiredItems[i][1], index.requiredItems[i][2])
    end
    item:remove(1)
    player:addMount(index.rewardMount)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have received a mount.")
    return true
end

for v, k in pairs(craft) do
    action:id(v)
end
action:register()

edit - updating remove item
 
Last edited by a moderator:
Solution
LUA:
local craft = {
    -- itemid --------------- {itemid, amount}
    [1111] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111}, -- check mounts.xml for mount id
    [2222] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111},
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index = craft(item:getId())
    if not index then
        return true
    end
    if player:hasMount(index.rewardMount) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You've already received this mount previously.")
        return true
    end
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i][1]) < index.requiredItems[i][2] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have the required items.")
            return true
        end
    end
    for i = 1, #index.requiredItems do
        player:removeItem(index.requiredItems[i][1], index.requiredItems[i][2])
    end
    player:removeItem(item:getId(), 1)
    player:addMount(index.rewardMount)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have received a mount.")
    return true
end

for v, k in pairs(craft) do
    action:id(v)
end
action:register()

LUA:
local craft = {
    -- itemid --------------- {itemid, amount}
    [1956] = {requiredItems = {{27851, 10}, {27978, 5}}, rewardMount = 8}, -- check mounts.xml for mount id
    [2222] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111},
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index = craft(item:getId())
    if not index then
        return true
    end
    if player:hasMount(index.rewardMount) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You've already received this mount previously.")
        return true
    end
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i][1]) < index.requiredItems[i][2] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have the required items.")
            return true
        end
    end
    for i = 1, #index.requiredItems do
        player:removeItem(index.requiredItems[i][1], index.requiredItems[i][2])
    end
    player:removeItem(item:getId(), 1)
    player:addMount(index.rewardMount)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have received a mount.")
    return true
end

for v, k in pairs(craft) do
    action:id(v)
end
action:register()

this error appeared on TFS:

Lua Script Error: [Scripts Interface]
C:\opentibia\data\scripts\craftmount.lua:callback
C:\opentibia\data\scripts\craftmount.lua:10: attempt to call upvalue 'craft' (a table value)
stack traceback:
[C]: in function 'craft'
C:\opentibia\data\scripts\craftmount.lua:10: in function <C:\opentibia\data\scripts\craftmount.lua:9>
 
LUA:
local craft = {
    -- itemid --------------- {itemid, amount}
    [1956] = {requiredItems = {{27851, 10}, {27978, 5}}, rewardMount = 8}, -- check mounts.xml for mount id
    [2222] = {requiredItems = {{1111, 1}, {2222, 2}}, rewardMount = 111},
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index = craft(item:getId())
    if not index then
        return true
    end
    if player:hasMount(index.rewardMount) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You've already received this mount previously.")
        return true
    end
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i][1]) < index.requiredItems[i][2] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have the required items.")
            return true
        end
    end
    for i = 1, #index.requiredItems do
        player:removeItem(index.requiredItems[i][1], index.requiredItems[i][2])
    end
    player:removeItem(item:getId(), 1)
    player:addMount(index.rewardMount)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have received a mount.")
    return true
end

for v, k in pairs(craft) do
    action:id(v)
end
action:register()

this error appeared on TFS:
ah, oops.

Change
LUA:
local index = craft(item:getId())
to
LUA:
local index = craft[item:getId()]
 
hello guys somebody help me with this problem



[2022-13-05 12:51:14.877] [error] [ProtocolGame::sendTextMessage] - Message type is wrong, missing or invalid for player with name Druid Sample, on position ( 32345 / 32223 / 7 )


using latest version canary server
 
hello guys somebody help me with this problem



[2022-13-05 12:51:14.877] [error] [ProtocolGame::sendTextMessage] - Message type is wrong, missing or invalid for player with name Druid Sample, on position ( 32345 / 32223 / 7 )


using latest version canary server
Change all MESSAGE_STATUS_CONSOLE_BLUE to MESSAGE_FAILURE
You can also see all message types on src/lua/functions/core/game/lua_enums.hpp
 
Back
Top