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

Lua help with event script tfs 1.2

jackl90

Member
Joined
Jul 25, 2017
Messages
249
Reaction score
12
i have loot analyzer on client. but actually just work if the item of is moved from corpse to player container, i need change this to work too if player push item from corpse to ground or from corpse to player container both...

This script i have.
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local t = Tile(fromCylinder:getPosition())
    local corpse = t:getTopDownItem()
    
    if corpse then
        local itemType = corpse:getType()
        if itemType:isCorpse() and toPosition.x == CONTAINER_POSITION then
            self:checkAnalyzerLootItem(item:getId(), item:getCount())
            
            dropAnalyzer = {}
                table.insert(dropAnalyzer, item:getName())
                table.insert(dropAnalyzer, item:getCount())
                table.insert(dropAnalyzer, item:getId())
            self:addAnalyzerDrop(dropAnalyzer)
        end
    end
end
 
Try this:
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
local t = Tile(fromCylinder:getPosition())
local corpse = t:getTopDownItem()
if corpse then
   local itemType = corpse:getType()
   for i = 1,255 do
      local notAllowed = getThingFromPos({x=toPosition.x,y=toPosition.y,z=toPosition.z,stackpos=i})
      if itemType:isCorpse() and notAllowed or itemType:isCorpse() and toPosition.x == CONTAINER_POSITION then
         self:checkAnalyzerLootItem(item:getId(), item:getCount())
         dropAnalyzer = {}
         table.insert(dropAnalyzer, item:getName())
         table.insert(dropAnalyzer, item:getCount())
         table.insert(dropAnalyzer, item:getId())
         self:addAnalyzerDrop(dropAnalyzer)
      end
   end
end
end
 
I didn't quite understand your explanation, but here is an example:
If the item is moved to another place outside the corpse this will happen:
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if not fromCylinder or fromCylinder:isTile() or fromCylinder == toCylinder then
        return true
    end

    local topParent = fromCylinder:getTopParent()
    if not topParent or not topParent:isItem() or not topParent:getType():isCorpse() then
        return true
    end

    -- If the item is moved to another place outside the corpse this will happen:
    local itemId = item:getId()
    self:checkAnalyzerLootItem(itemId, count)
    self:addAnalyzerDrop({item:getName(), count, itemId})
    return true
end
Whatever this function is, someone could place a macro to loot the corpse and then put the items back on the corpse and then loot them again, and so on indefinitely until the corpse rots and searches for another, I hope you have that protected somehow in case it is harmful to your system.
 
Back
Top