- Fórum
- OTServ
- Recursos
- Scripting
- Mods, funções e outros
- Getcreatureinrange(Type, Frompos, Topos, Toget)
SK
Getcreatureinrange(Type, Frompos, Topos, Toget)
Por SkyDangerous, 09 de ago. de 2012 em Mods, funções e outros
1
676
Por SkyDangerous, 09 de ago. de 2012 em Mods, funções e outros
info
Grupo: Lorde
Registrado: 17/01/09
Posts: 2.1k
Reputação: +395
Char no Tibia: Adra Sata
Testado no TFS 0.3.6
A função faz pega tal coisa dentre de uma posição
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 endComo Usar:
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)Exemplo como vai retornar:
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])) endExemplo como vai retornar:
Creditos:
darkhaos
Editado Agosto 9 por SkyDangerous