• 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!

could someone convert this script please

matthew4321

Mapper
Joined
Jan 19, 2011
Messages
91
Reaction score
4
Code:
local chance = 200 -- 1% * rateLoot
local t, r = {
    { {x=32876, y=31707, z=2}, {x=32985, y=31807, z=6} },
    { {x=32886, y=31727, z=8}, {x=32993, y=31806, z=9} },
    { {x=32891, y=31751, z=7}, {x=32990, y=31796, z=7} },
    { {x=32905, y=31797, z=7}, {x=32978, y=31804, z=7} },
    { {x=32951, y=31714, z=7}, {x=32987, y=31750, z=7} },
    { {x=32972, y=31704, z=7}, {x=32987, y=31713, z=7} },
    { {x=32889, y=31749, z=7}, {x=32893, y=31753, z=7} },
    { {x=32908, y=31749, z=7}, {x=32912, y=31750, z=7} },
    { {x=32929, y=31749, z=7}, {x=32933, y=31750, z=7} },
    { {x=32889, y=31770, z=7}, {x=32890, y=31774, z=7} },
    { {x=32889, y=31793, z=7}, {x=32893, y=31797, z=7} },
    { {x=32903, y=31802, z=7}, {x=32907, y=31806, z=7} },
    { {x=32937, y=31805, z=7}, {x=32941, y=31806, z=7} },
    { {x=32974, y=31805, z=7}, {x=32978, y=31806, z=7} }
}, getConfigValue('rateLoot')

function onDeath(cid, corpse)
    if math.random(100000) <= chance * r and isInArray({cid, nil}, getCreatureMaster(cid)) then
        local p = getThingPos(cid)
        for i = 1, #t do
            if isInRange(p, t[i][1], t[i][2]) then
                doAddContainerItem(corpse.uid, 3960)
                break
            end
        end
    end
    return true
end

could someone please convert this to tfs 1.2 thanks in advance
 
Wasn't much to change, not every script needs to be changed from a function to a metatable and its metamethod.

I included some of the functions in this script to show you this is the case.
Code:
-- from 8.6
function isInRange(pos, from, to)
    return (pos.x >= from.x and pos.y >= from.y and pos.z >= from.z and pos.x <= to.x and pos.y <= to.y and pos.z <= to.z)
end

local chance = 200 -- 1% * rateLoot
local t = {
    { {x=32876, y=31707, z=2}, {x=32985, y=31807, z=6} },
    { {x=32886, y=31727, z=8}, {x=32993, y=31806, z=9} },
    { {x=32891, y=31751, z=7}, {x=32990, y=31796, z=7} },
    { {x=32905, y=31797, z=7}, {x=32978, y=31804, z=7} },
    { {x=32951, y=31714, z=7}, {x=32987, y=31750, z=7} },
    { {x=32972, y=31704, z=7}, {x=32987, y=31713, z=7} },
    { {x=32889, y=31749, z=7}, {x=32893, y=31753, z=7} },
    { {x=32908, y=31749, z=7}, {x=32912, y=31750, z=7} },
    { {x=32929, y=31749, z=7}, {x=32933, y=31750, z=7} },
    { {x=32889, y=31770, z=7}, {x=32890, y=31774, z=7} },
    { {x=32889, y=31793, z=7}, {x=32893, y=31797, z=7} },
    { {x=32903, y=31802, z=7}, {x=32907, y=31806, z=7} },
    { {x=32937, y=31805, z=7}, {x=32941, y=31806, z=7} },
    { {x=32974, y=31805, z=7}, {x=32978, y=31806, z=7} }
}
-- local r = getConfigValue('rateLoot')
-- from serverinfo.lua
local r = configManager.getNumber(configKeys.RATE_LOOT)

function onDeath(cid, corpse)
    if math.random(100000) <= chance * r and isInArray({cid, nil}, getCreatureMaster(cid)) then
        local p = getThingPos(cid)
        for i = 1, #t do
            if isInRange(p, t[i][1], t[i][2]) then
                doAddContainerItem(corpse.uid, 3960)
                break
            end
        end
    end
    return true
