• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Count monsters from Game.getSpectators

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,758
Solutions
127
Reaction score
2,277
Hello, im trying to count all monsters in area with this function:
Code:
local specs = Game.getSpectators(Position(getCreaturePosition(cid)), false, false, 20, 20, 20, 20)
Im getting spectators that are in area but how to convert it to number to make statement like this?:
Code:
if count < 4 then
do something

Thank you for any help :D
 
If it's TFS 1.2 then:

Code:
    local specs = Game.getSpectators(Position(creature:getPosition()), false, false, 20, 20, 20, 20)
    local count = 0
    for i = 1, #specs do
        local spectator = specs[i]
        if spectator:isMonster()  then
            count = count + 1
        end
    end
    if (count < 4) then
    -- do something
    end
 
If it's TFS 1.2 then:

Code:
    local specs = Game.getSpectators(Position(creature:getPosition()), false, false, 20, 20, 20, 20)
    local count = 0
    for i = 1, #specs do
        local spectator = specs[i]
        if spectator:isMonster()  then
            count = count + 1
        end
    end
    if (count < 4) then
    -- do something
    end
doing this will only execute it once depending on circumstances, hence count will always be equal to 1. Therefore, you have to repeat it until you have what you seek and then do whatever you want to execute once that statement has been fulfilled.
 
Last edited:
One question more for you guys, is there any method to check, when monster dies, radius 2x2 near corpse ?

Or to check radius 2x2 near defined item in defined area?
for example: local area {x, y, z} to {xx, yy, zz} and check if in this area there is item with id ex. xxxx when if is check if near this item there is another item if yes then do something?
 
One question more for you guys, is there any method to check, when monster dies, radius 2x2 near corpse ?

Or to check radius 2x2 near defined item in defined area?
for example: local area {x, y, z} to {xx, yy, zz} and check if in this area there is item with id ex. xxxx when if is check if near this item there is another item if yes then do something?
Did I get you right? You kill a monster, it dies within a radius of 2 sqm of a specific corpse(?) and if it is, then execute rest of script?
 
Did I get you right? You kill a monster, it dies within a radius of 2 sqm of a specific corpse(?) and if it is, then execute rest of script?
I did it already with checking positions of the radius near the item.
Its like: you have monster and item.
M M M
M X M
M M M
x = item
m = monster

And if monster die in any M position it will do something.
 
I did it already with checking positions of the radius near the item.
Its like: you have monster and item.
M M M
M X M
M M M
x = item
m = monster

And if monster die in any M position it will do something.
ah oki, change title to solved
 
Back
Top