• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Convert script to 0.3.6 from 1.2

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
650
Solutions
14
Reaction score
88
Hello. Could someone convert this script for me from TFS 1.2 to 0.3.6(8.6), cause I have some issues?
Code:
function sendRandom(r)
    return math.random(-r, r)
end

local version = 1098

-- you can put these in global
ORB_TIME = 16
ORB_INCREMENTS = 1000
--

function cashRandom(min, max)
    return math.random(min, max)
end

function comma_value(amount)
  local formatted = amount
  while true do
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end

function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function giveMoney(m)
    local g = m
    local nug, cc, plat, gold, t = 1000000, 10000, 100, 1, {}
    while(m ~= 0) do
        if m >= nug then
            local c = m / nug
            m = m - (c * nug)
            table.insert(t, {2157, c}) -- nuggets
        elseif m >= cc then
            local c = math.floor(m / cc)
            m = m - (c * cc)
            table.insert(t, {2160, c}) -- crystal coin
        elseif m >= plat then
            local c = math.floor(m / plat)
            m = m - (c * plat)
            table.insert(t, {2152, c}) -- plat coins
        elseif m >= gold then
            local c = math.floor(m / gold)
            m = m - (c * gold)
            table.insert(t, {2148, c}) -- gold coins
        end
    end
    return t, g
end

