Marco Oliveira
Well-Known Member
- Joined
- Jan 5, 2019
- Messages
- 76
- Solutions
- 3
- Reaction score
- 78
- Location
- Minas Gerais - Brazil
- GitHub
- omarcopires
- Twitch
- omarcopires
Hello, I hope you are well!
I am having some problems with my autoloot system and would like some help if possible, I would be very grateful.
One of the problems returns error in the console when there is some kind of field or monster on top of the body when char tries to open, follows the following error:
Another problem I have with the system is that it simply ignores when the player no longer has the cap to load the item, it simply adds the item to the backpack.
autoloot actions:
lines 5 and 7 were added in a failed fix attempt, so can be removed if necessary.
I hope someone can help me, if something in the writing went wrong or rude I apologize because my english is bad and I have to use google translator, :x
Another problem discovered is that it ignores the body owner, making it possible to open any body!
I am having some problems with my autoloot system and would like some help if possible, I would be very grateful.
One of the problems returns error in the console when there is some kind of field or monster on top of the body when char tries to open, follows the following error:
Code:
2019-10-21 22:17:16 - Lua Script Error: [Action Interface]
2019-10-21 22:17:16 - data/actions/scripts/others/variables/autoloot.lua:onUse
2019-10-21 22:17:16 - data/actions/scripts/others/variables/autoloot.lua:5: attempt to index a nil value
2019-10-21 22:17:16 - stack traceback:
2019-10-21 22:17:16 - [C]: in function '__index'
2019-10-21 22:17:16 - data/actions/scripts/others/variables/autoloot.lua:5: in function <data/actions/scripts/others/variables/autoloot.lua:1>
Another problem I have with the system is that it simply ignores when the player no longer has the cap to load the item, it simply adds the item to the backpack.
autoloot actions:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local issue = {}
local bodycontainer, slot, msg = {}, 0, ''
if not Tile(toPosition):getTopVisibleThing() then
return true
end
local monster = Tile(toPosition):getTopVisibleThing()
local corpse = getTileItemById(toPosition, monster:getId()).uid
local slots = getContainerSize(corpse)
if not corpse or not slots then
return false
end
local logic, contlogic, bplogica = 1, {}, {}
if getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) then
for i = 0, getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) do
contlogic[logic] = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
if isContainer(contlogic[logic].uid) then
bplogica[logic] = contlogic[logic]
logic = logic + 1
end
end
end
for times = 1, slots do
bodycontainer[times] = getContainerItem(corpse, slot)
if player:getAutoLootItem(bodycontainer[times].itemid) then
local slotcorpse = bodycontainer[times].uid
local itemcorpse = Item(slotcorpse)
local slotgg
local localizou
local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. itemcorpse:getId() .. '')
if resultId then
local bp_id = result.getNumber(resultId, 'cont_id')
end
for i = 1, #bplogica do
local tempitem = Item(bplogica[i].uid)
if tempitem:getId() == result.getNumber(resultId, 'cont_id') and localizou ~= 1 then
local bp = bplogica[i].uid
local freeSlotsInBp = math.max(0, getContainerCap(bp) - getContainerSize(bp))
if freeSlotsInBp and freeSlotsInBp > 0 then
slotgg = bplogica[i].uid
localizou = 1
end
end
end
local destination = Item(slotgg)
if destination and destination:getTopParent() == player then
local weight = ItemType(itemcorpse):getWeight(itemcorpse.type)
if player:getFreeCapacity() >= weight then
itemcorpse:moveTo(destination)
if bodycontainer[times].type > 1 then
msg = ''..msg.. ', '..bodycontainer[times].type..' '..tostring(ItemType(bodycontainer[times].itemid):getPluralName())..''
else
msg = ''..msg.. ', '..tostring(ItemType(bodycontainer[times].itemid):getName())..''
end
end
else
if not table.contains(issue, bodycontainer[times].itemid) then
table.insert(issue, bodycontainer[times].itemid)
end
local weight = ItemType(itemcorpse):getWeight(itemcorpse.type)
if player:getFreeCapacity() >= weight then
itemcorpse:moveToSlot(player, 0)
end
end
else
slot = slot + 1
end
end
if msg ~= '' then
player:sendTextMessage(MESSAGE_INFO_DESCR,'Looted:'.. string.gsub(" "..msg, "%W%l", string.lower):sub(3) ..' opening corpse')
end
if issue then
if #issue >= 1 then
for i = 1, #issue do
player:sendTextMessage(MESSAGE_INFO_DESCR,'All main '..string.gsub(" "..string.lower(ItemType(issue[i]):getName()), "%W%l", string.upper):sub(2)..' full, buy a new or move itens to sub backpacks.')
end
end
end
end
lines 5 and 7 were added in a failed fix attempt, so can be removed if necessary.
I hope someone can help me, if something in the writing went wrong or rude I apologize because my english is bad and I have to use google translator, :x
Another problem discovered is that it ignores the body owner, making it possible to open any body!
Last edited: