Action [TFS 1.X] Cursed Chests

Shadow_

Intermediate OT User
Joined
Jun 2, 2018
Messages
418
Best answers
16
Reaction score
100
Location
Cairo, Egypt
Code:
    <globalevent name="CursedChestSpawner" interval="43200000โ€ฌ" script="cursed_chest_spawner.lua"/>
I don't want another chest to spawn after the finished one does anybody know how because I couldn't catch why it do this in the script
--edit
i did it by that way is it safe?
Code:
CURSED_CHESTS_AID = 4283

CURSED_CHESTS_SPAWNS = {
    [1] = {
        pos = Position(980, 1080, 7),
        size = 10,
        chests = {1}
    },
    [2] = {
        pos = Position(1060, 1085, 7),
        size = 10,
        chests = {1}
    },
    [3] = {
        pos = Position(1090, 1050, 7),
        size = 10,
        chests = {1}
    }
}

function _onThink(cid, interval, lastExecution)
    for spawnId, data in ipairs(CURSED_CHESTS_SPAWNS) do
        if not data.spawned then
            local from = Position(data.pos.x - data.size, data.pos.y - data.size, data.pos.z)
            local to = Position(data.pos.x + data.size, data.pos.y + data.size, data.pos.z)
            local chestId = math.random(1, #data.chests)
            local spawnPos = Position(math.random(from.x, to.x), math.random(from.y, to.y), data.pos.z)
            local tile = Tile(spawnPos)
            local spawnTest = 0

            while spawnTest < 100 do
                if isBadTile(tile) then
                    spawnPos = Position(math.random(from.x, to.x), math.random(from.y, to.y), data.pos.z)
                    tile = Tile(spawnPos)
                    spawnTest = spawnTest + 1
                else
                    break
                end
            end

            if spawnTest < 100 then
                local rarity = nil
                for i = #CURSED_CHESTS_TIERS, 1, -1 do
                    rarity = CURSED_CHESTS_TIERS[i]
                    if math.random(1, 100) <= rarity.chance then
                        break
                    end
                end
                if rarity ~= nil then
                    local chest = Game.createItem(rarity.item, 1, spawnPos)
                    chest:setActionId(CURSED_CHESTS_AID)
                    spawnPos:sendMagicEffect(CONST_ME_GROUNDSHAKER)
                    local chestData = {}
                    chestData.pos = spawnPos
                    chestData.spawnId = spawnId
                    chestData.wave = 0
                    chestData.monsters = {}
                    chestData.active = 0
                    chestData.finished = false
                    chestData.container = chest
                    chestData.chest = CURSED_CHESTS_CONFIG[chestId]
                    chestData.rarity = rarity
                    CURSED_CHESTS_DATA[#CURSED_CHESTS_DATA + 1] = chestData
                    data.spawned = true
                end
            end

        end
    end
    return true
end

function onThink(cid, interval, lastExecution)
    addEvent(_onThink, 43200000)
   return true
end
 
Last edited:

Lucifer

Active Member
Joined
Dec 27, 2014
Messages
144
Best answers
0
Reaction score
31
Location
Sweden
@oen432 Is it possible to change this script so it only summon monsters and the chest disappear direclty after spawning the monsters without any reward on the chest?
 

andu

Sold 649 scripts, 25 maps and 9 events!
Joined
Aug 7, 2009
Messages
926
Best answers
13
Reaction score
282
I tested it for a while and:

bug:
if there is alot of firefields around - some monsters are not spawning. Problably becouse on spawnpos is firefield and in every pos around. After that script instead of spawning 20 mobs, spawns only 19 or less and there is no way to advance forward in waves. You have to add a function what checks for firefields etc or check how many script has spawned mobs in total without any errors.

Also there is no way to edit boss for each chest rarity. You may change the code to make last wave be always a boss fight, unless something other is in cfg.

It would be good if chest are able to spawn randomly around the map. Deeper map - higher rarity. And more chests at once. Example one chest spawns every 5 minutes, for up to 30 chests in total. When 30th spawned players needs to destroy one chest to make script spawn 31th etc.
In the past I made a script what spawns herbs for alchemists around the map. Script was checking if lava is near, if yes - script was spawning fire blossoms etc. I can give you that code, so you will be able to upgrade your cursed chests.


#edit
are chests immune to disintegrate rune? my rune's script is bugged, someone have to check it
 
Last edited:
Top