• 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 Reload commands

fironfox

New Member
Joined
Dec 14, 2012
Messages
42
Reaction score
1
Have anyone command who make reload an specific archive?? Ex: in game have the comannd /reload actions. I need make this command for works in lua, force the reload in X hour of the day or each server save. Who know if this is possible?
 
Solution
Define the function table.find inside the callback like that:
Code:
    local config = {
        manaCost = 300,
        soulCost = 0,
    }

    local spheres = {
        [7759] = {3, 7},
        [7760] = {1, 5},
        [7761] = {2, 6},
        [7762] = {4, 8}
    }

    local enchantableGems = {2147, 2146, 2149, 2150}
    local enchantableItems = {2383, 7383, 7384, 7406, 7402, 2429, 2430, 7389, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}

    local enchantingAltars = {
        {7504, 7505, 7506, 7507},
        {7508, 7509, 7510, 7511},
        {7516, 7517, 7518, 7519},
        {7512, 7513, 7514, 7515}
    }

    local enchantedGems = {7760, 7759, 7761, 7762}
    local enchantedItems = {
        [2383] = {7744, 7763, 7854, 7869},
        [7383]...
Have anyone command who make reload an specific archive?? Ex: in game have the comannd /reload actions. I need make this command for works in lua, force the reload in X hour of the day or each server save. Who know if this is possible?
A talkaction isn't a spell, so it isn't assigned to a specific vocation, in theory it might be possible for say an npc or even item to execute a talkaction.
 
Sorry, i think i have formulated wrong this question... What i want to say if is possible to make a globalevent for each hour of the day execute the command "/reload actions" if yes, what lua function of tfs 1.2 do this?? Have one example?
 
There is no function to execute reloads in lua. Why do you even need that? For sure there is a better way to do it without reloading.
 
There is no function to execute reloads in lua. Why do you even need that? For sure there is a better way to do it without reloading.
Ok, here we go...

I have one script what make enchantement, like a global RL, when you use one ruby, saphire, amethyst or emerald in the correct id place he get enchanted... The scripts works very good but i don't know why script stop to work when my server restart (i close the tfs and open again like server save at global) and after i use in game the command /reload actions he works again... Anyone have an solution?? here are script:
Code:
local config = {
    manaCost = 300,
    soulCost = 0,
}

local spheres = {
    [7759] = {3, 7},
    [7760] = {1, 5},
    [7761] = {2, 6},
    [7762] = {4, 8}
}

local enchantableGems = {2147, 2146, 2149, 2150}
local enchantableItems = {2383, 7383, 7384, 7406, 7402, 2429, 2430, 7389, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}

local enchantingAltars = {
    {7504, 7505, 7506, 7507},
    {7508, 7509, 7510, 7511},
    {7516, 7517, 7518, 7519},
    {7512, 7513, 7514, 7515}
}

local enchantedGems = {7760, 7759, 7761, 7762}
local enchantedItems = {
    [2383] = {7744, 7763, 7854, 7869},
    [7383] = {7745, 7764, 7855, 7870},
    [7384] = {7746, 7765, 7856, 7871},
    [7406] = {7747, 7766, 7857, 7872},
    [7402] = {7748, 7767, 7858, 7873},
    [2429] = {7749, 7768, 7859, 7874},
    [2430] = {7750, 7769, 7860, 7875},
    [7389] = {7751, 7770, 7861, 7876},
    [7380] = {7752, 7771, 7862, 7877},
    [2454] = {7753, 7772, 7863, 7878},
    [2423] = {7754, 7773, 7864, 7879},
    [2445] = {7755, 7774, 7865, 7880},
    [7415] = {7756, 7775, 7866, 7881},
    [7392] = {7757, 7776, 7867, 7882},
    [2391] = {7758, 7777, 7868, 7883},
    [2544] = {7840, 7839, 7850, 7838},
    [8905] = {8906, 8907, 8909, 8908}
}

table.find = function(tab, value)
    for i = 1, #tab do
        if tab[i] == value then
            return i       
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isInArray({33268, 33269}, toPosition.x) and toPosition.y == 31830 and toPosition.z == 10 and player:getStorageValue(Storage.ElementalSphere.QuestLine) > 0 then
        if not isInArray(spheres[item.itemid], player:getVocation():getId()) then
            return false
        elseif isInArray({7915, 7916}, target.itemid) then
            player:say('Turn off the machine first.', TALKTYPE_MONSTER_SAY)
            return true
        else
            player:setStorageValue(Storage.ElementalSphere.MachineGemCount, math.max(1, player:getStorageValue(Storage.ElementalSphere.MachineGemCount) + 1))
            toPosition:sendMagicEffect(CONST_ME_PURPLEENERGY)
            item:transform(item.itemid, item.type - 1)
            return true
        end
    end

    if item.itemid == 2147 and target.itemid == 2342 then
        target:transform(2343)
        target:decay()
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end

    if item.itemid == 7760 and isInArray({9934, 10022}, target.itemid) then
        target:transform(9933)
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end

    if isInArray(enchantableGems, item.itemid) then
        local subtype = item.type
        if subtype == 0 then
            subtype = 1
        end

        local mana = config.manaCost * subtype
        if player:getMana() < mana then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
            return false
        end

        local soul = config.soulCost * subtype
        if player:getSoul() < soul then
            player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
            return false
        end

        local targetId = table.find(enchantableGems, item.itemid)
        if not targetId or not isInArray(enchantingAltars[targetId], target.itemid) then
            return false
        end

        player:addMana(-mana)
        player:addSoul(-soul)
        item:transform(enchantedGems[targetId])
        player:addManaSpent(mana * configManager.getNumber(configKeys.RATE_MAGIC))
        player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
        return true
    end

    if item.itemid == 7761 and isInArray({9949, 9954}, target.itemid) then
        target:transform(target.itemid - 1)
        target:decay()
        item:remove(1)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        return true
    end

    if isInArray(enchantedGems, item.itemid) then
        if not isInArray(enchantableItems, target.itemid) then
            fromPosition:sendMagicEffect(CONST_ME_POFF)
            return false
        end

        local targetId = table.find(enchantedGems, item.itemid)
        if not targetId then
            return false
        end

        local subtype = target.type
        if not isInArray({2544, 8905}, target.itemid) then
            subtype = 1000
        end

        target:transform(enchantedItems[target.itemid][targetId], subtype)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        item:remove(1)
        return true
    end
    return false
end
 
Define the function table.find inside the callback like that:
Code:
    local config = {
        manaCost = 300,
        soulCost = 0,
    }

    local spheres = {
        [7759] = {3, 7},
        [7760] = {1, 5},
        [7761] = {2, 6},
        [7762] = {4, 8}
    }

    local enchantableGems = {2147, 2146, 2149, 2150}
    local enchantableItems = {2383, 7383, 7384, 7406, 7402, 2429, 2430, 7389, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}

    local enchantingAltars = {
        {7504, 7505, 7506, 7507},
        {7508, 7509, 7510, 7511},
        {7516, 7517, 7518, 7519},
        {7512, 7513, 7514, 7515}
    }

    local enchantedGems = {7760, 7759, 7761, 7762}
    local enchantedItems = {
        [2383] = {7744, 7763, 7854, 7869},
        [7383] = {7745, 7764, 7855, 7870},
        [7384] = {7746, 7765, 7856, 7871},
        [7406] = {7747, 7766, 7857, 7872},
        [7402] = {7748, 7767, 7858, 7873},
        [2429] = {7749, 7768, 7859, 7874},
        [2430] = {7750, 7769, 7860, 7875},
        [7389] = {7751, 7770, 7861, 7876},
        [7380] = {7752, 7771, 7862, 7877},
        [2454] = {7753, 7772, 7863, 7878},
        [2423] = {7754, 7773, 7864, 7879},
        [2445] = {7755, 7774, 7865, 7880},
        [7415] = {7756, 7775, 7866, 7881},
        [7392] = {7757, 7776, 7867, 7882},
        [2391] = {7758, 7777, 7868, 7883},
        [2544] = {7840, 7839, 7850, 7838},
        [8905] = {8906, 8907, 8909, 8908}
    }

    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        function table.find(tab, value)
            for i = 1, #tab do
                if tab[i] == value then
                    return i
                end
            end
        end
        if isInArray({33268, 33269}, toPosition.x) and toPosition.y == 31830 and toPosition.z == 10 and player:getStorageValue(Storage.ElementalSphere.QuestLine) > 0 then
            if not isInArray(spheres[item.itemid], player:getVocation():getId()) then
                return false
            elseif isInArray({7915, 7916}, target.itemid) then
                player:say('Turn off the machine first.', TALKTYPE_MONSTER_SAY)
                return true
            else
                player:setStorageValue(Storage.ElementalSphere.MachineGemCount, math.max(1, player:getStorageValue(Storage.ElementalSphere.MachineGemCount) + 1))
                toPosition:sendMagicEffect(CONST_ME_PURPLEENERGY)
                item:transform(item.itemid, item.type - 1)
                return true
            end
        end

        if item.itemid == 2147 and target.itemid == 2342 then
            target:transform(2343)
            target:decay()
            item:remove(1)
            toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
            return true
        end

        if item.itemid == 7760 and isInArray({9934, 10022}, target.itemid) then
            target:transform(9933)
            item:remove(1)
            toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
            return true
        end

        if isInArray(enchantableGems, item.itemid) then
            local subtype = item.type
            if subtype == 0 then
                subtype = 1
            end

            local mana = config.manaCost * subtype
            if player:getMana() < mana then
                player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
                return false
            end

            local soul = config.soulCost * subtype
            if player:getSoul() < soul then
                player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
                return false
            end

            local targetId = table.find(enchantableGems, item.itemid)
            if not targetId or not isInArray(enchantingAltars[targetId], target.itemid) then
                return false
            end

            player:addMana(-mana)
            player:addSoul(-soul)
            item:transform(enchantedGems[targetId])
            player:addManaSpent(mana * configManager.getNumber(configKeys.RATE_MAGIC))
            player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
            return true
        end

        if item.itemid == 7761 and isInArray({9949, 9954}, target.itemid) then
            target:transform(target.itemid - 1)
            target:decay()
            item:remove(1)
            toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
            return true
        end

        if isInArray(enchantedGems, item.itemid) then
            if not isInArray(enchantableItems, target.itemid) then
                fromPosition:sendMagicEffect(CONST_ME_POFF)
                return false
            end

            local targetId = table.find(enchantedGems, item.itemid)
            if not targetId then
                return false
            end

            local subtype = target.type
            if not isInArray({2544, 8905}, target.itemid) then
                subtype = 1000
            end

            target:transform(enchantedItems[target.itemid][targetId], subtype)
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            item:remove(1)
            return true
        end
        return false
    end

Somewhere else in your libs it must be overwriting the value of table.find. This will prevent it.
 
Solution
Back
Top