• 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 Help Script OTX 2.16

Licerys

New Member
Joined
May 20, 2014
Messages
1
Reaction score
0
Hello OTland community! I have a problem with a script. I am trying to adapt this script from another server (also with OTX2 engine) to the latest version: OTX Server 2.16:: "Opportunity".
When the lever is pulled, nothing happens and the error is displayed on the console.
I hope you can help me!


console/error
Code:
[01:52:01.662] [Error - Action Interface]
[01:52:01.662] data/actions/scripts/legendary_lever.lua:onUse
[01:52:01.662] Description:
[01:52:01.662] data/lib/legendary_lever.lua:78: attempt to index field 'chances' (a nil value)
[01:52:01.663] stack traceback:
[01:52:01.663]  data/lib/legendary_lever.lua:78: in function 'randomize'
[01:52:01.663]  data/lib/legendary_lever.lua:167: in function <data/lib/legendary_lever.lua:27>
[01:52:01.664]  (tail call): ?
data/lib/legendary_leaver.lua
LUA:
MAX_DROPSET_RATE = 1000
LEGEND_SCENARIO_TILES = 11

if not legendLever then
    legendLever = {}
end

function loadLegendaryChances()
    for aid, lever in pairs(protectedLevers) do
        lever.chances = {}

        for id, content in pairs(lever.items) do
            local rate = content.rate * MAX_DROPSET_RATE
            for i = 1, rate do
                if i < MAX_DROPSET_RATE then
                    lever.chances[#lever.chances + 1] = id
                end
            end
        end

        if #lever.chances ~= MAX_DROPSET_RATE then
            print(('>> Warning:LegendaryLever %d is not precise drop, result: %f.'):format(aid, #lever.chances/MAX_DROPSET_RATE))
        end
    end
end

function legendLever:random(cid, obj, item)
    if not rawequal(type(obj), 'table') then
        return error('table of items not found.')
    end

    if obj.busy then
        doPlayerSendCancel(cid, 'Aguarde o resultado final do jogador ' .. obj.ownerName .. '.')
        return true
    end

    local itemId = 8978
    if obj.customKey then
        itemId = obj.customKey
    end

    if not doPlayerRemoveItem(cid, itemId, 1) then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'Você não possui 1x ' .. getItemInfo(itemId).name .. ' para tentar a sorte.')
        return true
    end

    local position = {x = obj.winPosition.x - (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}
    for i = 1, LEGEND_SCENARIO_TILES do
        local dummy = getTopCreature(position).uid
        if dummy ~= 0 then
            doSendMagicEffect(position, CONST_ME_POFF)
            doRemoveCreature(dummy)
        end
        position.x = position.x + 1
    end

    obj.wonLegend = false
    obj.busy = true
    obj.ownerName = getPlayerName(cid)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)

    if not obj.discardLog then
        local log = 'Player: ' .. obj.ownerName
        doWriteLogFile('data/logs/legend_drops_rolled.log', log)
    end
    
    doSendMagicEffect(obj.winPosition, 56)
    addEvent(function()
        doSendMagicEffect(obj.winPosition, 56)
    end, 4000)
    
    local addEventSpeed = 15.625
    local rollSpeed = 7100
    local fixPosition = {x = obj.winPosition.x + (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}

    local function randomize()
        local choice = obj.chances[math.random(MAX_DROPSET_RATE)]

        local formula = 1.075 + (addEventSpeed / 5000)
        addEventSpeed = addEventSpeed * formula
        if addEventSpeed > 400 then addEventSpeed = addEventSpeed / 1.02 end
        rollSpeed = rollSpeed / formula

        local position = {x = obj.winPosition.x - (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}
        for i = 1, LEGEND_SCENARIO_TILES do
            local dummy = getTopCreature(position).uid
            if dummy ~= 0 then
                if position.x == obj.winPosition.x - math.floor(LEGEND_SCENARIO_TILES/2) then
                    doRemoveCreature(dummy)
                else
                    setCreatureSpeed(dummy, rollSpeed)
                    doMoveCreature(dummy, WEST)
                end
            end
            position.x = position.x + 1
        end

        local dummy = doCreateMonster('legenddummy', fixPosition, false, true)
        if dummy then
            setCreatureSpeed(dummy, rollSpeed)
            doSetCreatureOutfit(dummy, {lookTypeEx = choice})
        end

        if addEventSpeed < 1000 then
            addEvent(randomize, addEventSpeed)
        else
            addEvent(function()
                local pos1 = {x = obj.winPosition.x + (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}
                local pos2 = {x = obj.winPosition.x - (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}
                doSendDistanceShoot(pos1, obj.winPosition, 37)
                doSendDistanceShoot(pos2, obj.winPosition, 37)
                doSendMagicEffect(obj.winPosition, 6)
            end, 1000)

            addEvent(function()
                local owner = getCreatureByName(obj.ownerName)
                local rewardId
                local position = obj.winPosition
                    local dummy = getTopCreature(position).uid
                    if dummy ~= 0 then
                        rewardId = getCreatureOutfit(dummy).lookTypeEx
                        local addItem
                        if owner then
                            addItem = doPlayerAddItem(owner, rewardId, obj.items[rewardId].count or 1)
                            if addItem and obj.items[rewardId].period then
                                doItemSetPeriod(addItem, obj.items[rewardId].period)
                            end
                            local rewardStr = (obj.items[rewardId].count or 1) .. 'x ' .. getItemInfo(rewardId).name
                            doPlayerSendTextMessage(owner, MESSAGE_INFO_DESCR, 'Parabéns, você encontrou ' .. rewardStr .. '.')
                            if not obj.discardLog then
                                local log = 'Player: ' .. getCreatureName(owner) .. ' | Reward: ' .. rewardStr
                                doWriteLogFile('data/logs/legend_drops_completed.log', log)
                            end
                        end
                        local foundRare = obj.items[rewardId].rare
                        if foundRare then
                            if addItem and owner then
                                doItemSetAttribute(addItem, 'description', ('Hyper item of player %s.'):format(getCreatureName(owner)))
                            end
                            local pos = {x = obj.winPosition.x - (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}
                            for i = 1, LEGEND_SCENARIO_TILES do
                                local dummy = getTopCreature(pos).uid
                                if dummy ~= 0 then
                                    doSetCreatureOutfit(dummy, { lookTypeEx = rewardId })
                                    doSendMagicEffect(getThingPos(dummy), 37)
                                    doSendMagicEffect(getThingPos(dummy), 56)
                                end
                                pos.x = pos.x + 1
                            end
                            if owner then
                                local itemName = getItemInfo(rewardId).name
                                doBroadcastMessage('[Soulwar Lever]: O jogador ' .. getCreatureName(owner) .. ' encontrou um ' .. itemName .. ', que incrível.', MESSAGE_EVENT_ADVANCE)
                            end
                            obj.wonLegend = true
                            self:drawEffects(obj)
                        else
                            doSendMagicEffect(position, 36)
                        end
                    end

                obj.busy = false
            end, 1500)
        end
    end

    randomize()
    return true
end

function legendLever:drawEffects(obj)
    local n = 0
    local function decrease()
        if not obj.wonLegend then
            return
        end
        local time = 20 - n
        if time > 0 then
            n = n + 1
            local position = {x = obj.winPosition.x - (math.floor(LEGEND_SCENARIO_TILES/2)), y = obj.winPosition.y, z = obj.winPosition.z}
            for i = 1, LEGEND_SCENARIO_TILES do
                doSendMagicEffect(position, math.random(28, 31))
                position.x = position.x + 1
            end
            addEvent(decrease, 850)
        end
    end

    decrease()
end

data/actions/scripts/legendary_leaver.lua
LUA:
if not protectedLevers then
    protectedLevers = {
        [17320] = {
            winPosition = {x = 16157, y = 17233, z = 7},
            items = {
                [12661] =    {rate = 0.01, rare = true},
                [10000] =    {rate = 0.02},
                [8978] =    {rate = 0.03},
                [2816] =    {rate = 0.05},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.06, count = 5},
                [6543] =    {rate = 0.08, count = 5},
                [6545] =    {rate = 0.09, count = 5},
                [7489] =    {rate = 0.09},
                [8305] =    {rate = 0.10},
                [12739] =    {rate = 0.12},
                [12372] =    {rate = 0.14, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        },
        [17321] = {
            winPosition = {x = 16157, y = 17245, z = 7},
            items = {
                [12748] =    {rate = 0.01, rare = true},
                [10000] =    {rate = 0.02},
                [8978] =    {rate = 0.03},
                [2816] =    {rate = 0.05},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.06, count = 5},
                [6543] =    {rate = 0.08, count = 5},
                [6545] =    {rate = 0.09, count = 5},
                [7489] =    {rate = 0.09},
                [8305] =    {rate = 0.10},
                [12739] =    {rate = 0.12},
                [12372] =    {rate = 0.14, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        },
        [17322] = {
            winPosition = {x = 16169, y = 17233, z = 7},
            items = {
                [12772] =    {rate = 0.01, rare = true},
                [10000] =    {rate = 0.02},
                [8978] =    {rate = 0.03},
                [2816] =    {rate = 0.05},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.06, count = 5},
                [6543] =    {rate = 0.08, count = 5},
                [6545] =    {rate = 0.09, count = 5},
                [7489] =    {rate = 0.09},
                [8305] =    {rate = 0.10},
                [12739] =    {rate = 0.12},
                [12372] =    {rate = 0.14, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        },
        [17323] = {
            winPosition = {x = 16169, y = 17245, z = 7},
            items = {
                [12751] =    {rate = 0.01, rare = true},
                [10000] =    {rate = 0.02},
                [8978] =    {rate = 0.03},
                [2816] =    {rate = 0.05},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.06, count = 5},
                [6543] =    {rate = 0.08, count = 5},
                [6545] =    {rate = 0.09, count = 5},
                [7489] =    {rate = 0.09},
                [8305] =    {rate = 0.10},
                [12739] =    {rate = 0.12},
                [12372] =    {rate = 0.14, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        },
        [17324] = {
            winPosition = {x = 16181, y = 17233, z = 7},
            items = {
                [12749] =    {rate = 0.01, rare = true},
                [10000] =    {rate = 0.02},
                [8978] =    {rate = 0.03},
                [2816] =    {rate = 0.05},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.06, count = 5},
                [6543] =    {rate = 0.08, count = 5},
                [6545] =    {rate = 0.09, count = 5},
                [7489] =    {rate = 0.09},
                [8305] =    {rate = 0.10},
                [12739] =    {rate = 0.12},
                [12372] =    {rate = 0.14, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        },
        [17325] = {
            winPosition = {x = 16181, y = 17245, z = 7},
            items = {
                [3973] =    {rate = 0.01, rare = true},
                [12607] =    {rate = 0.01, rare = true},
                [10000] =    {rate = 0.03},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.08, count = 5},
                [6543] =    {rate = 0.09},
                [6545] =    {rate = 0.09, count = 5},
                [8305] =    {rate = 0.10, count = 5},
                [7489] =    {rate = 0.12},
                [12739] =    {rate = 0.12},
                [12372] =    {rate = 0.14, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        },
        [17326] = {
            winPosition = {x = 172, y = 1924, z = 7},
            customKey = 2090,
            discardLog = true,
            items = {
                [12661] =    {rate = 0.02, period = 86400, rare = true},
                [12748] =    {rate = 0.02, period = 86400, rare = true},
                [12772] =    {rate = 0.02, period = 86400, rare = true},
                [12751] =    {rate = 0.02, period = 86400, rare = true},
                [12599] =    {rate = 0.05},
                [8300] =    {rate = 0.06},
                [2328] =    {rate = 0.06, count = 5},
                [6545] =    {rate = 0.08, count = 5},
                [6543] =    {rate = 0.09},
                [8305] =    {rate = 0.10, count = 5},
                [12739] =    {rate = 0.10},
                [7489] =    {rate = 0.11},
                [12372] =    {rate = 0.12, count = 15},
                [12601] =    {rate = 0.15, count = 15}
            }
        }
    }
end

function onUse(cid, item)
    local obj = protectedLevers[item.actionid]
    if not obj then
        return true
    end

    if getGameState() == GAMESTATE_STARTUP then
        doPlayerSendCancel(cid, 'Legendary levers have been disabled for serversave.')
        return true
    end

    return legendLever:random(cid, obj, item)
end
 

Similar threads

Back
Top