• 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
 
u missed end at function ondeath add it after return true to be like this

return true
end
 
Last edited:
try this instead
Lua:
hunterconfig = {
    respawntime = 10*1000,-- MAKE SAME AS SPAWN TIME ON MAP
    chance2 = 50,
    chance3 = 25,
    chance4 = 5,
    monster1 = 'Hunter1',
    monster2 = 'Hunter2',
    monster3 = 'Hunter3',
    monster4 = 'Hunter4'
}
hunters = {}
hunterpos = {}
function spawnhunter(pos)
    local chance = math.random(1, 100)
        if chance <= hunterconfig.chance4 then
            hunter = doCreateMonster(hunterconfig.monster4, pos)
        elseif chance <= hunterconfig.chance3 then
            hunter = doCreateMonster(hunterconfig.monster3, pos)
        elseif chance <= hunterconfig.chance2 then
            hunter = doCreateMonster(hunterconfig.monster2, pos)
        else
            hunter = doCreateMonster(hunterconfig.monster1, pos)
        end
        return hunter
end
function onSpawn(cid)
    for i=1,#hunters do
        if not hunters[i] then
            registerCreatureEvent(cid,'hunterdeath')
            hunters[i] = cid
            hunterpos[i] = getCreaturePosition(cid)
            return true
        end
    end
end
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for i, hunterid in pairs(hunters) do
        if cid == hunterid then
            addEvent(function()
                doRemoveCreature(hunters[i])
                hunters[i] = spawnhunter(hunterpos[i])
            end,hunterconfig.respawntime)
        end
    end
    return true
end
remove these
XML:
    <script>
        <event name="hunterdeath"/>
    </script>
and make sure you got this in creaturescripts.xml
XML:
<event type="spawn" name="hunterspawn" script="hunterdeath.lua" />
<event type="death" name="hunterdeath" script="hunterdeath.lua" />
no work :S i add every thing and still no work idk :S
 
It's not impossible, I did it for you, but either your distro doesn't support it (which it should) or you are too stupid to implement it
 
function onSpawn() exist in TFS?! I didnt hear about it... Told you to use my 1st script which i gave you in yours other(?) topic.
 
It's not impossible, I did it for you, but either your distro doesn't support it (which it should) or you are too stupid to implement it
man i implement it your script don't work




function onSpawn() exist in TFS?! I didnt hear about it... Told you to use my 1st script which i gave you in yours other(?) topic.

i need to random spawn will help me alote and i use this function
Feature - [CreatureEvent] OnSpawn(cid)
 
Try this one:
Lua:
    hunterconfig = {
       respawntime = 10, -- respawn in seconds
       chances = {50, 25, 5},
       monsters = {"Hunter1", "Hunter2", "Hunter3", "Hunter4"}
   }
   function spawnHunter(pos)
       addEvent(function()
           local chance = math.random(1, 100)
           if chance <= hunterconfig.chances[3] then
               hunter = doCreateMonster(hunterconfig.monsters[4], pos)
           elseif chance <= hunterconfig.chances[2] then
               hunter = doCreateMonster(hunterconfig.monsters[3], pos)
           elseif chance <= hunterconfig.chances[1] then
               hunter = doCreateMonster(hunterconfig.monsters[2], pos)
           else
               hunter = doCreateMonster(hunterconfig.monsters[1], pos)
           end
           return hunter
       end, hunterconfig.respawntime * 1000)
   end
   
   function onSpawn(cid)
       if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
            registerCreatureEvent(cid, "hunterdeath")
            return true
        end
    end
   
   function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
       if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
           spawnHunter(getCreaturePosition(cid))
           doRemoveCreature(cid)
           return false
        end
       return true
   end
 
