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

Solved Check if there's 4 monsters of the same kind

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
295
Location
Poland
Hello, I've got one issue with my script.
Basically it should work like this - if there's less than 4 monsters of the same kind the script should summon(within 10s) monsters based on how many of them are, if 3 then summon 1, if 2 then summon 2, but it sometimes spawn more than it is supposed to.
It also don't refresh the status of creatures, so if I kill one and three remains alive it says that there is one monster missing, but if I kill another one before it summon, it still summons one instead of two.
If all of them are being killed in less than 10s then it shouldn't summon anything more.
Could you help me in fixing that?

There's the script:
Code:
local maxSummons = 4
local storage = 6732133

function onThink(creature)
    local targetMonster = creature:getMonster()
    if not targetMonster or targetMonster:getMaster() then
        return
    end

    local t, spectator = Game.getSpectators(targetMonster:getPosition(), false, false, 20, 20, 20, 20)
    local check = 0
    if #t ~= nil then
        for i = 1, #t do
        spectator = t[i]
            if spectator:getName() == "Tentacle Of The Deep Terror" then
               check = check + 1
            end
        end
    end 
    local value = Game.getStorageValue(storage)
    if (check < 4) and (os.time()-value >= 10) then
        addEvent(function(cid)
            local creature = Creature(cid)
            if not creature then
                return
            end         
            for j = 1, maxSummons - check do
                Game.createMonster("Tentacle Of The Deep Terror", creature:getPosition(), false, true)
            end
            return true
        end, 10000, targetMonster:getId())
        Game.setStorageValue(storage, os.time())
    end
return true
end
Any help is appreciated. ;)
 
Back
Top