• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

"doTransformItem" Function Bugging AutoLoot

Mizakinha

New Member
Joined
Apr 18, 2021
Messages
34
Reaction score
4
Hello everybody!

Next... On my server every time someone opens a box the autoloot stops working (for the whole server, not just for the player that opened it). Both the box and the autoloot work perfectly, however, when someone uses the box and receives the pokemon, the autoloot stops working.

After several tests here I found that the problem is in the "doTransformItem(item, id)" function which is inside the "addPokeToPlayer" function. That said, I'm not able to pinpoint why this happens. Can anyone help me?

I'll leave the function, box and autoloot script below.

Note: I'm using Pokemon HuatsonOT V2.0 (DXP) as a base.

addPokeToPlayer function:

Lua:
function addPokeToPlayer(cid, pokemon, boost, gender, ball, unique, mega) --alterado v1.9 \/ peguem ele todo...
    local genders = {
        ["male"] = 4,
        ["female"] = 3,
        [1] = 4,
        [0] = 3,
        [4] = 4,
        [3] = 3,
    }
    if not isCreature(cid) then return false end


    local pokemon = doCorrectString(pokemon)
    if not pokes[pokemon] then return false end

    local GENDER = (gender and genders[gender]) and genders[gender] or getRandomGenderByName(pokemon)
    local btype = (ball and pokeballs[ball]) and ball or isShinyName(pokemon) and "shinypoke" or "poke"
    local happy = 250
    id = 11829

    if pokemon == "Shiny Ditto" then
        id = 11743
    end


    local cap = getPlayerFreeCap(cid)
    if (getPlayerFreeCap(cid) <= 1 and not isInArray({ 5, 6 }, getPlayerGroupId(cid))) or
        not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
        item = doCreateItemEx(id)
    else
        item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, id, 1)
    end
    if not item then return false end

    doItemSetAttribute(item, "poke", pokemon)
    doItemSetAttribute(item, "hpToDraw", 0)
    doSetItemAttribute(item, "hands", 0)
    doItemSetAttribute(item, "ball", btype)
    doItemSetAttribute(item, "reverseIcon", btype)
    doSetAttributesBallsByPokeName(cid, item, pokemon)

    if boost and tonumber(boost) and tonumber(boost) > 0 and tonumber(boost) <= 50 then
        doItemSetAttribute(item, "boost", boost)
    end
    if unique then
        doItemSetAttribute(item, "unique", getCreatureName(cid))
    end

    if (cap <= 1 and not isInArray({ 5, 6 }, getPlayerGroupId(cid))) or
        not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
        if mega then
            doItemSetAttribute(item, "yHeldItem", mega .. "|MEGA")
        end
        doPlayerSendMailByName(getCreatureName(cid), item, 1)
        sendMsgToPlayer(cid, 27, "You are already holding six digimons, so your new digimon was sent to your data center.")
    end

    doTransformItem(item, id)

    if mega then
        doItemSetAttribute(item, "yHeldItem", mega .. "|MEGA")
    end

    sendAllPokemonsBarPoke(cid)
    return true
end

Lua:
 function onUse(cid, item, frompos, item2, topos)
    if isWatchingTv(cid) then return true end
    if quemMatou then
        local player = getCreatureByName(quemMatou)
        if isPlayer(player) then
            local isInParyWithPlayer = false
            if isInParty(cid) and isInParty(player) then
                isInParyWithPlayer = isPartyEquals(player, cid)
            end

            if getCreatureName(cid) ~= getCreatureName(player) and not isInParyWithPlayer then
                doPlayerSendCancel(cid, "Voce nao pode abrir um loot que nao eh seu.")
                return true
            end
        end
    end
    local autoLootList = getAllItensInMyList(cid)
    local bag = getPlayerSlotItem(cid, 3).uid
    local itemsToRemove = {}

    if isCollectAll(cid) then
        for a = 0, getContainerSize(item.uid) do
            local it = getContainerItem(item.uid, a)
            if it.uid > 0 then
                if addItemInFreeBag(bag, it.itemid, it.type) ~= false then
                    table.insert(itemsToRemove, it.uid)
                end
            end
        end
    end

    if #autoLootList > 0 and not isCollectAll(cid) then
        for a = 0, getContainerSize(item.uid) do
            local it = getContainerItem(item.uid, a)
            if it.uid > 0 then
                for i = 1, #autoLootList do
                    if getItemInfo(it.itemid).name == autoLootList[i] then
                        if addItemInFreeBag(bag, it.itemid, it.type) ~= false then
                            table.insert(itemsToRemove, it.uid)
                        end
                    end
                end
            end
        end
    end

    if #itemsToRemove > 0 then
        for i = 1, #itemsToRemove do
            doChangeTypeItem(itemsToRemove[i], 0)
        end
    end

end

Lua:
local a = {
[11638] = {pokemons = {"Caterpie", "Weedle"}},
[11639] = {pokemons = {"Bulbasaur", "Charmander", "Squirtle"}},
--[11640] = {pokemons = {"Politoed", "Hitmontop"}},
--[11641] = {pokemons = {"Dragonite", "Shiny Horsea"}},
--[12581] = {pokemons = {"Aerodactyl"}},
--[12227] = {pokemons = {"Shiny Milotic", "Shiny Mr. Mime"}}
}     

local happy = 1000
        
function onUse(cid, item, frompos, item2, topos)
         local b = a[item.itemid]                                   
               if not b then return true end
         local pokemon = b.pokemons[math.random(#b.pokemons)]
               if not pokes[pokemon] then return true end 
        
         doPlayerSendTextMessage(cid, 27, "You opened a Gift!")
         doPlayerSendTextMessage(cid, 27, "The prize Pokemon was a "..pokemon..", congratulations!")
         doSendMagicEffect(getThingPos(cid), 29)
              
         addPokeToPlayer(cid, pokemon, 0, nil, "poke")     --alterado v1.9                                                 
         doRemoveItem(item.uid, 1)
    
return true
end
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,241
Solutions
543
Reaction score
4,469
My best guess is that because item is being used globally instead of locally, it's messing with the other function.

Assuming that's correct.. try changing
Lua:
    local cap = getPlayerFreeCap(cid)
    if (getPlayerFreeCap(cid) <= 1 and not isInArray({ 5, 6 }, getPlayerGroupId(cid))) or
to this
Lua:
    local cap = getPlayerFreeCap(cid)
    local item
    if (getPlayerFreeCap(cid) <= 1 and not isInArray({ 5, 6 }, getPlayerGroupId(cid))) or
 
OP
OP
M

Mizakinha

New Member
Joined
Apr 18, 2021
Messages
34
Reaction score
4
My best guess is that because item is being used globally instead of locally, it's messing with the other function.

Assuming that's correct.. try changing
Lua:
    local cap = getPlayerFreeCap(cid)
    if (getPlayerFreeCap(cid) <= 1 and not isInArray({ 5, 6 }, getPlayerGroupId(cid))) or
to this
Lua:
    local cap = getPlayerFreeCap(cid)
    local item
    if (getPlayerFreeCap(cid) <= 1 and not isInArray({ 5, 6 }, getPlayerGroupId(cid))) or
I made this change to put the local variable (item), but it keeps giving the same error. :(
 
Top