• 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!

Lua Check monster in X area

fironfox

New Member
Joined
Dec 14, 2012
Messages
42
Reaction score
1
Hello guys, i'm making a script of one quest and i need to know if have one function or someone have a script to check if in X area have X monster, and if have X monster the script don't spawn it again. I'm using tfs 1.2
 
provide the script
Code:
    silver = {x=33527, y=32419, z=12}

function onUse(cid, item, fromPosition, itemEx)
    local player = Player(cid)
    if not player then
        return true
    end
    if(item.itemid == 22604) then
        if(itemEx.itemid == 22638) then
            if player:getStorageValue(1) and #Game.getSpectators(silver, false, true, 16, 16, 16, 16) == 0 then
                doTeleportThing(cid, silver)
                doSummonCreature("terofar", {x=33524, y=32418, z=12})
                doRemoveItem(item.uid, 1)
            end
        end
    end
    return true
end
 
getSpectators returns a table of creature ids for all creatures currently in the specified area (i think... :D)
map.h

Code:
void getSpectators(SpectatorVec& list, const Position& centerPos, bool multifloor = false, bool onlyPlayers = false,
                           int32_t minRangeX = 0, int32_t maxRangeX = 0,
                           int32_t minRangeY = 0, int32_t maxRangeY = 0);
 
map.h

Code:
void getSpectators(SpectatorVec& list, const Position& centerPos, bool multifloor = false, bool onlyPlayers = false,
                           int32_t minRangeX = 0, int32_t maxRangeX = 0,
                           int32_t minRangeY = 0, int32_t maxRangeY = 0);
Hmm, so if i need check if have monster in position X i onlye need set this #Game.getSpectators(silver, false, FALSE, 16, 16, 16, 16) to check player or monsters?

This is correct? I'm not at home now and i can't test
Code:
if  #Game.getSpectators(silver, false, true, 16, 16, 16, 16) == 0 and #Game.getSpectators(silver, false, false, 16, 16, 16, 16) == 1 then
    doTeleportThing(cid, silver)
    doRemoveItem(item.uid, 1)
    else if #Game.getSpectators(silver, false, true, 16, 16, 16, 16) == 0 and #Game.getSpectators(silver, false, false, 16, 16, 16, 16) == 0
        doTeleportThing(cid, silver)
        doSummonCreature("terofar", {x=33524, y=32418, z=12})
        doRemoveItem(item.uid, 1)
        else if  #Game.getSpectators(silver, false, true, 16, 16, 16, 16) == 1
            return false
        end
 
Last edited:
Code:
if #Game.getSpectators(silver, false, false, 16, 16, 16, 16)-#Game.getSpectators(silver, false, true, 16, 16, 16, 16) > 0 then
This if you don't want to specify the monster you want in the area.

If you want to check if X monster is in the area you have to iterate over the table and check every creature in it.
 
Code:
if #Game.getSpectators(silver, false, false, 16, 16, 16, 16)-#Game.getSpectators(silver, false, true, 16, 16, 16, 16) > 0 then
This if you don't want to specify the monster you want in the area.

If you want to check if X monster is in the area you have to iterate over the table and check every creature in it.
oh god D: but, my script i have posted here are correct??
 
Test it maybe?
I'm in home now and i will test it today and edit here

Edited:
I have make that script for my tfs 1.2, and i'm no get erros in log but the scripts don't work, what could be?
Code:
local centralareaboss = {x = 33481, y = 32869, z = 11}

function onUse(cid, item, fromPosition, itemEx)
    local player = Player(cid)
    if not player then
        return true
    end
            pos1 = {x = 33440, y = 32877, z = getCreaturePosition(cid).z}
            --pos2 = {x = 33440, y = 32878, z = getCreaturePosition(cid).z}
            --pos3 = {x = 33440, y = 32879, z = getCreaturePosition(cid).z}
            --pos4 = {x = 33440, y = 32880, z = getCreaturePosition(cid).z}
            --pos5 = {x = 33440, y = 32881, z = getCreaturePosition(cid).z}
    if(isPlayer(getTopCreature(pos1).uid)) then --and (isPlayer(getTopCreature(pos2).uid) and (isPlayer(getTopCreature(pos3).uid) and (isPlayer(getTopCreature(pos4).uid) and (isPlayer(getTopCreature(pos5).uid) then
        if  #Game.getSpectators(centralareaboss, false, true, 16, 16, 16, 16) == 0 and #Game.getSpectators(centralareaboss, false, false, 16, 16, 16, 16) == 1 then
            doTeleportThing(getTopCreature(pos1).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos2).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos3).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos4).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos5).uid, {x = 33481, y = 32869, z = 11})   
        end           
        if #Game.getSpectators(centralareaboss, false, true, 16, 16, 16, 16) == 0 and #Game.getSpectators(centralareaboss, false, false, 16, 16, 16, 16) == 0 then
            doTeleportThing(getTopCreature(pos1).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos2).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos3).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos4).uid, {x = 33481, y = 32869, z = 11})
            --doTeleportThing(getTopCreature(pos5).uid, {x = 33481, y = 32869, z = 11})   
            doSummonCreature("Rat", centralareaboss)
        end
        if  #Game.getSpectators(centralareaboss, false, true, 16, 16, 16, 16) == 1 then
            return false
        end
    end
    return true
end
ps: i used comments for thest only 1 sqm
 
Last edited:
Back
Top