• 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 Script that finds the surrounding items.

Drakkhan

Illuria Project Lead
Joined
Oct 3, 2013
Messages
141
Reaction score
22
I'm looking for a script that gets the SIDs, names and location of the 8 items immediately adjacent to the player when the script is called.

These 8 items (using pseudo-"spell area" notation):
{
{1, 2, 3},
{4, P, 5},
{6, 7, 8}
}

Where P is the player.

Regards,

Drakkhan
 
Found the answer to my question. Note that I'm using TFS 0.2.14 (Mystic Spirit)

On my server, available lua functions can be found in "server/doc/LUA_FUNCTIONS".

So, you can get information on the ground tile at a location with:
Code:
getThingfromPos(pos)

Which returns a table of data on the ground item at the table of position data "pos". This didn't function as I needed, because it ignores a sword for example and returns the grass under it.

I couldn't find a function that reasonably returns the top item at a location.. but I did find this function that returns information on items with provided id if they are at the location:
Code:
getTileItemById(pos, itemId, <optional> subType)

Since I was only looking for a way to check if an item is around the player, this will do. This function returns a table of information on the item with itemId at the position of interest. If an item of itemId is not at the location, 0 is returned.

Test code:

Code:
local playerPos = getCreaturePosition(cid)

local item1pos = {}
item1pos.x = playerPos.x - 1
item1pos.y = playerPos.y - 1
item1pos.z = playerPos.z

local item1 = getTileItemById(item1pos, 2555)
local item1name = getItemName(item1.itemid)


doCreatureSay(cid, string.format("item1: %d %s", item1.itemid, item1name), TALKTYPE_ORANGE_1)

Boom!
 
Back
Top