end
-- from npc.lua
-- doAddContainerItem(container, itemid, subType)
-- from compat.lua 1.2
function getCreatureMaster(cid)
    local c = Creature(cid)
    if c ~= nil then
        local master = c:getMaster()
        return master ~= nil and master:getId() or c:getId()
    end
    return false
end

function getThingPos(uid)
    local thing
    if type(uid) ~= "userdata" then
        if uid >= 0x10000000 then
            thing = Creature(uid)
        else
            thing = Item(uid)
        end
    else
        thing = uid
    end

    if thing == nil then
        return false
    end

    local stackpos = 0
    local tile = thing:getTile()
    if tile ~= nil then
        stackpos = tile:getThingIndex(thing)
    end

    local position = thing:getPosition()
    position.stackpos = stackpos
    return position
end
 
Wasn't much to change, not every script needs to be changed from a function to a metatable and its metamethod.

I included some of the functions in this script to show you this is the case.
Code:
-- from 8.6
function isInRange(pos, from, to)
    return (pos.x >= from.x and pos.y >= from.y and pos.z >= from.z and pos.x <= to.x and pos.y <= to.y and pos.z <= to.z)
end

local chance = 200 -- 1% * rateLoot
local t = {
    { {x=32876, y=31707, z=2}, {x=32985, y=31807, z=6} },
    { {x=32886, y=31727, z=8}, {x=32993, y=31806, z=9} },
    { {x=32891, y=31751, z=7}, {x=32990, y=31796, z=7} },
    { {x=32905, y=31797, z=7}, {x=32978, y=31804, z=7} },
    { {x=32951, y=31714, z=7}, {x=32987, y=31750, z=7} },
    { {x=32972, y=31704, z=7}, {x=32987, y=31713, z=7} },
    { {x=32889, y=31749, z=7}, {x=32893, y=31753, z=7} },
    { {x=32908, y=31749, z=7}, {x=32912, y=31750, z=7} },
    { {x=32929, y=31749, z=7}, {x=32933, y=31750, z=7} },
    { {x=32889, y=31770, z=7}, {x=32890, y=31774, z=7} },
    { {x=32889, y=31793, z=7}, {x=32893, y=31797, z=7} },
    { {x=32903, y=31802, z=7}, {x=32907, y=31806, z=7} },
    { {x=32937, y=31805, z=7}, {x=32941, y=31806, z=7} },
    { {x=32974, y=31805, z=7}, {x=32978, y=31806, z=7} }
}
-- local r = getConfigValue('rateLoot')
-- from serverinfo.lua
local r = configManager.getNumber(configKeys.RATE_LOOT)

function onDeath(cid, corpse)
    if math.random(100000) <= chance * r and isInArray({cid, nil}, getCreatureMaster(cid)) then
        local p = getThingPos(cid)
        for i = 1, #t do
            if isInRange(p, t[i][1], t[i][2]) then
                doAddContainerItem(corpse.uid, 3960)
                break
            end
        end
    end
    return true
end
-- from npc.lua
-- doAddContainerItem(container, itemid, subType)
-- from compat.lua 1.2
function getCreatureMaster(cid)
    local c = Creature(cid)
    if c ~= nil then
        local master = c:getMaster()
        return master ~= nil and master:getId() or c:getId()
    end
    return false
end

function getThingPos(uid)
    local thing
    if type(uid) ~= "userdata" then
        if uid >= 0x10000000 then
            thing = Creature(uid)
        else
            thing = Item(uid)
        end
    else
        thing = uid
    end

    if thing == nil then
        return false
    end

    local stackpos = 0
    local tile = thing:getTile()
    if tile ~= nil then
        stackpos = tile:getThingIndex(thing)
    end

    local position = thing:getPosition()
    position.stackpos = stackpos
    return position
end
ok thanks alot
 
Back
Top