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:
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