• 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 Respawn - more than one place.

Apoccalypse

New Member
Joined
Apr 15, 2017
Messages
114
Solutions
2
Reaction score
4
Hi quys,
I have the following script:

LUA:
local config = {
    bosspos = {x = 246, y = 969, z = 4},
    bossspawnstorage = 70400
}
local monster = {'Ferumbras'}


local function respawn()
    doCreateMonster('Ferumbras', config.bosspos)
    doBroadcastMessage('There are rumors that Ferumbras walks around his chamber...', 21)
    setGlobalStorageValue(config.bossspawnstorage, 0)
end
function onKill(cid, target, damage, flags)
local minspawn = 86400  --1d
local maxspawn = 259200 -- 3d
local random = math.random(minspawn, maxspawn)

    if isMonster(target) then
        local targetName = getCreatureName(target)
        local playerName = getCreatureName(cid)
        if isInArray(monster, targetName) and getGlobalStorageValue(config.bossspawnstorage) ~= 1 then
            local message = ("%s has just killed the evil mage %s. Congratulation!"):format(playerName, targetName)
            doBroadcastMessage(message, 21)
            setGlobalStorageValue(config.bossspawnstorage, 1)
            addEvent(respawn, random * 1000)
        end
    end
    return true
end

It works great for me but I am just wondering is it possible to make the boss to respawn at one of three declared places.Let's call them:
local pos1 ={x=x1 ,y=y1 ,z=z1}
local pos2 ={x=x2 ,y=y2 ,z=z2}
local pos3 ={x=x3 ,y=y3 ,z=z3}
The final result which I want to receive is that the boss would have the chance 33.33% to respawn at one of these places.

I tried to do something like this:

LUA:
local config = {
   
    bossspawnstorage = 70401
}

local monster = {'Evil Mastermind'}


local function respawn() 
local   bosspos1 = {x = 435, y = 505, z = 7}
local    bosspos2 = {x = 437, y = 499, z = 7}
local    bosspos3 = {x = 442, y = 506, z = 7}
local   Posrandom = random(bosspos1, bosspos2, bosspos3)

    doCreateMonster('Evil Mastermind', Posrandom)
    doBroadcastMessage('There are rumors that Evil Mastermind walks around his chamber...', 21)
    setGlobalStorageValue(config.bossspawnstorage, 0)
end

function onKill(cid, target, damage, flags)
local minspawn = 1  --1d
local maxspawn = 5 -- 3d
local random = math.random(minspawn, maxspawn)


    if isMonster(target) then
        local targetName = getCreatureName(target)
        local playerName = getCreatureName(cid)
        if isInArray(monster, targetName) and getGlobalStorageValue(config.bossspawnstorage) ~= 1 then
            local message = ("%s has just killed the evil mage %s. Congratulation!"):format(playerName, targetName)
            doBroadcastMessage(message, 21)
            setGlobalStorageValue(bossspawnstorage, 1)
            addEvent(respawn, random * 1000)
        end
    end
    return true
end

But I get this error:

Code:
[19:44:19.182] [Error - CreatureScript Interface]
[19:44:19.182] In a timer event called from:
[19:44:19.182] data/creaturescripts/scripts/RespawnEvilMastermind.lua:onKill
[19:44:19.182] Description:
[19:44:19.182] ...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:13: attempt to call global 'random' (a nil value)
[19:44:19.182] stack traceback:
[19:44:19.182]  ...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:13: in function <...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:9>

If anyone would help that would be great :)
 
Solution
LUA:
local config = {

    bossspawnstorage = 70401
}

    local t = {
 
   {x = 435, y = 505, z = 7},
   {x = 437, y = 499, z = 7},
   {x = 442, y = 506, z = 7}}

local monster = {'Evil Mastermind'}


local function respawn()
local   Posrandom = random(t)

    doCreateMonster('Evil Mastermind', Posrandom)
    doBroadcastMessage('There are rumors that Evil Mastermind walks around his chamber...', 21)
    setGlobalStorageValue(config.bossspawnstorage, 0)
