• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.x] getCustomSpectators(..) - show player/monster/NPC - on/off

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,955
Solutions
98
Reaction score
3,351
Location
Poland
GitHub
gesior
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.

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)
# - before function gives number of table elements, not elements

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:
kAbF8ZCkc.jpg
 
Last edited:
Your scripts are amazing but I didnt understand, what this script do? sorry
 
I believe it's a new function that can be applied in many different instances.

For example, you could use this function to check if there are any monsters, players, or NPCs within "x" range of player.

Example:
A door won't level that opens a door won't work unless the boss is dead. You can use this to check if there the boss monster is within 10 spaces of the player. If the boss isn't there, then the level will work and open the door. If the monster is still spawned, then the lever won't work.

I'm just assuming, though.
 
this is impractical function.
I hope new scripters do not adapt this.

Although some of my first scripts used it, its still pretty bad and no longer using it anywhere and never will.

A hint for better solution:
Table:getPlayers()
Table:getMonsters()
Table:getCreatures()
Table:getNpcs()
 
Back
Top