• 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 0.3 Count monsters, fromX, toX.

Kuantikum

Member
Joined
Jul 3, 2015
Messages
219
Solutions
1
Reaction score
20
I would like to know if it is possible to count how many monsters there are in an area fromX toX ??



Lua:
local top_left_corner = {x = 3341, y = 804, z = 6}
local bottom_right_corner = {x = 3352, y = 811, z = 6}
 if monsters_summoned[1] then
        local monster_count = 0
        for i = 1, #monsters_summoned do
            if isCreature(monsters_summoned[i]) then
                monster_count = monster_count + 1
            end
        end
 if monster_count > 0 then
            doCreatureSay(cid, monster_count .. " creatures from previous lever activation are still alive.", TALKTYPE_MONSTER)
            return true
        end
    end

Can you help me?
 
Solution
yes monster_count is the variable that is equal to amount of monsters that are in that area

here is script that will check room and even delete if there is no players in room and respawn

Lua:
local room = { -- room with Hide
    fromX = 33300,
    fromY = 32277,
    fromZ = 13,
    toX = 33316,
    toY = 32293,
    toZ = 13}
local config = {
bosspos = {
{x=33308,y=32280,z=13}, -- position where boss first spawns
},
boss = "The Horned Fox", -- name of the boss
from = {{x = 33300, y = 32277, z = 13}},
to = {{x = 33316, y = 32293, z = 13}},
}

local player_pos = {x=33308, y=32288, z=13}
local cansel_pos = {x=33308, y=32285, z=12}

local monster = "The Horned Fox"
function onStepIn(cid, item, frompos, item2, topos)

    if item.uid ==...
yes monster_count is the variable that is equal to amount of monsters that are in that area

here is script that will check room and even delete if there is no players in room and respawn

Lua:
local room = { -- room with Hide
    fromX = 33300,
    fromY = 32277,
    fromZ = 13,
    toX = 33316,
    toY = 32293,
    toZ = 13}
local config = {
bosspos = {
{x=33308,y=32280,z=13}, -- position where boss first spawns
},
boss = "The Horned Fox", -- name of the boss
from = {{x = 33300, y = 32277, z = 13}},
to = {{x = 33316, y = 32293, z = 13}},
}

local player_pos = {x=33308, y=32288, z=13}
local cansel_pos = {x=33308, y=32285, z=12}

local monster = "The Horned Fox"
function onStepIn(cid, item, frompos, item2, topos)

    if item.uid == 34254  then
    killedboss = getPlayerStorageValue(cid,34254)
        if killedboss == -1 and getPlayerStorageValue (cid, 73505) >= 1 then
        local monster_room = false
        local monsters = {}
        local i = 1
            for x = room.fromX, room.toX do
                for y = room.fromY, room.toY do
                    for z = room.fromZ, room.toZ do
                        local pos = {x=x, y=y, z=z,stackpos = 253}
                        local thing = getThingfromPos(pos)
                        if isPlayer(thing.uid) then
                            doPlayerSendTextMessage(cid,19,"The room is currently occupied.") 
                            return true
                        elseif isMonster(thing.uid) then
                            monsters[i] = getThingfromPos({x=x,y=y,z=z,stackpos=253})
                            i = i+1
                            monster_room = true                               
                        end
                    end
                end
            end       
            if monster_room then
                for r = 1, #monsters do
                    doRemoveCreature(monsters[r].uid)
                end
            end
    
        doTeleportThing(cid, player_pos)
        doSummonCreature(config.boss, config.bosspos[1])
        doPlayerSetStorageValue (cid, 34254, 1)
        doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You have ten minutes to kill and loot this boss, else you will lose that chance and will be kicked out.')
        addEvent(checkRoom, 600000, {})
        else
            doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You did not complete the task Quest or you have already fought the boss!')
            doTeleportThing(cid, cansel_pos)
        end
    end
    return true
end



function checkRoom(param)

            for x = room.fromX, room.toX do
                for y = room.fromY, room.toY do
                    for z = room.fromZ, room.toZ do
                        local pos = {x=x, y=y, z=z,stackpos = 253}
                        local thing = getThingfromPos(pos)
                        if isPlayer(thing.uid) then
                            doPlayerSendTextMessage(thing.uid,MESSAGE_EVENT_ADVANCE,"Your time has passed.")
                            doTeleportThing(thing.uid, cansel_pos)
                            return true
                        end
                    end
                end
            end
end
 
Solution
yes monster_count is the variable that is equal to amount of monsters that are in that area

here is script that will check room and even delete if there is no players in room and respawn

Lua:
local room = { -- room with Hide
    fromX = 33300,
    fromY = 32277,
    fromZ = 13,
    toX = 33316,
    toY = 32293,
    toZ = 13}
local config = {
bosspos = {
{x=33308,y=32280,z=13}, -- position where boss first spawns
},
boss = "The Horned Fox", -- name of the boss
from = {{x = 33300, y = 32277, z = 13}},
to = {{x = 33316, y = 32293, z = 13}},
}

local player_pos = {x=33308, y=32288, z=13}
local cansel_pos = {x=33308, y=32285, z=12}

local monster = "The Horned Fox"
function onStepIn(cid, item, frompos, item2, topos)

    if item.uid == 34254  then
    killedboss = getPlayerStorageValue(cid,34254)
        if killedboss == -1 and getPlayerStorageValue (cid, 73505) >= 1 then
        local monster_room = false
        local monsters = {}
        local i = 1
            for x = room.fromX, room.toX do
                for y = room.fromY, room.toY do
                    for z = room.fromZ, room.toZ do
                        local pos = {x=x, y=y, z=z,stackpos = 253}
                        local thing = getThingfromPos(pos)
                        if isPlayer(thing.uid) then
                            doPlayerSendTextMessage(cid,19,"The room is currently occupied.")
                            return true
                        elseif isMonster(thing.uid) then
                            monsters[i] = getThingfromPos({x=x,y=y,z=z,stackpos=253})
                            i = i+1
                            monster_room = true                              
                        end
                    end
                end
            end      
            if monster_room then
                for r = 1, #monsters do
                    doRemoveCreature(monsters[r].uid)
                end
            end
   
        doTeleportThing(cid, player_pos)
        doSummonCreature(config.boss, config.bosspos[1])
        doPlayerSetStorageValue (cid, 34254, 1)
        doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You have ten minutes to kill and loot this boss, else you will lose that chance and will be kicked out.')
        addEvent(checkRoom, 600000, {})
        else
            doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You did not complete the task Quest or you have already fought the boss!')
            doTeleportThing(cid, cansel_pos)
        end
    end
    return true
end



function checkRoom(param)

            for x = room.fromX, room.toX do
                for y = room.fromY, room.toY do
                    for z = room.fromZ, room.toZ do
                        local pos = {x=x, y=y, z=z,stackpos = 253}
                        local thing = getThingfromPos(pos)
                        if isPlayer(thing.uid) then
                            doPlayerSendTextMessage(thing.uid,MESSAGE_EVENT_ADVANCE,"Your time has passed.")
                            doTeleportThing(thing.uid, cansel_pos)
                            return true
                        end
                    end
                end
            end
end
iLL Check it out, thx for share!
 
you are welcome i used script from this forum and edited it to work with my tfs 0.4 glad 0.3 is backwards compatible ;]
 
Back
Top