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

random 1++ spawn boss

Mauzim

Member
Joined
Jan 3, 2011
Messages
568
Reaction score
9
how to add to this script if win random 1-21 spawn then make random location of this mob like in 5 or 12
Code:
local mobs =
{
        -- 1
        [1] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [2] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [3] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [4] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        -- 2
        [5] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}, {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [6] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [7] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [8] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [9] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [10] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [11] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        -- 3
        [12] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}, {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},  {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [13] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [14] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [15] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        -- 4
        [16] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [17] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [18] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [19] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [20] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"},
        [21] = {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}
}

function onThink(interval, lastExecution, thinkInterval)
        spawn = mobs[math.random(21)]
        random = math.random(1000)
        if(random <= 50) then
                doSummonCreature(spawn.mob, {x=spawn.x, y=spawn.y, z=spawn.z})
        else
            return true
        end
end

any1 can help me?
 
Last edited by a moderator:
Code:
local mobs =
{
[1] = {{x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}},
[2] = {{x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}},
[3] = {{x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}, {x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}},
[4] = {{x = xxxx, y = xxxx, z = xx, mob="XXXXXX"}},
}

3 layers of table: A (main container), B (one container per entry in A), C (location points, one or more per B entry)

For each index to A, generate a random integer between 1 and the number of entries in its B, then pull the location point (C) with that index into B.

The general rule: when you want a variable number of entries, use a container. The second or third time you use stacked containers, read the language docs to find the any assists for processing containers (e.g. it's in "Programming in LUA")
 
Put some real values into the table example I provided above, write code as described, and it will work ok.


Your earlier table structure is wrong. You need another level, like this:
PHP:
{
      {  {}  },
      {  {}, {}, {}  },
      {  {}  }
      {  {}, {}  },
      {  {}  }
}
The text I wrote about containers explains the general "data structure design" principle. You need a container layer for every level that allows multiple instances (two container layers in this case). Then you can use container level operations to loop through the instances.
 
can you explain me it?:x im blind about tables please post some finished code i need 1 random value in this globalevent and then example 3 monsters [bug], [minotaur], [orc] then after random globalevent random is 1 from 3 then every mosnter have {x/y/z}, {x/y/z}, and it doesnt matter 1 or 5 random position but creature spawn only in 1
 
Here's a simple Lua program that demonstrates what I explained. I don't think it's exactly what you want, but if you understand the principles the rest is easy.

Notes:
  • This is made to run outside OT. I don't know what happens when you use Lua "print()" in OT, but apart from hat the code will run ok if you put it into an OT script.
  • There's 10% of seeing creature "D"each cycle. 30 cycles should deliver 3 on average, but now and again it will be 0.
  • When I tested it I noticed the sequence of random numbers is the same each time I ran the code. I only just learned Lua, don't know how to deal with the RNG yet, and don't feel like checking it out.
  • The Lua operator #tableName returns the number of elements in the table, but only if it has integer index values. It corks on the outer table (mobs) and the next one in (e.g. #mobs[3] is 2) but it won't work on the inner arrays, because they are indexed by "x", "y", "z", and "mob". #mobs[3][2] returns 0.

PHP:
local mobs =
{
[1] = {{x = 1, y = 2, z = 3, mob="A"}},
[2] = {{x = 4, y = 5, z = 6, mob="B"}},
[3] = {{x = 7, y = 8, z = 9, mob="C"}, {x = 10, y = 11, z = 12, mob="D"}},
[4] = {{x = 13, y = 14, z = 15, mob="E"}},
}

for i= 1, 30 do  -- make 30 selections so we expect to get creature D in one of them

  mobLength = #mobs

  groupIndex = math.random(1, mobLength)  -- select one of the containers of monsters

  creatureIndex = 1
  groupLength = #mobs[groupIndex]

  if groupLength > 1 then
       creatureIndex = math.random(1, groupLength) -- if there are several monsters in the container, select one at random
  end

  creature = mobs[groupIndex][creatureIndex]
  creatureToString = "{" .. creature["x"] .. ", " .. creature["y"] .. ", " .. creature["z"] .. ", " .. creature["mob"] .. "}"

  print ( "cycle " .. i .. ", Creature selected: " .. creatureToString )

end

BTW: The redundant lines like " mobLength = #mobs" are there because the "#" screws up the php formatting tag.
 
Last edited:
Back
Top