Tested and working on TFS 0.3.6
Here i'm releasing my function...
Useful to get the count or name from creatures in a certain range
Here is...
So... How to use?
Here is an example to how to use to get the count:
How to get the names:
The names are returned in a table.
Note:
* If you write "creature" in type, function will return names or count of all creatures (monsters, players and npc)
Here i'm releasing my function...
Useful to get the count or name from creatures in a certain range
Here is...
Lua:
function getCreatureInRange(type, fromPos, toPos, toGet, itemid)
local types =
{
["player"] = isPlayer,
["monster"] = isMonster,
["npc"] = isNpc,
["creature"] = isCreature
}
local tmp = {}
local type = types[type]
if(not type) then
print('[getCreatureInRange]>> Unknow type')
return 0
end
local thing = nil
for x = fromPos.x, toPos.x do
for y = fromPos.y, toPos.y do
for z = fromPos.z, toPos.z do
for s = 1, 253 do
local position = {x = x, y = y, z = z, stackpos = s}
thing = getTileThingByPos(position)
if(type(thing.uid) == true) then
table.insert(tmp, thing.uid)
end
end
end
end
end
if(toGet == "count") then
return table.maxn(tmp)
elseif(toGet == "name") then
return tmp
else
print('[getCreatureInRange]>> Unknow creature to get')
return 0
end
return true
end
So... How to use?
Here is an example to how to use to get the count:
Lua:
--in the selected area, there is a demon, a troll and a fire elemental, so...
local fromPos = {x = 100, y = 100, z = 7, stackpos = 1}
local toPos = {x = 150, y = 150, z = 7, stackpos = 1}
local t = getCreatureInRange("monster", fromPos, toPos, "count")
print('>> There are ' .. t .. ' monsters)
Code:
>> There are 3 monsters
How to get the names:
Lua:
--to get the names in the selected area:
local fromPos = {x = 100, y = 100, z = 7, stackpos = 1}
local toPos = {x = 150, y = 150, z = 7, stackpos = 1}
local t = getCreatureInRange("monster", fromPos, toPos, "name")
for i = 1, table.maxn(t) do
print('>> The names are ' .. getCreatureName(t[i]))
end
Code:
>> The names are Demon
>> The names are Troll
>> The names are Fire Elemental
The names are returned in a table.
Note:
* If you write "creature" in type, function will return names or count of all creatures (monsters, players and npc)
Last edited: