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

[HELP] Check area for monsters

Spoking

Oldschool Developer
Joined
Sep 4, 2007
Messages
434
Reaction score
34
Hello, I edited this script, but it seems to not be working
Its the end, where it should be looking for monsters in that area.

If there are monsters, say: Please kill the monsters first.
If the area is cleared, it will do

Code:
	elseif clicks == 5 and monsters1 == 0 then
		setGlobalStorageValue(50000, clicks+1)
		doPlayerSay(cid, "You have finished this quest, run on the chair for your reward!", 19)
		addEvent(reset, 30*1*1000) -- 30 seconds



Code:
-- Config #1 -- 
local BlindField = {x=797, y=934, z=7, stackpos=1}
-- end -- 

function mapArea(fromPos, toPos, stack)
        -- Area iterator by Colandus.
        local pos = {x=fromPos.x, y=fromPos.y-1, z=fromPos.z}
        return function()
                if (pos.y < toPos.y) then
                        pos.y = pos.y+1
                elseif (pos.x <= toPos.x) then
                        pos.y = fromPos.y
                        pos.x = pos.x+1
                else
                        pos.x = fromPos.x
                        pos.y = fromPos.y
                        pos.z = pos.z+1
                end
                if (pos.x <= toPos.x and pos.y <= toPos.y or pos.z < toPos.z) then
                        if (stack == nil) then
                                return pos
                        else
                                pos.stackpos = stack
                                --return pos, getTileThingByPos(pos)
                                return pos, getThingfromPos(pos)
                        end
                end
        end
end


function getMonstersfromArea(fromPos, toPos)
        local monsters = {}    
        for _, thing in mapArea(fromPos, toPos, 253) do
                if isMonster(thing.uid) == TRUE then
                        table.insert(monsters, thing.uid)
            end

        end
          local bfm = getThingfromPos(BlindField)
            if isMonster(bfm.uid) == TRUE then
            table.insert(monsters, bfm.uid)
            end
        return monsters
end

function getMonstersNumbersfromArea(fromPos, toPos)  
        for _, thing in mapArea(fromPos, toPos, 253) do
                if isMonster(thing.uid) == TRUE then
					return 1
                else 
					return 0
				end
		end
end



function onUse(cid, item, fromPosition, itemEx, toPosition)

-- CONFIG #2!!!! --


-- Map checking --

local topLeft = {x=790, y=927, z=7}
local buttomRight = {x=800, y=942, z=7}

-- Immortality of Azerus
local monsters = getMonstersfromArea(topLeft, buttomRight)
local monsters1 = getMonstersNumbersfromArea(topLeft, buttomRight)

-- Position Of TP --
local tp = {x=795, y=928, z=7}

-- Position of Gllobus
local glo = {x=795, y=934, z=7}

-- END OF CONFIG! --



function FirstWave()
    doSummonCreature("Rift Worm", {x= glo.x - 4,y=glo.y,z=glo.z})

    doSummonCreature("Rift Worm", {x= glo.x + 4,y=glo.y,z=glo.z})

    doSummonCreature("Rift Worm", {x=glo.x,y=glo.y + 4,z=glo.z})

    doSummonCreature("Rift Worm", {x=glo.x,y=glo.y - 4,z=glo.z})

    doSummonCreature("Rift Worm", {x=glo.x,y=glo.y + 5,z=glo.z})

    doSummonCreature("Azerus", {x=glo.x,y=glo.y - 5,z=glo.z})
end

function SecondWave()
local monsters1 = getMonstersfromArea(topLeft, buttomRight)

    for _, monster in pairs(monsters1) do
    if getCreatureName(monster) == "Azerus" then
    doRemoveCreature(monster)
    end
    end
    doSummonCreature("Azerus1", {x=glo.x,y=glo.y - 5,z=glo.z})

    doSummonCreature("Rift Brood", {x= glo.x - 4,y=glo.y,z=glo.z})

    doSummonCreature("Rift Brood", {x= glo.x + 4,y=glo.y,z=glo.z})

    doSummonCreature("Rift Brood", {x=glo.x,y=glo.y + 4,z=glo.z})

    doSummonCreature("Rift Brood", {x=glo.x,y=glo.y - 4,z=glo.z})

    doSummonCreature("Rift Brood", {x=glo.x,y=glo.y + 5,z=glo.z})
end
function ThirdWave()
local monsters1 = getMonstersfromArea(topLeft, buttomRight)

    for _, monster in pairs(monsters1) do
    if getCreatureName(monster) == "Azerus" then
    doRemoveCreature(monster)
    end
    end
    doSummonCreature("Azerus2", {x= glo.x - 5,y=glo.y,z=glo.z})

    doSummonCreature("Rift Scythe", {x= glo.x - 4,y=glo.y,z=glo.z})

    doSummonCreature("Rift Scythe", {x= glo.x + 4,y=glo.y,z=glo.z})
end

