• 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 Find item with action id on map

andu

Sold 649 scripts, 25 maps and 9 events!
Joined
Aug 7, 2009
Messages
969
Solutions
17
Reaction score
354
GitHub
olrios
Twitch
olrios
Somewhere, randomly on a map my script spawned an item with random actionid between 1000 and 2000
Do we have in TFS 1.2 function what will let me find that item's coordinates with lua script?

Example, player click on Treasure Map and description appears: "Treasure coordinates are: x, y, z"

example logic:
Code:
function onUse...
local item = searchMapForItemWithActionId(1000)
local itemPos = item:getPosition()
...
 
Last edited:
Solution
Somewhere, randomly on a map my script spawned an item with random actionid between 1000 and 2000
Do we have in TFS 1.2 function what will let me find that item's coordinates with lua script?

Example, player click on Treasure Map and description appears: "Treasure coordinates are: x, y, z"

example logic:
Code:
function onUse...
local item = searchMapForItemWithActionId(1000)
local itemPos = item:getPosition()
...
I don't think so.
You can look full map but it will not be a nice way.
If i have to do something like that, when i spawn the item, i store the item userData in a global table with the Position(x,y,z) as index, then if i need to find the item, just look if the index exist...

Lua:
function spawnMyItem(item, position)...
Somewhere, randomly on a map my script spawned an item with random actionid between 1000 and 2000
Do we have in TFS 1.2 function what will let me find that item's coordinates with lua script?

Example, player click on Treasure Map and description appears: "Treasure coordinates are: x, y, z"

example logic:
Code:
function onUse...
local item = searchMapForItemWithActionId(1000)
local itemPos = item:getPosition()
...
I don't think so.
You can look full map but it will not be a nice way.
If i have to do something like that, when i spawn the item, i store the item userData in a global table with the Position(x,y,z) as index, then if i need to find the item, just look if the index exist...

Lua:
function spawnMyItem(item, position)
    Game.createItem(item, 1, position)
    myGlobalTable[position] = {itemData = item, randomVariable = "blablabla"}
end

function findMyItem(position)
    if myGlobalTable[position] then
        return myGlobalTable[position].itemData
    end
end
Something like that... If you move, remove, alter the item, just alter the table too.
 
Solution
controlling the item before creation (until closing server):
Code:
if not specialItems then -- prevent wiping after reload
specialItems = {}
end

theItem = game.createItem(id, count, pos)
table.insert(specialItems, theItem:getUniqueId())

function something(searched)
    for i = 1, #specialItems do
       local item = Item(specialItems[i])
        if item then
            if item:getActionId() == searched then
                return item
            end
        end
    end
end

or search database attributes somehow
 
You could do it with unique ID just by doing
item = Item(2000) if item then pos =item:getPosition() end
 
Back
Top