• 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 Summoning boss

marcos16

Falkhonn
Joined
May 4, 2012
Messages
224
Reaction score
1
Hello! I am using the following globalevents.
His duty is to summon a boss every x time, but he is with an error, he is summoning 4 boss.
I want you to try to summon only 1, and if that boss is already alive try another who is not and summon him ...
Thanks in advance.

Tfs 0.4.

Code:
function onThink(interval, lastExecution)

    local mName = 'none'
    local pos = {x=0,y=0,z=0}
    local dice = 1
    local thing = 0
    local certo = 1
    local try = 5
  
    while certo == 1 and try > 1 do
      
        try = try -1
      
        dice = math.random(4) 
      
        if dice == 1 then
            mName = 'morgaroth'
            pos = {x=980, y=866, z=12}
        elseif dice == 2 then
            mName = 'infernatil'
            pos = {x=955, y=369, z=8}
        elseif dice == 3 then
            mName = 'apocalypse'
            pos = {x=1651, y=615, z=12}
        elseif dice == 4 then
            mName = 'ferumbras'
            pos = {x=331, y=390, z=8}
        else
            mName = 'Bazir
            pos = {x=1387, y=1504, z=11}
        end
      
        thing = getCreatureByName(mName)
      
        if thing == nil then
            print('BOSS: '..mName)
            doSummonCreature(mName, pos)
            certo = 1
        else
            print('Already exist trying another')
        end
    end
  
    return TRUE
end
 
Code:
local function Position(x, y, z)
    return {x = x, y = y, z = z}
end

local t = {
    {name = 'Morgaroth', pos = Position(980, 866, 12)},
    {name = 'Infernatil', pos = Position(955, 369, 8)},
    {name = 'Apocalypse', pos = Position(1651, 615, 12)},
    {name = 'Ferumbras', pos = Position(331, 390, 8)},
}

function onThink(interval, lastExecution)
    local roll = math.random(5)
    local monster = t[roll]
    if not monster then
        doSummonCreature('Bazir', Position(1387, 1504, 11))
    else
        doSummonCreature(monster.name, monster.pos)
    end
    return true
end
 
Code:
local function Position(x, y, z)
    return {x = x, y = y, z = z}
end

local t = {
    {name = 'Morgaroth', pos = Position(980, 866, 12)},
    {name = 'Infernatil', pos = Position(955, 369, 8)},
    {name = 'Apocalypse', pos = Position(1651, 615, 12)},
    {name = 'Ferumbras', pos = Position(331, 390, 8)},
}

function onThink(interval, lastExecution)
    local roll = math.random(5)
    local monster = t[roll]
    if not monster then
        doSummonCreature('Bazir', Position(1387, 1504, 11))
    else
        doSummonCreature(monster.name, monster.pos)
    end
    return true
end
He's summoning the same thing over and over, I want him to check the monster, if he's not alive to summon ...
 
Code:
local t = {

    {name = 'Morgaroth', pos = {x = 900, y = 700, z = 7}},
    {name = 'Apocalypse', pos = {x = 900, y = 700, z = 7}},
    {name = 'Bazir', pos = {x = 900, y = 700, z = 7}},
    {name = 'Ungrez', pos = {x = 900, y = 700, z = 7}}
}

function onThink(interval, lastExecution)
    for i = 1,#t,1 do
        if not getCreatureByName(t[i].name) then
            doCreateMonster(t[i].name, t[i].pos)
            break
        end
    end
    return true
end
 
hard to understand what you want
are you wanting it to keep trying to summon something if it's not there?
If he is to try a monster he is alive he will try another, and he will not summon the same [that is alive]. So that there is more than 1 boss making it difficult to kill
 
First option, requires usage of global storages and creatureEvents. Adding new bosses will require modification of both file's config. If your bosses are inside room or closed arena, you should use 2nd option.
GlobalEvents:
Code:
local t = {
    {name = 'Morgaroth', pos = {x = 900, y = 700, z = 7}, storage = 123001},
    {name = 'Apocalypse', pos = {x = 900, y = 700, z = 7}, storage = 123002},
    {name = 'Bazir', pos = {x = 900, y = 700, z = 7}, storage = 123003},
    {name = 'Ungrez', pos = {x = 900, y = 700, z = 7}, storage = 123004}
}