function ThirdWave1() --  with 2s delay

    doSummonCreature("Rift Scythe", {x=glo.x,y=glo.y + 4,z=glo.z})

    doSummonCreature("Rift Scythe", {x=glo.x,y=glo.y - 4,z=glo.z})

    doSummonCreature("Rift Scythe", {x=glo.x,y=glo.y + 5,z=glo.z})
end

function FourthWave()
local monsters1 = getMonstersfromArea(topLeft, buttomRight)

    for _, monster in pairs(monsters1) do
    if getCreatureName(monster) == "Azerus" then
    doRemoveCreature(monster)
    end
    end
    doSummonCreature("Azerus3", {x= glo.x - 5,y=glo.y,z=glo.z})

    doSummonCreature("War Golem", {x= glo.x - 4,y=glo.y,z=glo.z})

    doSummonCreature("War Golem", {x= glo.x + 4,y=glo.y,z=glo.z})

    doSummonCreature("War Golem", {x=glo.x,y=glo.y - 4,z=glo.z})

    doSummonCreature("War Golem", {x=glo.x,y=glo.y + 4,z=glo.z})

end

function Glllobe()
local GlobePos = {x=795, y=934, z=7, stackpos = 1}
doItemSetAttribute(getThingFromPos(GlobePos).uid, "aid", 58261)
end

function reset()
setGlobalStorageValue(50000, 0)
local monsters1 = getMonstersfromArea(topLeft, buttomRight)
    for _, monster in pairs(monsters1) do
	doRemoveCreature(monster)
	end
end


local monsters = getMonstersfromArea(topLeft, buttomRight)
local monsters1 = getMonstersNumbersfromArea(topLeft, buttomRight)


local clicks = getGlobalStorageValue(50000)
	if clicks < 1 then
		addEvent(FirstWave, 0)
		setGlobalStorageValue(50000, 1)
	elseif clicks == 1 then
		addEvent(SecondWave, 0)
		setGlobalStorageValue(50000, clicks+1)
	elseif clicks == 2 then
		addEvent(ThirdWave, 0)
		addEvent(ThirdWave1, 0)
		setGlobalStorageValue(50000, clicks+1)
	elseif clicks == 3 then	
		addEvent(FourthWave, 0)
		setGlobalStorageValue(50000, clicks+1)
	elseif clicks == 4 then
		addEvent(Glllobe, 0) 
		setGlobalStorageValue(50000, clicks+1)
	elseif clicks == 5 and monsters1 == 0 then
		setGlobalStorageValue(50000, clicks+1)
		doPlayerSay(cid, "You have finished this quest, run on the chair for your reward!", 19)
		addEvent(reset, 30*1*1000) -- 30 seconds
	elseif clicks == 5 and monsters1 == 1 then
		doPlayerSendTextMessage(cid,22,"Kill first.")
	elseif clicks == 6 then
		doPlayerSendTextMessage(cid, 22, "You may not spam this machine, please wait 30 seconds.")
	end




return TRUE
end
 
movements/movements.xml:
Code:
<movevent type="StepIn" actionid="[B]XXXX[/B]" event="script" value="[B]whatEverYouWant.lua[/B]"/>

movements/scripts/whatEverYouWant.lua
:
Code:
local cfg = {
    fromPos = {1780, 650, 7}, -- Area top left position.
    toPos = {1880, 720, 7}, -- Area bottom right position.
    newPos = {x = 1234, y = 1234, z = 7}[COLOR=Red],[/COLOR] -- Where player will get teleported when stepping on the tile.
    msg_pass = "You finished the quest! Congratulations!",
    msg_fail = "You have to kill all monsters first!",
    msg_type = MESSAGE_EVENT_ADVANCE,
    }
    
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) then
        for x = cfg.fromPos[1], cfg.toPos[1] do
            for y = cfg.fromPos[2], cfg.toPos[2] do
                for z = cfg.fromPos[3], cfg.toPos[3] do
                    pos = {x = x, y = y, z = z, stackpos = 253}
                    get = getThingPos(pos)
                    if isMonster(get) then
                        doPlayerSendTextMessage(cid, cfg.msg_type, cfg.msg_fail)
                        doTeleportThing(cid, fromPosition, FALSE)
                    else
                        [COLOR=Red]doPlayerSendTextMessage(cid, cfg.msg_type, cfg.msg_pass)[/COLOR]
                        doTeleportThing(cid, cfg.newPos, FALSE)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
                    end
                end
            end
        end
    end
    return TRUE
end
Maybe it's not what you wanted, but it's what I think you mean :p
 
Last edited:
PHP:
        for x = cfg.fromPos[1], cfg.toPos[1] do
            for y = cfg.fromPos[2], cfg.toPos[2] do
                for z = cfg.fromPos[3], cfg.toPos[3] do
explain
 
it explains itself ;s

Well uhm.. I can't explain very good xD but it works like isInArea(pos, fromPos, toPos), I guess


EDIT; @Xeon, huh?

EDIT2; edited the script, found a missing ",". The edited stuffs are marked in red
 
Last edited:
Back
Top