Try this one:
Lua:
    hunterconfig = {
       respawntime = 10, -- respawn in seconds
       chances = {50, 25, 5},
       monsters = {"Hunter1", "Hunter2", "Hunter3", "Hunter4"}
   }
   function spawnHunter(pos)
       addEvent(function()
           local chance = math.random(1, 100)
           if chance <= hunterconfig.chances[3] then
               hunter = doCreateMonster(hunterconfig.monsters[4], pos)
           elseif chance <= hunterconfig.chances[2] then
               hunter = doCreateMonster(hunterconfig.monsters[3], pos)
           elseif chance <= hunterconfig.chances[1] then
               hunter = doCreateMonster(hunterconfig.monsters[2], pos)
           else
               hunter = doCreateMonster(hunterconfig.monsters[1], pos)
           end
           return hunter
       end, hunterconfig.respawntime * 1000)
   end
  
   function onSpawn(cid)
       if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
            registerCreatureEvent(cid, "hunterdeath")
            return true
        end
    end
  
   function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
       if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
           spawnHunter(getCreaturePosition(cid))
           doRemoveCreature(cid)
           return false
        end
       return true
   end
nothing happen :S no error always spawn normal hunter
 
nothing happen :S no error always spawn normal hunter
how many times did you even try?
normal hunter spawns at 50% rate
it's like saying if i roll a dice once and it lands on 3, that it always lands on 3
Lua:
local hunterconfig = {
    respawntime = 10, -- respawn in seconds
    chances = {50, 25, 5},
    monsters = {"Hunter1", "Hunter2", "Hunter3", "Hunter4"}
}


local function spawnHunter(pos)
    local chance = math.random(100)
    local index = #hunterconfig.monsters
    for i = 1, #chances do
        if chance <= hunterconfig.chances[i] then
            return doCreateMonster(hunterconfig.monsters[index])
        end
        index = index - 1
    end
end
   
function onSpawn(cid)
    if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
        registerCreatureEvent(cid, "hunterdeath")
        return true
    end
end
   
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
        addEvent(spawnHunter, hunterconfig.respawntime * 1000, getCreaturePosition(cid))
        doRemoveCreature(cid)
        return false
    end
    return true
end
 
how many times did you even try?
normal hunter spawns at 50% rate
it's like saying if i roll a dice once and it lands on 3, that it always lands on 3
Lua:
local hunterconfig = {
    respawntime = 10, -- respawn in seconds
    chances = {50, 25, 5},
    monsters = {"Hunter1", "Hunter2", "Hunter3", "Hunter4"}
}


local function spawnHunter(pos)
    local chance = math.random(100)
    local index = #hunterconfig.monsters
    for i = 1, #chances do
        if chance <= hunterconfig.chances[i] then
            return doCreateMonster(hunterconfig.monsters[index])
        end
        index = index - 1
    end
end
 
function onSpawn(cid)
    if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
        registerCreatureEvent(cid, "hunterdeath")
        return true
    end
end
 
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if isInArray(getCreatureName(cid), hunterconfig.monsters) and isMonster(cid) then
        addEvent(spawnHunter, hunterconfig.respawntime * 1000, getCreaturePosition(cid))
        doRemoveCreature(cid)
        return false
    end
    return true
end
i up chance to 80.6045 and nothing happen kill hunter like 20-25 time :S

Edit

i killed it 200 time and no thing
 
Last edited:
Creaturescript:

Lua:
local monsters = {
[1] = "Hunter",
[2] = "Hunter1",
[3] = "Hunter2",
[4] = "Hunter3",
[5] = "Hunter4"
}

local spawn_time = 30 -- Time in seconds to respawn a new one.
local spawn_pos = {x = 1000, y = 1000, z = 7}

function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        for i = 1, #monsters do
            if getCreatureName(target) == monsters[i] then
                isHunter = true
                break
            end
        end
     
        if isHunter then
            addEvent(spawnNew, spawn_time * 1000)
        end
end
return true
end

function spawnNew()
    new_hunter = math.random(1, 5)
    doCreateMonster(monsters[new_hunter], spawn_pos)
end

Add the onKill in your creaturescripts.xml and register the event in login.lua

Then GlobalEvent

Lua:
local spawn_pos = {x = 1000, y = 1000, z = 7}
function onStartup()
doCreateMonster("Hunter", spawn_pos)
end

Add onStartup in the globalevents.xml

Remove the hunter spawn from your map.
 
Last edited:
Creaturescript:

Lua:
local monsters = {
[1] = "Hunter",
[2] = "Hunter1",
[3] = "Hunter2",
[4] = "Hunter3",
[5] = "Hunter4"
}

