Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getCreaturesInRetangleArea(pos_init, pos_final)
- --[[
- getCreaturesInRetangleArea(pos_init, pos_final)
- * pos_init(1) = ponta esquerda superior da area
- * pos_final(2) = ponta direita inferior da area
- @return table -> lista de uids das criaturas na area
- ]]
- -- private
- local function isPosition(pos)
- return (type(pos) == "table" and type(pos.x) == "number" and type(pos.y) == "number" and type(pos.z) == "number")
- end
- local creatureList = {}
- local error = nil
- if not (isPosition(pos_init) and isPosition(pos_final)) then
- error = debug.traceback("Invalid parameters, expected positions")
- end
- if not (pos_init.x <= pos_final.x and pos_init.y <= pos_init.y and pos_init.z == pos_final.z) then
- error = debug.traceback("can't form a retangle with positions")
- end
- if error then
- print(error)
- return false
- end
- for x = pos_init.x, pos_final.x do
- for y = pos_init.y, pos_final.y do
- local pos = {x = x, y = y, z = pos_init.z}
- for stack = 0, getTileInfo(pos).things do
- pos.stackpos = stack
- local thing = getThingfromPos(pos)
- if isCreature(thing.uid) then
- table.insert(creatureList, thing.uid)
- end
- end
- end
- end
- return creatureList
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement