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

onspawn

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
im use this script its work fine but have one problem when boss spawn and after time spawn normal monster spawn again in same spot anyone can fix it if boss spawn normal monster don't spawn again??

the problem in example
if hunter2 spawned after 60 sec {time to spawn in map} normal hunter spawn again

tfs 0.4

Code:
local config = {
    chance = 40,                   
    bosses = {
        ["Hunter"] = "Hunter2",
    },
}
function onSpawn(cid)
    if isMonster(cid) then
        addEvent(function()
            if isCreature(cid) then
                local boss = config.bosses[getCreatureName(cid)]
                if boss and math.random(1, 100) <= config.chance then
                    local pos = getThingPos(cid)
                    doRemoveCreature(cid)
                    doCreateMonster(boss, pos)
                end
            end
        end, 5)
    end
    return true
end
 
Add also this to globalevents:
Code:
<globalevent name="monsters" type="startup" event="script" value="monsters.lua"/>
monsters.lua
Lua:
function onStartup()
   for _, monster in ipairs(checkSpawnMonster()) do
       if isMonster(monster) and getCreatureStorage(monster, 110) ~= 1 then
           doCreatureSetStorage(monster, 110, 1)
           registerCreatureEvent(monster, "hunterdeath")
       end
   end
   return true
end
and rest should work, let me know if smth is poping in console after killing
not work event don't spawn hunter at startup
 
I don't have time to figure out a solution to the OP but I can provide an explanation of why this will never work in lua without the addition of a function to handle such cases.

When a monster spawns in the map it cannot respawn until it is killed (or removed).
When you use onSpawn (or onDeath for that matter) to remove the creature and place a new creature, the original creature is technically "killed".
This means the next spawn interval will think the monster no longer exists and respawn said monster.

The easiest solution (an lua solution) is to do what people here have already said. Preset certain locations in a table and math.random for boss instead of normal monster.

If you want a proper solution which allows dynamic spawning of bosses rather than monsters onSpawn then I think the easiest way would most likely be a function similar to doTransformItem but rather doTransformMonster?
This would need to transform the monsters type into a new one whilst retaining its uid.
 
add this to globalevents:
Code:
<globalevent name="check" interval="1000" event="script" value="checkm.lua"/>
Code:
function onThink(interval, lastExecution, thinkInterval)
   for _, monster in ipairs(checkSpawnMonster()) do
       print("".. getCreatureName(monster) .." exist on map")
       break
   end
   return true
end
tell me what printing in console
 
Back
Top