• 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 Bosses drop loot on the ground.

DukeeH

Active Member
Joined
Dec 6, 2010
Messages
550
Solutions
3
Reaction score
39
Hello, I'm using TFS 0.3.7/OTX.

I'm trying to make a script that drops bosses loot on the ground.

It probably needs to be onkill and should work for 4 or 5 monsters (table on the start).

It can be a math random range of -4 to +4 x and y from the monster, so it would be around him.

And preferably, not stack one item above other.

Thanks for your time.
 
Solution
Lua:
local function isNormalPosition(pos)
    local tile = getTileThingByPos(pos)
    if(tile.uid > 0 and (not hasProperty(tile.uid, CONST_PROP_BLOCKINGANDNOTMOVEABLE) and not hasProperty(tile.uid, CONST_PROP_BLOCKPATHFIND)) and (not getTileInfo(pos).protection)) then
        return true
    end
    return false
end

function onDeath(cid, corpse, deathList)
    local name = string.lower(getCreatureName(cid))
    if(name == "rat") then -- change for boss name
        local all_positions = {}
        local centerPos = getCreaturePosition(cid)(cid)
       
        for i = -7, 7 do
            for j = -7, 7 do
                table.insert(all_positions, {x=centerPos.x + i, y=centerPos.y + j, z=7})
            end
        end...
Lua:
local function isNormalPosition(pos)
    local tile = getTileThingByPos(pos)
    if(tile.uid > 0 and (not hasProperty(tile.uid, CONST_PROP_BLOCKINGANDNOTMOVEABLE) and not hasProperty(tile.uid, CONST_PROP_BLOCKPATHFIND)) and (not getTileInfo(pos).protection)) then
        return true
    end
    return false
end

function onDeath(cid, corpse, deathList)
    local name = string.lower(getCreatureName(cid))
    if(name == "rat") then -- change for boss name
        local all_positions = {}
        local centerPos = getCreaturePosition(cid)(cid)
       
        for i = -7, 7 do
            for j = -7, 7 do
                table.insert(all_positions, {x=centerPos.x + i, y=centerPos.y + j, z=7})
            end
        end
       
        local tokens = 0
        while(tokens < 3) do
            local pos = all_positions[math.random(1,#all_positions)]
            if(isNormalPosition(pos)) then
                doCreateItem(2150, 1, pos) --- change items id here
                doSendMagicEffect(pos, CONST_ME_TUTORIALARROW)
                tokens = tokens + 1
            end       
        end
       
        local coins = 0       
        while(coins < 30) do
            local pos = all_positions[math.random(1,#all_positions)]
            if(isNormalPosition(pos)) then
                doCreateItem(2157, math.random(20,35), pos) --- change items id here and chance
                doSendMagicEffect(pos, CONST_ME_EXPLOSIONAREA)
                coins = coins + 1
            end
        end
       
        for i = 1, 10 do
            local pos = all_positions[math.random(1,#all_positions)]
            if(isNormalPosition(pos)) then
                if(math.random(1,3) == 2) then
                    doCreateItem(9020, 1, pos) --- change items id here
                end
                doSendMagicEffect(pos, CONST_ME_TUTORIALARROW)
                doSendMagicEffect(pos, CONST_ME_EXPLOSIONAREA)
            end
        end
       
        local pos = all_positions[math.random(1,#all_positions)]
        if(isNormalPosition(pos)) then
            if(math.random(1,2) == 2) then
                doCreateItem(ITEM_DONATION_COIN, 1, pos) --- change items id here
            end
            doSendMagicEffect(pos, CONST_ME_EXPLOSIONAREA)
            doSendMagicEffect(pos, CONST_ME_TUTORIALARROW)
        end
           
        doBroadcastMessage("add msg do you want!", MESSAGE_STATUS_WARNING)
    end
    return true
end
 
Last edited:
Solution
Lua:
local function isNormalPosition(pos)
    local tile = getTileThingByPos(pos)
    if(tile.uid > 0 and (not hasProperty(tile.uid, CONST_PROP_BLOCKINGANDNOTMOVEABLE) and not hasProperty(tile.uid, CONST_PROP_BLOCKPATHFIND)) and (not getTileInfo(pos).protection)) then
        return true
    end
    return false
end

function onDeath(cid, corpse, deathList)
    local name = string.lower(getCreatureName(cid))
    if(name == "rat") then -- change for boss name
        local all_positions = {}
        local centerPos = thingPos(cid)
       
        for i = -7, 7 do
            for j = -7, 7 do
                table.insert(all_positions, {x=centerPos.x + i, y=centerPos.y + j, z=7})
            end
        end
       
        local tokens = 0
        while(tokens < 3) do
            local pos = all_positions[math.random(1,#all_positions)]
            if(isNormalPosition(pos)) then
                doCreateItem(2150, 1, pos) --- change items id here
                doSendMagicEffect(pos, CONST_ME_TUTORIALARROW)
                tokens = tokens + 1
            end       
        end
       
        local coins = 0       
        while(coins < 30) do
            local pos = all_positions[math.random(1,#all_positions)]
            if(isNormalPosition(pos)) then
                doCreateItem(2157, math.random(20,35), pos) --- change items id here and chance
                doSendMagicEffect(pos, CONST_ME_EXPLOSIONAREA)
                coins = coins + 1
            end
        end
       
        for i = 1, 10 do
            local pos = all_positions[math.random(1,#all_positions)]
            if(isNormalPosition(pos)) then
                if(math.random(1,3) == 2) then
                    doCreateItem(9020, 1, pos) --- change items id here
                end
                doSendMagicEffect(pos, CONST_ME_TUTORIALARROW)
                doSendMagicEffect(pos, CONST_ME_EXPLOSIONAREA)
            end
        end
       
        local pos = all_positions[math.random(1,#all_positions)]
        if(isNormalPosition(pos)) then
            if(math.random(1,2) == 2) then
                doCreateItem(ITEM_DONATION_COIN, 1, pos) --- change items id here
            end
            doSendMagicEffect(pos, CONST_ME_EXPLOSIONAREA)
            doSendMagicEffect(pos, CONST_ME_TUTORIALARROW)
        end
           
        doBroadcastMessage("add msg do you want!", MESSAGE_STATUS_WARNING)
    end
    return true
end
Thanks for your help, but is it possible that it counts the loot on the monster body?
Get what inside the container and drop from -4 to +4 xy from monser body.
And the if name could be used for 4 or 5 monsters?
 
Thanks for your help, but is it possible that it counts the loot on the monster body?
Get what inside the container and drop from -4 to +4 xy from monser body.
And the if name could be used for 4 or 5 monsters?
Lua:
local creaturenames = {"rat","cave rat"}
local name = string.lower(getCreatureName(cid))
if(isInArray(creaturenames, name)) then
 
Back
Top