• 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 Check if target.x offset == an item

MrVilhelm

Mafia Penguin
Joined
Dec 11, 2020
Messages
141
Solutions
1
Reaction score
113
Location
Sweden
GitHub
MrVilhelm
Hi! Me again 🤓 !

So Im trying Lua again and Im trying to search for a target.x offset. basically what I want is that when you use an item anywhere the script checks if that position you used the item on - 9 x has an object on it.

I tried this but got an error
Lua:
elseif (target.x - 9):getId() == 2113 then

//I also tried


    local activeTile = {
        x = toPosition.x,
        y = toPosition.y + 10,
        z = toPosition.z
    }

elseif activeTile:getId() == 2113 then
Sadly I failed in both occasions :(

Error output for the first one : attempt to perform arithmetic on field 'x' (a nil value)
Error output for the second one : attempt to call method 'getId' (a nil value)

EDIT ( Realised I was searching for a x in the first one instead of the Y, but I was searching for the Y, anywho, same error but just wanted to let you know, YES I saw I wrote it wrong XD )
 
Solution
Hi! Me again 🤓 !

So Im trying Lua again and Im trying to search for a target.x offset. basically what I want is that when you use an item anywhere the script checks if that position you used the item on - 9 x has an object on it.

I tried this but got an error
Lua:
elseif (target.x - 9):getId() == 2113 then

//I also tried


    local activeTile = {
        x = toPosition.x,
        y = toPosition.y + 10,
        z = toPosition.z
    }

elseif activeTile:getId() == 2113 then
Sadly I failed in both occasions :(

Error output for the first one : attempt to perform arithmetic on field 'x' (a nil value)
Error output for the second one : attempt to call method 'getId' (a nil value)

EDIT ( Realised I was searching for a x in the...
Hi! Me again 🤓 !

So Im trying Lua again and Im trying to search for a target.x offset. basically what I want is that when you use an item anywhere the script checks if that position you used the item on - 9 x has an object on it.

I tried this but got an error
Lua:
elseif (target.x - 9):getId() == 2113 then

//I also tried


    local activeTile = {
        x = toPosition.x,
        y = toPosition.y + 10,
        z = toPosition.z
    }

elseif activeTile:getId() == 2113 then
Sadly I failed in both occasions :(

Error output for the first one : attempt to perform arithmetic on field 'x' (a nil value)
Error output for the second one : attempt to call method 'getId' (a nil value)

EDIT ( Realised I was searching for a x in the first one instead of the Y, but I was searching for the Y, anywho, same error but just wanted to let you know, YES I saw I wrote it wrong XD )

(Assuming you are using TFS 1.3):
Lua:
local useItem = Action()

function useItem.onUse(player, item, fromPosition, itemEx, toPosition)
    local destinationTile = Tile(toPosition.x - 9, toPosition.y, toPosition.z)
    if destinationTile then
        local itemAtDestination = destinationTile:getItemById(2113)
        if itemAtDestination then
            -- item found at "target.x - 9"
        end
    end
    return true
end

useItem:id(2159) -- item to use
useItem:register()
 
Solution
(Assuming you are using TFS 1.3):
Lua:
local useItem = Action()

function leuseItem.onUse(player, item, fromPosition, itemEx, toPosition)
    local destinationTile = Tile(toPosition.x - 9, toPosition.y, toPosition.z)
    if destinationTile then
        local itemAtDestination = destinationTile:getItemById(2113)
        if itemAtDestination then
            -- item found at "target.x - 9"
        end
    end
    return true
end

useItem:id(2159) -- item to use
useItem:register()
Yes TFS 1.3, sorry for that. Forgot that!
Post automatically merged:

(Assuming you are using TFS 1.3):
Lua:
local useItem = Action()

function useItem.onUse(player, item, fromPosition, itemEx, toPosition)
    local destinationTile = Tile(toPosition.x - 9, toPosition.y, toPosition.z)
    if destinationTile then
        local itemAtDestination = destinationTile:getItemById(2113)
        if itemAtDestination then
            -- item found at "target.x - 9"
        end
    end
    return true
end

useItem:id(2159) -- item to use
useItem:register()
Thanks a lot for the answer!

Output I got while trying this :

attempt to index global 'leuseItem' (a nil value)
3: 'end' expected (to close 'function' at line 1) near '<eof>'
Post automatically merged:

(Assuming you are using TFS 1.3):
Lua:
local useItem = Action()

function useItem.onUse(player, item, fromPosition, itemEx, toPosition)
    local destinationTile = Tile(toPosition.x - 9, toPosition.y, toPosition.z)
    if destinationTile then
        local itemAtDestination = destinationTile:getItemById(2113)
        if itemAtDestination then
            -- item found at "target.x - 9"
        end
    end
    return true
end

useItem:id(2159) -- item to use
useItem:register()
But anyways, I read what you did and I got out a working thing atleast ^^ SO thanks a lot

Lua:
local activeTile = Tile(toPosition.x, toPosition.y + 10, toPosition.z)

elseif activeTile:getItemById(2113) then

final solution ^^
 
Last edited:
Back
Top