• 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 TFS 1.1 - container:hasItem(item)

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,571
Solutions
3
Reaction score
98
Location
Portugal
hey can any1 tell me how to use properly container:hasItem?

I checked luascript.cpp and I dont see any issue in the way I'm using the function...

I tried:

Code:
function onKill(creature, target)
    local corpsePos = target:getPosition()
    local corpseId = 1987
    local itemId = 11304

    if Container(corpseId,corpsePos):hasItem(itemId) then
        corpsePos:sendMagicEffect(56)
    else
        corpsePos:sendMagicEffect(CONST_ME_POFF)
    end

    return true
end

but I keep getting error

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/looteffect.lua:onKill
data/creaturescripts/scripts/looteffect.lua:6: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/looteffect.lua:6: in function <data/creatur
escripts/scripts/looteffect.lua:1>
 
thanks, and btw, how do I define container pos?

Code:
function onKill(creature, target)

    local corpsePos = target:getPosition()
    local itemId = ItemType(11304)
    local container = Container(ItemType(1987))

    if container:hasItem(itemId) then
        corpsePos:sendMagicEffect(56)
    else
        corpsePos:sendMagicEffect(CONST_ME_POFF)
    end

    return true
end

I checked and TFS 1.1 doesn't actually have

Code:
Container(itemId[, position])
 
This exists in both 1.0 & 1.1
Code:
Game.createContainer(itemId, size[, position])
 
Last edited:
I know but I want to get container from pos, not to create a new container >.<

the container pos is in

Code:
local corpsePos = target:getPosition()

the container is:

Code:
Container(ItemType(1987))

now I just want to check if that position has container like:

Code:
position:Container(ItemType(1987)):hasItem(ItemType(11304))

I just don't know how
 
This is how inheritance works in OOP, all containers are items, but not all items are containers.
Try that...
Code:
Container(ItemType(1987)):getPosition()
 
tried and

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/looteffect.lua:onKill
data/creaturescripts/scripts/looteffect.lua:6: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/looteffect.lua:6: in function <data/creatur
escripts/scripts/looteffect.lua:1>

Code:
function onKill(creature, target)

    local position = target:getPosition()
    local itemId = ItemType(11304)

    if Container(ItemType(1987)):getPosition():hasItem(itemId) then
        position:sendMagicEffect(56)
    else
        position:sendMagicEffect(CONST_ME_POFF)
    end

    return true
end

P.S: I just noticed I guess I'm doing the whole script wrong

Its supposed to send magic effect if creature loot was item 11304

Whats ur opinion? am I doing it correctly (even thats not working yet)?
 
What are you trying to do? Are you trying to check if a bag within a corpse, contains a specific item?
 
Back
Top