function onThink(interval, lastExecution)
    local list = t
    for i = 1, #list do
        if getGlobalStorageValue(list[i].storage) == 1 then
            table.remove(list, i)
        end
    end
    if list ~= nil and #list > 0 then
        local rand = math.random(1, #list)
        local boss = doCreateMonster(t[rand].name, t[rand].pos)
        if isCreature(boss) == true then
            registerCreatureEvent(boss, "removeGlobalStorageWhenKilled")
            setGlobalStorageValue(t[rand].storage, 1)
        end
    end
    return true
end
CreatureEvents:
Code:
local t = {
    {name = 'Morgaroth', storage = 123001},
    {name = 'Apocalypse', storage = 123002},
    {name = 'Bazir', storage = 123003},
    {name = 'Ungrez', storage = 123004}
}

function onPrepareDeath(cid)
    local name = getCreatureName(cid)
    for i = 1, #t do
        if name == t[i].name then
            setGlobalStorageValue(t[i].storage, 0)
        end
    end
    return true
end


Second option, only one script but it have one cons. When someone pull boss far away, second the same boss may spawn.
Code:
local maxCheckRange = 20

local t = {
    {name = 'Morgaroth', pos = {x = 900, y = 700, z = 7}},
    {name = 'Apocalypse', pos = {x = 900, y = 700, z = 7}},
    {name = 'Bazir', pos = {x = 900, y = 700, z = 7}},
    {name = 'Ungrez', pos = {x = 900, y = 700, z = 7}}
}

function onThink(interval, lastExecution)
    local list = {}
    for i = 1, #t do
        local spec, check = getSpectators(t[i].pos, maxCheckRange, maxCheckRange), 0
        if spec ~= nil and #spec > 0 then
            for k = 1, #spec do
                if getCreatureName(spec[k]) == t[i].name then
                    check = 1
                    break
                end
            end
        end
        if check == 0 then
            table.insert(list, t[i])
        end
    end
    if list ~= nil and #list > 0 then
        local rand = math.random(1, #list)
        doCreateMonster(list[rand].name, list[rand].pos)
    end
    return true
end

As you see, those codes are light years more advanced then the ones someone posted above. They have to looks like this to work as you excepting.
 
Both Xeraphus' and Cade's scripts have issues in script logic. (unknown scriptfile)

nope
but you're still wrong about


those codes are light years more advanced then the ones someone posted above

pretty much they're giving a solution to solving a problem using a method they came up with. If they misinterpreted the problem, then that doesn't automatically mean that if someone elses interprets the problem correctly that it is necessarily more advanced. Also, I'd like to point out that when it comes to Lua scripting you don't have to care much about performance since it fulfills what it's supposed to do as far as you don't do something wrong.

If we have this equation as an example of what you're saying and put this into perspective:

x^2 + 2x = 1
since you know some math, you know that you can use the quadratic formula to solve any quadratic equation. You use it and get the roots;
x1 = -1 - sqrt(2)
x2 = sqrt(2) - 1

But there are other ways of looking at the problem, for example by simplifying it:
(x + 1)^2 - 2 = 0
and from here, using some basic math you can get the same roots.

Both Xeraphus' and Cade's scripts have issues in script logic. (unknown scriptfile)
you should yourself look over some logic in your own scripts
 
Last edited:
Both Xeraphus' and Cade's scripts have issues in script logic. (unknown scriptfile)

nope
i mean if we're judging here you make useless conditions in if statements in 99% of your scripts
of course mine had flaws because it's hard to tell from his broken english what he wants exactly
6SIOxwf.png
 
i mean if we're judging here you make useless conditions in if statements in 99% of your scripts
of course mine had flaws because it's hard to tell from his broken english what he wants exactly

There's really no matter what he wanted. Your script is like "lets write some text".
Code:
local t = {
    {name = 'Morgaroth', pos = Position(980, 866, 12)},
    {name = 'Infernatil', pos = Position(955, 369, 8)},
    {name = 'Apocalypse', pos = Position(1651, 615, 12)},
    {name = 'Ferumbras', pos = Position(331, 390, 8)},
}

[...]

    local monster = t[roll]
    if not monster then
This logic shows all. And my comment was to help him understand that code must have more advenced things and cant be short like yours.
I noticed he's a beginner in scripting and many ofter beginners wont 'install' hard scripts. You are very often tried to help here someone, but in most of cases you are left topic w/o solution or someone after you have to write proper fix. I really don't like you cuz you mostly spamming support/request topics with "maybe my tries will be successful" and you are hating ppl who are fixing your mistakes.
 
There's really no matter what he wanted. Your script is like "lets write some text".

This logic shows all. And my comment was to help him understand that code must have more advenced things and cant be short like yours.
I noticed he's a beginner in scripting and many ofter beginners wont 'install' hard scripts. You are very often tried to help here someone, but in most of cases you are left topic w/o solution or someone after you have to write proper fix. I really don't like you cuz you mostly spamming support/request topics with "maybe my tries will be successful" and you are hating ppl who are fixing your mistakes.
sure
 
edited my post @andu . Helping someone understand or learn to program have nothing to do with knowing how to do more advanced things. Your "additions" to their scripts was neither advanced nor complex. complexity and unecessarities are useless in programming and only display that you're a bad programmer.
 
So you realized you were wrong and decided to run away since you don't have any valid arguments to back up your bullshit
SeemsGood
Someone who will read this topic post by post will notice that you are a noob. And my valid argument is you are too dumb to notice own mistake and I'm dont have time and nerves to explain it to such poor person like you. This is valid argument.

Blocked, go back to school.
 
The script that I quoted in the first topic [my] is working, but is summoning more than 1 boss was to summon only 1. When there is already a live boss will not be born himself, will try another ... is trying 4 times and 4 attempts if not the living monster will summon the 4, being that I want only 1. I did not need this whole "trick". Sorry for my English, I'm Brazilian.
 
So you only want 1 boss to be alive at a time? If a boss is already summoned a different boss is not to be summoned. Is that correct?

In that case

Code:
local t = {

    {name = 'Morgaroth', pos = {x = 900, y = 700, z = 7}},
    {name = 'Apocalypse', pos = {x = 900, y = 700, z = 7}},
    {name = 'Bazir', pos = {x = 900, y = 700, z = 7}},
    {name = 'Ungrez', pos = {x = 900, y = 700, z = 7}}
}

function onThink(interval, lastExecution)
    for i = 1,#t do
        if getCreatureByName(t[i].name) then
            return false
        end
    end

    local rand = math.random(#t)
    doCreateMonster(t[rand].name, t[rand].pos)
    
    return true
end
 
Last edited:
Back
Top