• 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 Summon Monsters Amount tables, 1.0

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,286
Location
Sweden?
Hello,

i just wonder how can i add that when it summon the monster from table, it will also summon the amount it get from that monster row table.

Code:
local monsters = {
    ["Rat"] = {level = 3, amount = 2},
    ["Cave Rat"] = {level = 5, amount = 4}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local mons = {}
    for a, b in pairs (monsters) do
              if getPlayerLevel(cid) >= b.level then
                table.insert(mons, a)
              end
          end
    doSummonCreature(mons[math.random(#mons)], toPosition)
    doCreatureSay(cid, "Watch out!", TALKTYPE_ORANGE_1)
    doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
    return true
end

Thanks.
 
for i = 1, mons[rand].amount do
-- summon creature
end

This give me a nil value error :/
Code:
local monsters = {
    ["Rat"] = {level = 3, amount = 2},
    ["Cave Rat"] = {level = 5, amount = 4}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local mons = {}
    for a, b in pairs (monsters) do
            if getPlayerLevel(cid) >= b.level then
                    table.insert(mons, a)
                  end
    end
    local rand = mons[math.random(#mons)]
    for i = 1, mons[rand].amount do
            doSummonCreature(rand, toPosition)
    end
        doCreatureSay(cid, "Watch out!", TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
    return true
end
 
use
Code:
getClosestFreeTile(cid, targetpos[, extended = false[, ignoreHouse = true]])
as pos or write it urself using this:
Code:
function isPathable(pos)
if queryTileAddThing(getThingfromPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).uid, {x = pos.x, y = pos.y, z = pos.z}) == RETURNVALUE_NOERROR then
return true
else
return false
end
end
 
Ive fixed the rand part:
Code:
local monsters = {
    ["Rat"] = {level = 3, amount = 2},
    ["Cave Rat"] = {level = 5, amount = 4}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local mons = {}
        for a, b in pairs (monsters) do
                if getPlayerLevel(cid) >= b.level then
                        table.insert(mons, a)
                end
        end
        local rand = math.random(#mons)
        for i = 1, mons[rand].amount do
                doSummonCreature(rand, toPosition)
        end
        doCreatureSay(cid, "Watch out!", TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
        return true
end

Now the error is at line 14:
Code:
'for' limit must be a number
 
Code:
for i = 1, #monsters do
if getPlayerLevel(cid) >= monsters[i].level then
for a = 1, monsters[i].amount do
doSummonCreature(monsters[i].name, toPosition)
end
end
end
 
there you go.
Code:
local monsters
{
   {level = x, name = "rat", ammount = x},
   {level = x, name = "cave rat", ammount = x}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pick = {}
   for i = 1, #monsters do
     if getPlayerLevel(cid) >= monsters[i].level then
       table.insert(pick, i)
     end
   end
   if pick[1] ~= nil then
     local rnd = 1
     if #pick > 1 then
       local rnd = math.random(1,#pick)
     end
     for i = 1, monsters[pick[rnd]].ammount do
       doSummonCreature(monsters[pick[rnd]].name, toPosition)
     end
     doCreatureSay(cid, "Watch out!", TALKTYPE_ORANGE_1)
  doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
   else
     doPlayerSendCancel(cid, "Your level is to low."
   end
   return true
end
 
Last edited:
Back
Top