local spawn_time = 30 -- Time in seconds to respawn a new one.
local spawn_pos = {x = 1000, y = 1000, z = 7}

function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        for i = 1, #monsters do
            if getCreatureName(target) == monsters[i] then
                isHunter = true
                break
            end
        end
     
        if isHunter then
            addEvent(spawnNew, spawn_time * 1000)
        end
end
return true
end

function spawnNew()
    new_hunter = math.random(1, 5)
    doCreateMonster(monsters[new_hunter], spawn_pos)
end

Add the onKill in your creaturescripts.xml and register the event in login.lua

Then GlobalEvent

Lua:
local monsters = {
[1] = "Hunter",
[2] = "Hunter1",
[3] = "Hunter2",
[4] = "Hunter3",
[5] = "Hunter4"
}
local spawn_pos = {x = 1000, y = 1000, z = 7}
function onStartup()
doCreateMonster("Hunter", spawn_pos)
end

Add onStartup in the globalevents.xml

Remove the hunter spawn from your map.
when die don't spawn again :S and always when close server and open again spawn hunter not random
 
try this and after kill put here that what will be printed in the console
Code:
local monsters = {
[1] = "Hunter",
[2] = "Hunter1",
[3] = "Hunter2",
[4] = "Hunter3",
[5] = "Hunter4"
}
local spawn_time = 30 -- Time in seconds to respawn a new one.
local spawn_pos = {x = 1000, y = 1000, z = 7}
function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        for i = 1, #monsters do
            if getCreatureName(target) == monsters[i] then
                isHunter = true
               print("Hunter detected and killed.")
                break
           else
               print("".. getCreatureName(target) .." killed - its not a Hunter.")
            end
        end
    
        if isHunter then
           print("Spawning new Hunter within ".. spawn_time .." seconds.")
            addEvent(spawnNew, spawn_time * 1000)
        end
end
return true
end
function spawnNew()
    new_hunter = math.random(1, 5)
   print("".. new_hunter .." has been spawn.")
    doCreateMonster(monsters[new_hunter], spawn_pos)
end
 
try this and after kill put here that what will be printed in the console
Code:
local monsters = {
[1] = "Hunter",
[2] = "Hunter1",
[3] = "Hunter2",
[4] = "Hunter3",
[5] = "Hunter4"
}
local spawn_time = 30 -- Time in seconds to respawn a new one.
local spawn_pos = {x = 1000, y = 1000, z = 7}
function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        for i = 1, #monsters do
            if getCreatureName(target) == monsters[i] then
                isHunter = true
               print("Hunter detected and killed.")
                break
           else
               print("".. getCreatureName(target) .." killed - its not a Hunter.")
            end
        end
  
        if isHunter then
           print("Spawning new Hunter within ".. spawn_time .." seconds.")
            addEvent(spawnNew, spawn_time * 1000)
        end
end
return true
end
function spawnNew()
    new_hunter = math.random(1, 5)
   print("".. new_hunter .." has been spawn.")
    doCreateMonster(monsters[new_hunter], spawn_pos)
end


no thing happen when server start spawn hunter and when kill no spawn again

Code:
local monsters = {
[1] = "Hunter",
[2] = "Hunter2",
[3] = "Rat",
[4] = "Wolf",
[5] = "Cat"
}
local spawn_time = 30 -- Time in seconds to respawn a new one.
local spawn_pos = {x = 1101, y = 1202, z = 7}
function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        for i = 1, #monsters do
            if getCreatureName(target) == monsters[i] then
                isHunter = true
               print("Hunter detected and killed.")
                break
           else
               print("".. getCreatureName(target) .." killed - its not a Hunter.")
            end
        end
 
        if isHunter then
           print("Spawning new Hunter within ".. spawn_time .." seconds.")
            addEvent(spawnNew, spawn_time * 1000)
        end
end
return true
end
function spawnNew()
    new_hunter = math.random(1, 5)
   print("".. new_hunter .." has been spawn.")
    doCreateMonster(monsters[new_hunter], spawn_pos)
end


creature xml

<event type="Kill" name="hunterdeath" script="filename.lua"/>

and othere script in globalevents
 
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
 
Back
Top