• 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 Learn spell by making quest TFS 1.5

SalvaART

TriasOT.online
Joined
May 1, 2017
Messages
208
Solutions
1
Reaction score
123
Location
USA
Hello everyone!

Could someone explain to me how to teach spells by completing quests? Namely, when we complete the quest, click on the box, it teaches us the spell, gives us a reward and a message pops up such as you received a reward xxx and you learned the "utevo lux" time.

Big + for any help!
 
Solution
Thank you very much! And how i can add there function about cap check - if you dont have a cap or slots you can't take a reward - big thanks for that!

cap check:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then
        local rewardWeight = ItemType(2160):getWeight(10) -- Calculates the weight (itemId/amount)
        if player:getFreeCapacity() >= rewardWeight then
            player:learnSpell("light")
            player:addItem(2160, 10)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
            player:setStorageValue(Storage.YourQuestStorage, 1)
            return...
Something like that:
XML:
<action itemid="YourBoxId" script="other/light_quest.lua" /> -- Replace 'YourBoxId' with the id value of the box
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then -- Replace 'YourQuestStorage' with the storage value of the quest
        player:learnSpell("light") -- Teaches the spell to the player
        player:addItem(2160, 10) -- Example reward, 10 crystal coins
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
        player:setStorageValue(Storage.YourQuestStorage, 1)
        return true
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Chest is empty.")
        return true
    end
end
 
Something like that:
XML:
<action itemid="YourBoxId" script="other/light_quest.lua" /> -- Replace 'YourBoxId' with the id value of the box
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then -- Replace 'YourQuestStorage' with the storage value of the quest
        player:learnSpell("light") -- Teaches the spell to the player
        player:addItem(2160, 10) -- Example reward, 10 crystal coins
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
        player:setStorageValue(Storage.YourQuestStorage, 1)
        return true
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Chest is empty.")
        return true
    end
end
Thank you very much! And how i can add there function about cap check - if you dont have a cap or slots you can't take a reward - big thanks for that!
 
Thank you very much! And how i can add there function about cap check - if you dont have a cap or slots you can't take a reward - big thanks for that!

cap check:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then
        local rewardWeight = ItemType(2160):getWeight(10) -- Calculates the weight (itemId/amount)
        if player:getFreeCapacity() >= rewardWeight then
            player:learnSpell("light")
            player:addItem(2160, 10)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
            player:setStorageValue(Storage.YourQuestStorage, 1)
            return true
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough capacity to carry the reward.")
            return true
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Chest is empty.")
        return true
    end
end

For slots check maybe something like this?
Lua:
function hasFreeSlotInContainers(player)
    for i = 0, 10 do -- Check all container slots of the player
        local container = player:getContainerById(i)
        if container and container:getEmptySlots(false) > 0 then
            return true
        end
    end
    return false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then
        local rewardWeight = ItemType(2160):getWeight(10) -- Weight of the reward (10 crystal coins)
        if player:getFreeCapacity() >= rewardWeight and hasFreeSlotInContainers(player) then
            player:learnSpell("light") -- Teaches the spell to the player
            player:addItem(2160, 10) -- Example reward, 10 crystal coins
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
            player:setStorageValue(Storage.YourQuestStorage, 1) -- Marks that the player has used the chest
            return true
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough capacity or free slots to carry the reward.")
            return true
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Chest is empty.")
        return true
    end
end
 
Last edited:
Solution
cap check:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then
        local rewardWeight = ItemType(2160):getWeight(10) -- Calculates the weight (itemId/amount)
        if player:getFreeCapacity() >= rewardWeight then
            player:learnSpell("light")
            player:addItem(2160, 10)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
            player:setStorageValue(Storage.YourQuestStorage, 1)
            return true
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough capacity to carry the reward.")
            return true
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Chest is empty.")
        return true
    end
end

For slots check maybe something like this?
Lua:
function hasFreeSlotInContainers(player)
    for i = 0, 10 do -- Check all container slots of the player
        local container = player:getContainerById(i)
        if container and container:getEmptySlots(false) > 0 then
            return true
        end
    end
    return false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.YourQuestStorage) < 1 then
        local rewardWeight = ItemType(2160):getWeight(10) -- Weight of the reward (10 crystal coins)
        if player:getFreeCapacity() >= rewardWeight and hasFreeSlotInContainers(player) then
            player:learnSpell("light") -- Teaches the spell to the player
            player:addItem(2160, 10) -- Example reward, 10 crystal coins
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a reward and learned the 'utevo lux' spell.")
            player:setStorageValue(Storage.YourQuestStorage, 1) -- Marks that the player has used the chest
            return true
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough capacity or free slots to carry the reward.")
            return true
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Chest is empty.")
        return true
    end
end
Thank you boss for your time, everything works!
 
Back
Top