• 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 Random Spawn in arena

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
I am trying to do a function to adapt my system, it is an arena and inside the arena will summon several monsters in random spaces, however I am not able to make them sum up in space and only in place.

TFS 1.3

Lua:
_CHAMPARENA_LH = {
    monsterPos      = {x = 130, y = 362, z = 7},
    arenaCenter     = {x = 132, y = 362, z = 7},     
    arenaLength        = 2,                            
    arenaWidth         = 3               
}

function _CHAMPARENA_LH.sendWave(number)
    if Game.getStorageValue(_CHAMPARENA_LH.global_storage) < 0 then
        return false
    end
    
    for name, amount in pairs(_CHAMPARENA_LH.waves[number]) do
        for i = 1, amount do
            local cid = Game.createMonster(name, _CHAMPARENA_LH.monsterPos, true, true)           
            cid:registerEvent("CHArenaDeath")
        end

        Position(_CHAMPARENA_LH.monsterPos):sendMagicEffect(11)
    end
    
    Game.setStorageValue(_CHAMPARENA_LH.global_storage, number)   

    Game.setStorageValue(_CHAMPARENA_LH.global_aux, -1)
    addEvent(_CHAMPARENA_LH.prepareWave, _CHAMPARENA_LH.waveInterval * 60000, number + 1)
    return true
end

As we realize he summons in just one place, my goal is to summon up several monsters in random places within the arena.

Can you help me? I'm trying to adapt this function: Lua - Monster dont spawning on random position (https://otland.net/threads/monster-dont-spawning-on-random-position.256308/#post-2483501)
 
Solution
post code data/lib/arena.lua

I looked at the zombie arena and managed to get the function they use, thank you very much
Lua:
function _CHAMPARENA_LH.getRandomSpawnPosition(fromPosition, toPosition)
    local random = math.random
    return Position(random(fromPosition.x, toPosition.x), random(fromPosition.y, toPosition.y), random(fromPosition.z, toPosition.z))
end
Lua:
_CHAMPARENA_LH = {
    monsterPos    = Position(130, 362, 7),
    arenaCenter    = Position(132, 362, 7),   
    arenaLength    = 2,                         
    arenaWidth    = 3             
}

function _CHAMPARENA_LH.sendWave(number)
    if Game.getStorageValue(_CHAMPARENA_LH.global_storage) < 0 then
        return false
    end
  
    for name, amount in pairs(_CHAMPARENA_LH.waves[number]) do
        for i = 1, amount do
            local cid = Game.createMonster(name, Position(arenaCenter.x + math.random(-arenaLength.x, arenaLength.x), arenaCenter.y + math.random(-arenaWidth.y, arenaWidth.y), arenaCenter.z), true, true)         
            if cid then
                cid:registerEvent("CHArenaDeath")
                cid:getPosition():sendMagicEffect(11)
            end
        end
    end
  
    Game.setStorageValue(_CHAMPARENA_LH.global_storage, number) 

    Game.setStorageValue(_CHAMPARENA_LH.global_aux, -1)
    addEvent(_CHAMPARENA_LH.prepareWave, _CHAMPARENA_LH.waveInterval * 60000, number + 1)
    return true
end
 
Lua:
_CHAMPARENA_LH = {
    monsterPos    = Position(130, 362, 7),
    arenaCenter    = Position(132, 362, 7),  
    arenaLength    = 2,                        
    arenaWidth    = 3            
}

function _CHAMPARENA_LH.sendWave(number)
    if Game.getStorageValue(_CHAMPARENA_LH.global_storage) < 0 then
        return false
    end
 
    for name, amount in pairs(_CHAMPARENA_LH.waves[number]) do
        for i = 1, amount do
            local cid = Game.createMonster(name, Position(arenaCenter.x + math.random(-arenaLength.x, arenaLength.x), arenaCenter.y + math.random(-arenaWidth.y, arenaWidth.y), arenaCenter.z), true, true)        
            if cid then
                cid:registerEvent("CHArenaDeath")
                cid:getPosition():sendMagicEffect(11)
            end
        end
    end
 
    Game.setStorageValue(_CHAMPARENA_LH.global_storage, number)

    Game.setStorageValue(_CHAMPARENA_LH.global_aux, -1)
    addEvent(_CHAMPARENA_LH.prepareWave, _CHAMPARENA_LH.waveInterval * 60000, number + 1)
    return true
end
1610489794394.png
 
post code data/lib/arena.lua

I looked at the zombie arena and managed to get the function they use, thank you very much
Lua:
function _CHAMPARENA_LH.getRandomSpawnPosition(fromPosition, toPosition)
    local random = math.random
    return Position(random(fromPosition.x, toPosition.x), random(fromPosition.y, toPosition.y), random(fromPosition.z, toPosition.z))
end
 
Solution
Back
Top