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

RevScripts Sell All ActionId sells equiped items! :(

nicoelperro

New Member
Joined
May 3, 2024
Messages
14
Reaction score
3
Okay, first of all thank you for your time.
This server is 8.6 and it works with The Real Server 3.1 wich i understand uses TFS 0.X
I have this script that's made to automaticaly sell all items that are on the shoplist, but it also sells your equiped items and it can get to be annoying for the player.

function onUse(cid, item, fromPosition, itemEx, toPosition)
local shopItems = {
[2182] = {name = "Snakebite Rod", price = 500},
[2190] = {name = "Wand of Vortex", price = 500},
[8922] = {name = "Wand of Voodoo", price = 2000},
[2191] = {name = "Wand of Dragonbreath", price = 1000},
[2188] = {name = "Wand of Decay", price = 1000},
[8920] = {name = "Wand of Sandstorm", price = 3000},
[8911] = {name = "Northwind Rod", price = 1000},
[8912] = {name = "Springsprout Rod", price = 1000},
[2187] = {name = "Wand of Inferno", price = 3500},
[2183] = {name = "Hailstorm Rod", price = 3500},
[2186] = {name = "Moonlight Rod", price = 1000},
[2185] = {name = "Volcanic Rod", price = 1000},
[2181] = {name = "Terra Rod", price = 2000},
[2189] = {name = "Wand of Cosmic Energy", price = 2000},
}

local totalGold = 0

-- Calcular el total de oro ganado
for itemId, itemData in pairs(shopItems) do
local itemCount = getPlayerItemCount(cid, itemId)
if itemCount > 0 then
doPlayerRemoveItem(cid, itemId, itemCount)
totalGold = totalGold + (itemCount * itemData.price)
end
end

if totalGold > 0 then
doPlayerAddMoney(cid, totalGold)
doSendMagicEffect(getCreaturePosition(cid), 30)

addEvent(function()
doSendMagicEffect(getCreaturePosition(cid), 29)
end, 350)

-- Mostrar solo el total de oro ganado
doSendAnimatedText(fromPosition, "Total: " .. totalGold .. " gps", TEXTCOLOR_YELLOW)
else
doSendAnimatedText(fromPosition, "Nada para vender", TEXTCOLOR_RED)
doSendMagicEffect(getCreaturePosition(cid), 3)
end

return true
end

It could be awesome if someone can help me get this script fixed so people can sell all faster without loosing their items :D
 
Im not genius/scripter/professional blablabla
But my stupid head, see that solution:
Maybe change this:
LUA:
local itemCount = getPlayerItemCount(cid, itemId)

To:
LUA:
local itemCount = getPlayerItemCount(cid, itemId) - 1


Propably its stupid solution, but i think one Item of each not be sold 😅
 
LUA:
local config = {
    searchAllContainers = true
}

function getPlayerItemsById(cid, itemid, deepSearch)
    local items = {}

    local function scanContainer(container)
        for i = 0, getContainerSize(container.uid) - 1 do
            local item = getContainerItem(container.uid, i)
            if item.itemid == itemid then
                table.insert(items, item)
            end
            if deepSearch and isContainer(item.uid) then
                scanContainer(item)
            end
        end
    end

    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local item = getPlayerSlotItem(cid, slot)
        if item and item.uid > 0 and isContainer(item.uid) then
            scanContainer(item)
        end
    end

    return items
end


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local shopItems = {
        [2182] = {name = "Snakebite Rod", price = 500},
        [2190] = {name = "Wand of Vortex", price = 500},
        [8922] = {name = "Wand of Voodoo", price = 2000},
        [2191] = {name = "Wand of Dragonbreath", price = 1000},
        [2188] = {name = "Wand of Decay", price = 1000},
        [8920] = {name = "Wand of Sandstorm", price = 3000},
        [8911] = {name = "Northwind Rod", price = 1000},
        [8912] = {name = "Springsprout Rod", price = 1000},
        [2187] = {name = "Wand of Inferno", price = 3500},
        [2183] = {name = "Hailstorm Rod", price = 3500},
        [2186] = {name = "Moonlight Rod", price = 1000},
        [2185] = {name = "Volcanic Rod", price = 1000},
        [2181] = {name = "Terra Rod", price = 2000},
        [2189] = {name = "Wand of Cosmic Energy", price = 2000},
    }

    local totalGold = 0
    local equippedItems = {}

    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local equipped = getPlayerSlotItem(cid, slot)
        if equipped and equipped.uid > 0 then
            equippedItems[equipped.uid] = true
        end
    end

    for itemId, itemData in pairs(shopItems) do
        local items = getPlayerItemsById(cid, itemId, config.searchAllContainers)
        for _, item in ipairs(items) do
            if not equippedItems[item.uid] then
                doRemoveItem(item.uid)
                totalGold = totalGold + itemData.price
            end
        end
    end

    if totalGold > 0 then
        doPlayerAddMoney(cid, totalGold)
        doSendMagicEffect(getCreaturePosition(cid), 30)
        addEvent(function()
            doSendMagicEffect(getCreaturePosition(cid), 29)
        end, 350)
        doSendAnimatedText(fromPosition, "Total: " .. totalGold .. " gps", TEXTCOLOR_YELLOW)
    else
        doSendAnimatedText(fromPosition, "Nada para vender", TEXTCOLOR_RED)
        doSendMagicEffect(getCreaturePosition(cid), 3)
    end

    return true
end
searchAllContainers = true/false if you want sell from all containers or just from main bp.
 
Im not genius/scripter/professional blablabla
But my stupid head, see that solution:
Maybe change this:
LUA:
local itemCount = getPlayerItemCount(cid, itemId)

To:
LUA:
local itemCount = getPlayerItemCount(cid, itemId) - 1


Propably its stupid solution, but i think one Item of each not be sold 😅
it's a very useful solution, what can i say, i'd like to make this ot as comfortable as i can so i would rather use a scripts that allows my players to instantly sell everything instead of having to sell twice, buuuut sometimes the easier solutions are not the most complicated, it was pretty genius just to add a "-1" to solve the entire problem that i've been struggling with for the past 2 days haha
I'll keep this one at the moment, thank you
Post automatically merged:

LUA:
local config = {
    searchAllContainers = true
}

function getPlayerItemsById(cid, itemid, deepSearch)
    local items = {}

    local function scanContainer(container)
        for i = 0, getContainerSize(container.uid) - 1 do
            local item = getContainerItem(container.uid, i)
            if item.itemid == itemid then
                table.insert(items, item)
            end
            if deepSearch and isContainer(item.uid) then
                scanContainer(item)
            end
        end
    end

    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local item = getPlayerSlotItem(cid, slot)
        if item and item.uid > 0 and isContainer(item.uid) then
            scanContainer(item)
        end
    end

    return items
end


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local shopItems = {
        [2182] = {name = "Snakebite Rod", price = 500},
        [2190] = {name = "Wand of Vortex", price = 500},
        [8922] = {name = "Wand of Voodoo", price = 2000},
        [2191] = {name = "Wand of Dragonbreath", price = 1000},
        [2188] = {name = "Wand of Decay", price = 1000},
        [8920] = {name = "Wand of Sandstorm", price = 3000},
        [8911] = {name = "Northwind Rod", price = 1000},
        [8912] = {name = "Springsprout Rod", price = 1000},
        [2187] = {name = "Wand of Inferno", price = 3500},
        [2183] = {name = "Hailstorm Rod", price = 3500},
        [2186] = {name = "Moonlight Rod", price = 1000},
        [2185] = {name = "Volcanic Rod", price = 1000},
        [2181] = {name = "Terra Rod", price = 2000},
        [2189] = {name = "Wand of Cosmic Energy", price = 2000},
    }

    local totalGold = 0
    local equippedItems = {}

    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local equipped = getPlayerSlotItem(cid, slot)
        if equipped and equipped.uid > 0 then
            equippedItems[equipped.uid] = true
        end
    end

    for itemId, itemData in pairs(shopItems) do
        local items = getPlayerItemsById(cid, itemId, config.searchAllContainers)
        for _, item in ipairs(items) do
            if not equippedItems[item.uid] then
                doRemoveItem(item.uid)
                totalGold = totalGold + itemData.price
            end
        end
    end

    if totalGold > 0 then
        doPlayerAddMoney(cid, totalGold)
        doSendMagicEffect(getCreaturePosition(cid), 30)
        addEvent(function()
            doSendMagicEffect(getCreaturePosition(cid), 29)
        end, 350)
        doSendAnimatedText(fromPosition, "Total: " .. totalGold .. " gps", TEXTCOLOR_YELLOW)
    else
        doSendAnimatedText(fromPosition, "Nada para vender", TEXTCOLOR_RED)
        doSendMagicEffect(getCreaturePosition(cid), 3)
    end

    return true
end
searchAllContainers = true/false if you want sell from all containers or just from main bp.
It seems like you took some time to try and fix this script for me, thanks a lot, i'm afraid it's not working :(
i think it's uncompatible with my tfs
 
@nicoelperro any errors? i was tested script @Canarian on TFS 1.5 (8.6) and it work perfect, not selling items what are equpied, but all in backpack are sold
Nevermind everything i've said about this script.. it's fantastic, i must have done something wrong when i putted it on the OT, thanks a lot people
 
Last edited:

Similar threads

Back
Top