end
function onKill(cid, target, damage, flags)
local minspawn = 1  --1d
local maxspawn = 5 -- 3d
local random = math.random(minspawn, maxspawn)


    if isMonster(target) then
        local targetName = getCreatureName(target)
        local playerName = getCreatureName(cid)...
try something like this for your positions
Code:
local t = {
   {x = 100, y = 100, z = 7},
   {x = 100, y = 100, z = 7},
   {x = 100, y = 100, z = 7}
}
 
Last edited:
LUA:
local config = {

    bossspawnstorage = 70401
}

    local t = {
   
   {x = 435, y = 505, z = 7},
   {x = 437, y = 499, z = 7},
   {x = 442, y = 506, z = 7}}

local monster = {'Evil Mastermind'}


local function respawn()
local   Posrandom = random(t)

    doCreateMonster('Evil Mastermind', Posrandom)
    doBroadcastMessage('There are rumors that Evil Mastermind walks around his chamber...', 21)
    setGlobalStorageValue(config.bossspawnstorage, 0)
end
function onKill(cid, target, damage, flags)
local minspawn = 1  --1d
local maxspawn = 5 -- 3d
local random = math.random(minspawn, maxspawn)


    if isMonster(target) then
        local targetName = getCreatureName(target)
        local playerName = getCreatureName(cid)
        if isInArray(monster, targetName) and getGlobalStorageValue(config.bossspawnstorage) ~= 1 then
            local message = ("%s has just killed the evil mage %s. Congratulation!"):format(playerName, targetName)
            doBroadcastMessage(message, 21)
            setGlobalStorageValue(bossspawnstorage, 1)
            addEvent(respawn, random * 1000)
        end
    end
    return true
end

Code:
[20:23:12.700] [Error - CreatureScript Interface]
[20:23:12.700] In a timer event called from:
[20:23:12.700] data/creaturescripts/scripts/RespawnEvilMastermind.lua:onKill
[20:23:12.700] Description:
[20:23:12.700] ...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:17: attempt to call global 'random' (a nil value)
[20:23:12.716] stack traceback:
[20:23:12.716]  ...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:17: in function <...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:16>

The same as before.
 
LUA:
local config = {

    bossspawnstorage = 70401
}

    local t = {
 
   {x = 435, y = 505, z = 7},
   {x = 437, y = 499, z = 7},
   {x = 442, y = 506, z = 7}}

local monster = {'Evil Mastermind'}


local function respawn()
local   Posrandom = random(t)

    doCreateMonster('Evil Mastermind', Posrandom)
    doBroadcastMessage('There are rumors that Evil Mastermind walks around his chamber...', 21)
    setGlobalStorageValue(config.bossspawnstorage, 0)
end
function onKill(cid, target, damage, flags)
local minspawn = 1  --1d
local maxspawn = 5 -- 3d
local random = math.random(minspawn, maxspawn)


    if isMonster(target) then
        local targetName = getCreatureName(target)
        local playerName = getCreatureName(cid)
        if isInArray(monster, targetName) and getGlobalStorageValue(config.bossspawnstorage) ~= 1 then
            local message = ("%s has just killed the evil mage %s. Congratulation!"):format(playerName, targetName)
            doBroadcastMessage(message, 21)
            setGlobalStorageValue(bossspawnstorage, 1)
            addEvent(respawn, random * 1000)
        end
    end
    return true
end

Code:
[20:23:12.700] [Error - CreatureScript Interface]
[20:23:12.700] In a timer event called from:
[20:23:12.700] data/creaturescripts/scripts/RespawnEvilMastermind.lua:onKill
[20:23:12.700] Description:
[20:23:12.700] ...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:17: attempt to call global 'random' (a nil value)
[20:23:12.716] stack traceback:
[20:23:12.716]  ...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:17: in function <...ta/creaturescripts/scripts/RespawnEvilMastermind.lua:16>

The same as before.
It's 'math.random', not just 'random'.

LUA:
local Posrandom = t[math.random(#t)]
 
Solution
Back
Top