Game.getSpectators is very useful function, but you can only specify 'show only player' 'on/off'. I think that function in which you can choose to show player/monster/NPC on list is better.
At end of post is description what 'minRangeX' and other parameters mean in TFS 1.x Game.getSpectators.
Example of use:
Count monsters in range 5 tiles around 'player' on same floor:
# - before function gives number of table elements, not elements
Send message to all players in range 6 tiles:
About min/max range in this function (Game.getSpectators in TFS):
0 = 11 (min/max 11) - so some of your codes with 0, 15 positions could be very wrong, as server translate it to 11!
minRangeX - tiles to left (over 0! not under!)
maxRangeX - tiles to right (over 0! not under!)
minRangeY - tiles to top (over 0! not under!)
maxRangeY - tiles to bottom (over 0! not under!)
Here image with example values and area it will scan for players/monsters/NPCs:
At end of post is description what 'minRangeX' and other parameters mean in TFS 1.x Game.getSpectators.
PHP:
function getCustomSpectators(position, multifloor, showPlayers, showMonsters, showNPCs, minRangeX, maxRangeX, minRangeY, maxRangeY)
//getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
local spectators = Game.getSpectators(position, multifloor, false, minRangeX, maxRangeX, minRangeY, maxRangeY)
customSpectatorsList = {}
for _, spectatorCreature in ipairs(spectators) do
if (showPlayers and spectatorCreature:isPlayer()) or
(showMonsters and spectatorCreature:isMonster()) or
(showNPCs and spectatorCreature:isNpc()) then
table.insert(customSpectatorsList, spectatorCreature)
end
end
return customSpectatorsList
end
Example of use:
Count monsters in range 5 tiles around 'player' on same floor:
PHP:
local numberOfMonstersAroundPlayerInRange_5 = #getCustomSpectators(player:getPosition(), false, false, true, false, 5, 5, 5, 5)
Send message to all players in range 6 tiles:
PHP:
local tmpSpectators = getCustomSpectators(player:getPosition(), false, true, false, false, 6, 6, 6, 6)
for _, playerInRange in pairs(tmpSpectators) do
playerInRange:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are noob.")
end
About min/max range in this function (Game.getSpectators in TFS):
0 = 11 (min/max 11) - so some of your codes with 0, 15 positions could be very wrong, as server translate it to 11!
minRangeX - tiles to left (over 0! not under!)
maxRangeX - tiles to right (over 0! not under!)
minRangeY - tiles to top (over 0! not under!)
maxRangeY - tiles to bottom (over 0! not under!)
Here image with example values and area it will scan for players/monsters/NPCs:

Last edited: