• 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 Add new condition to the Event monster

Mariuskens

Sword Art Online 2D-MMORPG
Joined
Nov 21, 2008
Messages
1,000
Reaction score
106
Location
Spain
GitHub
Olimpotibia
I want to add Math.Random(1,1000) here:

local reSpawn = CreatureEvent("createBoss")

......................
local data = {
["rat"] = {spawnName = "cave rat"; --[[spawnPosition = Position(x, y, z)]]}
}

function reSpawn.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local event = data[creature:getName():lower()]
if event then
local monster = Game.createMonster(event.spawnName, event.spawnPosition ~= nil and event.spawnPosition or creature:getPosition(), true, true)
if monster then
monster:say(event.broadcast, TALKTYPE_MONSTER_SAY)
end
end
return true
end

reSpawn:register()

is just to add a chance for example you need kill 500 demons and can be appear one Orshabaal.

Thanks you in avance
 
Lua:
local config = {
                 ["Demon"] = { requiredKills = 500, spawnMonster = "Orshabaal", chance = 0.5 },    --- 0,5 = 50%
                 ["Rat"] = { requiredKills = 10, spawnMonster = "Cave Rat", chance = 100 },                
               }

if not config.monstersTable then      
   config.monstersTable = {}
end

local function getKills(name)
     
   if not config[name] then
      return false
   end
 
   if not config.monstersTable[name] then
      config.monstersTable[name] = 0
   end
 
   return config.monstersTable[name]
end

local function cleanKills(name)
 
   if not config.monstersTable then
      return
   end
 
   if not config.monstersTable[name] then
      return
   end
 
   config.monstersTable[name] = 0
end
 
local function spawnBoss(name, position)

   local t = config[name]
   if not t then
      return nil
   end
 
   local chance = t.chance
   if not chance then
      chance = 100
   end
   if chance < 1 then
      chance = chance * 100
   end
   local rand = math.random(0, 100)
   if rand <= chance then
      local bossName = t.spawnMonster
      local boss = Game.createMonster(bossName, position, true, true)
      if boss then
         boss:say("Boss has been spawned!")
         cleanKills(name)
      end
   end
end

local function addKill(creature)
 
   if not creature then
      return nil
   end
 
   local name = creature:getName()
   local position = creature:getPosition()
   local value = getKills(name)
   if not value then
      return
   end
   config.monstersTable[name] = value + 1
   value = getKills(name)
   local t = config[name]
   if not t then
      return
   end
   local requiredKills = t.requiredKills
   if value >= requiredKills then
      spawnBoss(name, position)
   end
end

local reSpawn = CreatureEvent("createBoss")
function reSpawn.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
   if not creature then
      return true
   end
 
   addKill(creature)
   return true
end
reSpawn:register()
 
Back
Top