JayMeazy
Member
- Joined
- Sep 7, 2020
- Messages
- 92
- Solutions
- 2
- Reaction score
- 24
hello, I'm trying to access the tiles in a combat area, like AREA_CIRCLE3X3, to see if monsters and players are there. I created a function spell:area(), and then put the area in spells.xml, here's my function:
which gives me the error:
luaCombatSetArea(). This function can only be used while loading the script.
which is because it's inside the function I guess, and while for this particular function I can set the combat2:setArea(AREA_SQUARE7X7) outside of the function, but this one I can't:
any ideas? I have no idea how to get Game.getSpectators to work with a combat area, I'm thinking about just making it a c++ function, where it handles the combat area.
Code:
local combat2 = Combat()
function getTilesInArea()
-- param1 - pos/creature
-- param2 - pattern
combat2:setArea(AREA_SQUARE7X7)
local tiles = {}
local positions = combat2:getPositions() -- get positions of creatures from combat area
for _, position in ipairs(positions) do
local tile = Tile(position) -- create a tile for this position
tiles[#tiles+1] = tile
end
return tiles
end
luaCombatSetArea(). This function can only be used while loading the script.
which is because it's inside the function I guess, and while for this particular function I can set the combat2:setArea(AREA_SQUARE7X7) outside of the function, but this one I can't:
Code:
local combat = Combat()
function getCreaturesInArea2(param2, param3)
-- param2 - pattern
-- param3 - type of return
-- 1 - everyone, 2 - monsters, 3 - players
local specs = 0
local monsters = 0
local players = 0
combat:setArea(param2)
local positions = combat:getPositions() -- get positions of creatures from combat area
for _, position in ipairs(positions) do
local tile = Tile(position) -- create a tile for this position
for _, creature in ipairs(tile:getCreatures()) do
if creature ~= player then
specs = specs + 1
if creature:isMonster() then
monsters = monsters + 1
elseif creature:isPlayer() then
players = players + 1
end
end
end
end
if param3 == 1 then
return specs
elseif param3 == 2 then
return monsters
else
return players
end
end