function sendOrbEffect(cid, tier)
    local player = Player(cid)
    if not player then
        return false
    end
    local colors = {5,30,35,95,108,129,143,155,180,198,210,215}
    local xp = player:getExperience()
    local exp = getExpForLevel(player:getLevel() + 1)

    local orbs = {
        {
            type_ = "cash",
            name = "~* gold *~",
            symbol = "$$",
            itemid = function(x)
                local tier = x or 1
                local cash = 0
                local min_coin = (tier * 5)
                local max_coin = (tier * 50)
                return cashRandom(min_coin, max_coin)
            end
        },
        {
            type_ = "loot",
            name = "~* loot *~",
            symbol = "fri itens plx!",
            itemid = function(n)
                local t = {
                    [1] = {
                        {6433, 1},
                        {2503, 1},
                        {2504, 1},
                        {2641, 1},
                        {2542, 1},
                        {6301, 1},
                        {2184, 1},
                        {2406, 1},
                        {2423, 1},
                        {2393, 1},
                        {2415, 1},
                        {5907, 1}
                    },
                    [2] = {
                        {2457, 1},
                        {2463, 1},
                        {2647, 1},
                        {2645, 1},
                        {2532, 1},
                        {2213, 1},
                        {8910, 1},
                        {2403, 1},
                        {7432, 1},
                        {7449, 1},
                        {2387, 1},
                        {2414, 1}
                    },
                    [3] = {
                        {2496, 1},
                        {2505, 1},
                        {2469, 1},
                        {3982, 1},
                        {2517, 1},
                        {2121, 1},
                        {2181, 1},
                        {8209, 1},
                        {8927, 1},
                        {2419, 1},
                        {3962, 1},
                        {8856, 1}
                    }
                }
                n = n > 3 and 3 or n
                return t[n][math.random(#t[n])]
            end,
        },
        {
            type_ = "xp",
            name = "~* exp *~",
            symbol = "Free XP!",
            itemid = function(n)
                return exp - xp
            end,
        }
    }

    local effects = {2, 5, 6, 7, 11, 12, 16, 18, 19, 20,27,37, 38}

    local loot = orbs[math.random(#orbs)]
    local msg = ''
    local p = player:getPosition()
    for i = 1, ORB_TIME do
        p.x = p.x + sendRandom(1)
        p.y = p.y + sendRandom(1)
        addEvent(function(x, n, cid, t)
            local player = Player(cid)
            if player then
                x:sendMagicEffect(effects[math.random(#effects)])
                if player:getPosition() == x then
                    if version == 860 then
                        -- uncomment to use in otx3 8.6
                        --Game.sendAnimatedText(loot.symbol, x, colors[math.random(#colors)])
                    else
                        player:say(loot.symbol, TALKTYPE_MONSTER_SAY, false, nil, x)
                    end
                    player:getPosition():sendMagicEffect(40)
                    local items = loot.itemid(t)
                    if loot.type_ == "loot" then
                        local id = items[1]
                        local name = ItemType(id):getName()
                        local amount = 1
                        if #items > 2 then
                            amount = math.random(items[2], items[3])
                        else
                            amount = items[2]
                        end
                        player:addItem(id, amount)
                        msg = "You've siphoned "..((amount == 1 and loot.type_ == "loot") and "" or amount).." "..name.." from the orb!"
                    elseif loot.type_ == "cash" then
                            local c, amount = giveMoney(items)
                            for k, v in pairs(c) do
                                player:addItem(v[1], v[2])
                            end
                            msg = "You've siphoned $"..comma_value(amount).. " gold from the orb!"
                    else
                        local comma = comma_value(items)
                        player:addExperience(items, false)
                        msg = "You siphoned "..comma.." experience from the orb!"
                    end
                    player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
                else
                    if version == 860 then
                        -- uncomment to use in otx3 8.6
                        --Game.sendAnimatedText(loot.name, x, colors[math.random(#colors)])
                    else
                        player:say(loot.name, TALKTYPE_MONSTER_SAY, false, nil, x)
                    end
                end
            end
        end, i * ORB_INCREMENTS, p, 31, cid, tier
        )
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if killer:isPlayer() then
        local chance = 25
        local roll = math.random(100)
        killer:sendTextMessage(MESSAGE_INFO_DESCR, "you rolled a "..roll)
        if  chance > roll then
            local times = math.random(1, 3)
            for h = 1, times do
                sendOrbEffect(killer:getId(), 3)
            end
        end
    end
    return true
end
Thank in advance :D

Nobody can help ? at least the main function onDeath coz there is no errors and it doesn't work.
 
Last edited by a moderator:
Hello. Could someone convert this script for me from TFS 1.2 to 0.3.6(8.6), cause I have some issues?
Code:
function sendRandom(r)
    return math.random(-r, r)
end

local version = 1098

-- you can put these in global
ORB_TIME = 16
ORB_INCREMENTS = 1000
--

function cashRandom(min, max)
    return math.random(min, max)
end

function comma_value(amount)
  local formatted = amount
  while true do
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end

function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function giveMoney(m)
    local g = m
    local nug, cc, plat, gold, t = 1000000, 10000, 100, 1, {}
    while(m ~= 0) do
        if m >= nug then
            local c = m / nug
            m = m - (c * nug)
            table.insert(t, {2157, c}) -- nuggets
        elseif m >= cc then
            local c = math.floor(m / cc)
            m = m - (c * cc)
            table.insert(t, {2160, c}) -- crystal coin
        elseif m >= plat then
            local c = math.floor(m / plat)
            m = m - (c * plat)
            table.insert(t, {2152, c}) -- plat coins
        elseif m >= gold then
            local c = math.floor(m / gold)
            m = m - (c * gold)
            table.insert(t, {2148, c}) -- gold coins
        end
    end
    return t, g
end

function sendOrbEffect(cid, tier)
    local player = Player(cid)
    if not player then
        return false
    end
    local colors = {5,30,35,95,108,129,143,155,180,198,210,215}
    local xp = player:getExperience()
    local exp = getExpForLevel(player:getLevel() + 1)

    local orbs = {
        {
            type_ = "cash",
            name = "~* gold *~",
            symbol = "$$",
            itemid = function(x)
                local tier = x or 1
                local cash = 0
                local min_coin = (tier * 5)
                local max_coin = (tier * 50)
                return cashRandom(min_coin, max_coin)
            end
        },
        {
            type_ = "loot",
            name = "~* loot *~",
            symbol = "fri itens plx!",
            itemid = function(n)
                local t = {
                    [1] = {
                        {6433, 1},
                        {2503, 1},
                        {2504, 1},
                        {2641, 1},
                        {2542, 1},
                        {6301, 1},
                        {2184, 1},
                        {2406, 1},
                        {2423, 1},
                        {2393, 1},
                        {2415, 1},
                        {5907, 1}
                    },
                    [2] = {
                        {2457, 1},
                        {2463, 1},
                        {2647, 1},
                        {2645, 1},
                        {2532, 1},
                        {2213, 1},
                        {8910, 1},
                        {2403, 1},
                        {7432, 1},
                        {7449, 1},
                        {2387, 1},
                        {2414, 1}
                    },
                    [3] = {
                        {2496, 1},
                        {2505, 1},
                        {2469, 1},
                        {3982, 1},
                        {2517, 1},
                        {2121, 1},
                        {2181, 1},
                        {8209, 1},
                        {8927, 1},
                        {2419, 1},
                        {3962, 1},
                        {8856, 1}
                    }
                }
                n = n > 3 and 3 or n
                return t[n][math.random(#t[n])]
            end,
        },
        {
            type_ = "xp",
            name = "~* exp *~",
            symbol = "Free XP!",
            itemid = function(n)
                return exp - xp
            end,
        }
    }

    local effects = {2, 5, 6, 7, 11, 12, 16, 18, 19, 20,27,37, 38}

    local loot = orbs[math.random(#orbs)]
    local msg = ''
    local p = player:getPosition()
    for i = 1, ORB_TIME do
        p.x = p.x + sendRandom(1)
        p.y = p.y + sendRandom(1)
        addEvent(function(x, n, cid, t)
            local player = Player(cid)
            if player then
                x:sendMagicEffect(effects[math.random(#effects)])
                if player:getPosition() == x then
                    if version == 860 then
                        -- uncomment to use in otx3 8.6
                        --Game.sendAnimatedText(loot.symbol, x, colors[math.random(#colors)])
                    else
                        player:say(loot.symbol, TALKTYPE_MONSTER_SAY, false, nil, x)
                    end
                    player:getPosition():sendMagicEffect(40)
                    local items = loot.itemid(t)
                    if loot.type_ == "loot" then
                        local id = items[1]
                        local name = ItemType(id):getName()
                        local amount = 1
                        if #items > 2 then
                            amount = math.random(items[2], items[3])
                        else
                            amount = items[2]
                        end
                        player:addItem(id, amount)
                        msg = "You've siphoned "..((amount == 1 and loot.type_ == "loot") and "" or amount).." "..name.." from the orb!"
                    elseif loot.type_ == "cash" then
                            local c, amount = giveMoney(items)
                            for k, v in pairs(c) do
                                player:addItem(v[1], v[2])
                            end
                            msg = "You've siphoned $"..comma_value(amount).. " gold from the orb!"
                    else
                        local comma = comma_value(items)
                        player:addExperience(items, false)
                        msg = "You siphoned "..comma.." experience from the orb!"
                    end
                    player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
                else
                    if version == 860 then
                        -- uncomment to use in otx3 8.6
                        --Game.sendAnimatedText(loot.name, x, colors[math.random(#colors)])
                    else
                        player:say(loot.name, TALKTYPE_MONSTER_SAY, false, nil, x)
                    end
                end
            end
        end, i * ORB_INCREMENTS, p, 31, cid, tier
        )
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if killer:isPlayer() then
        local chance = 25
        local roll = math.random(100)
        killer:sendTextMessage(MESSAGE_INFO_DESCR, "you rolled a "..roll)
        if  chance > roll then
            local times = math.random(1, 3)
            for h = 1, times do
                sendOrbEffect(killer:getId(), 3)
            end
        end
    end
    return true
end
Thank in advance :D

Nobody can help ? at least the main function onDeath coz there is no errors and it doesn't work.

Is it registerd in the XML file aswell as login.lua?
 
yes but I need it to 8.6 version .

Oh must have misread your thread, ill move it to requests.
In the future - this is a support board where we help you with existing scripts, request board is to get scripts created or in this case converted.
 
Back
Top