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

MoveEvent Tile allows sell loot (include item in container)

sharinn

Active Member
Joined
Aug 27, 2011
Messages
154
Solutions
7
Reaction score
41
GitHub
ArturKnopik
Twitch
krecikondexin
How this work: throw item/bp with items on ground with special actionId(specified inside script), script will check if item exist in table, if exits will get gold assigned to this item, remove that item and add gold to player, does not remove items/bp that cannot be sold(bp and items stay on player)


Add in data/global.lua or in data/events/scripts/player.lua

Lua:
--Simple loot table
lootTable = { --[ItemID] = valueInGoldCoin,
    [2383] = 1200,  [2514] = 100000,    [2391] = 1100,    [2392] = 5000,  [2393] = 18000,    [2396] = 500,   [2400] = 300000,    [2409] = 900,   [2414] = 12000, [2425] = 30,
    [2427] = 5000,  [2430] = 3000,        [2431] = 300000,[2432] = 8000,  [2434] = 1800,    [2436] = 9000,  [2195] = 35000,        [2463] = 500,    [2466] = 50000,    [2487] = 12000,
    [2488] = 12000, [2462] = 3000,        [2491] = 2000,    [2492] = 60000,    [2497] = 6000,    [2498] = 30000, [2515] = 2000,        [2516] = 4000,    [2519] = 5500,    [2647] = 400,
    [2476] = 4000,  [2475] = 6000,        [2520] = 45000,    [2528] = 8500,    [2532] = 1000,    [2534] = 28000,    [2536] = 10000,        [2539] = 60000,    [2542] = 50000,    [2645] = 50000,
    [2656] = 11000,    [3968] = 100000,    [3972] = 20000,    [2415] = 500000,[2421] = 300000,[2445] = 2000,    [2447] = 30000,        [2453] = 150000,[2469] = 800000,[2470] = 60000,
    [2471] = 800000,[2472] = 110000,    [2474] = 140000,[2477] = 8000,    [2489] = 1000,    [2493] = 150000,[2494] = 200000,    [2495] = 800000,[2496] = 150000,[2522] = 200000,
    [2523] = 400000,[6132] = 400000,    [2646] = 500000,[5741] = 50000,    [6433] = 50000,    [6391] = 50000,    [6528] = 100000,    [7435] = 27000,    [7410] = 12000,    [7412] = 12000,
    [7437] = 9000,    [7407] = 100000,    [7455] = 30000,    [7456] = 30000,    [7449] = 12000,    [7730] = 65000,    [7903] = 33000,        [7902] = 33000,    [7901] = 33000,    [7900] = 36000,
    [7899] = 80000,    [7898] = 80000,        [7897] = 50000,    [7896] = 50000,    [7434] = 60000,    [7380] = 12500,    [7895] = 50000,        [7894] = 50000,    [7893] = 27000,    [7892] = 27000,
    [7891] = 27000,    [7886] = 27000,        [7884] = 80000,    [7885] = 50000,    [7429] = 20000,    [7384] = 20000,    [7389] = 21000,        [7406] = 3000,    [7392] = 3000,    [8912] = 9000,
    [7885] = 50000,    [7429] = 20000,        [7384] = 20000,    [7389] = 21000,    [7406] = 3000,    [7392] = 3000,    [8912] = 9000,        [8910] = 12000,    [8911] = 10000,    [8920] = 10000,
    [8922] = 10000,    [8921] = 8000,        [8924] = 80000,    [8925] = 90000,    [8926] = 90000,    [8927] = 90000,    [8930] = 50000,        [8931] = 100000,[8932] = 57000,    [8905] = 250000,
    [8900] = 3000,    [8901] = 3000,        [8902] = 8000,    [8903] = 8000,    [8904] = 20000,    [8601] = 2000,    [8602] = 2000,        [8881] = 48000,    [8882] = 48000,    [8883] = 48000,
    [8884] = 48000,    [7423] = 50000,        [8869] = 30000,    [8892] = 30000,    [8865] = 30000,    [8878] = 42500,    [8890] = 80000,        [8886] = 140000,[8887] = 140000,[8885] = 140000,
    [8879] = 150000,[8877] = 99000,        [8891] = 90000, [2187] = 3000,    [7413] = 8000,    [9928] = 100000
}
Add in data/global.lua or in data/events/scripts/player.lua, i recommend same file where paste lootTable
Lua:
function scanContainerSellLootTile(itemUid, playerUid, toPosition, lootStruct)
    local item = Item(itemUid)
    local player = Player(playerUid)
    for a = item:getSize() - 1, 0, -1 do
        local containerItem = item:getItem(a)
        if containerItem:getType():isContainer() then
            scanContainerSellLootTile(containerItem:getUniqueId(), playerUid, toPosition, lootStruct)
        end
        local containerItem = item:getItem(a)
        if lootTable[containerItem:getId()] then
            player:addMoney(lootTable[containerItem:getId()])
            lootStruct.itemValue = lootStruct.itemValue + lootTable[containerItem:getId()]
            lootStruct.itemCount = lootStruct.itemCount + 1
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You sell " .. containerItem:getName() .. " for " .. lootTable[containerItem:getId()]/10000 .. "cc.")
            containerItem:remove()
        end
    end
    toPosition:sendMagicEffect(11)
    toPosition:sendMagicEffect(35)
    toPosition:sendMagicEffect(37)
    return lootStruct
end

on data/events/scripts/player.lua -> opentibiabr/otservbr-global (https://github.com/opentibiabr/otservbr-global/blob/81c38af55d67298ce17f2ef6b31e82c0e8f13edf/data/events/scripts/player.lua#L299)

Lua:
local tile = Tile(toPosition) 
    if tile then
        local sellTileGroundAction = tile:getGround():getActionId()

        if  sellTileGroundAction then
            if  sellTileGroundAction == 5585 then -- actionid ground that will sell the loot, can be changed or moved to variable outside this function etc
                if item:getType():isContainer() then
                    local lootStruct = {itemValue = 0, itemCount = 0 }
                    local lootStat = scanContainerSellLootFlame(item:getUniqueId(), self, toPosition, lootStruct)
                    self:sendTextMessage(MESSAGE_INFO_DESCR, "Loot value: number of items: " ..lootStat.itemCount .. ", value of items: " .. lootStat.itemValue/10000 .. "cc.")
                else
                    if lootTable[item:getId()] then
                        self:addMoney(lootTable[item:getId()])
                        toPosition:sendMagicEffect(11)
                        toPosition:sendMagicEffect(35)
                        toPosition:sendMagicEffect(37)
                        item:remove()
                        self:sendTextMessage(MESSAGE_INFO_DESCR, "You sell " .. item:getName() .. " for " .. lootTable[item:getId()]/10000 .. "cc.")
                    end
                end 
                return false
            end
        end
    end

Known issue: when you throw bp with loot and gold will be pushed to this bp will break sell loot loop
PS: sorry for ugly lootTable formating, my visual studio display this perfect :)
 
[Warning - BaseEvents::loadFromXml] Failed to configure event
How to registe event?

edit
solved
 
Last edited:
Back
Top