• 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
 
This is probably not the correct way to achieve what you want, instead make a globalevent:
XML:
    <globalevent type="startup" name="hunters" script="hunters.lua" />

Lua:
local config = {
    chance = 40,  
    monster = 'Hunter'
    boss = 'Hunter2'
}
local hunterpos = {
{x=1000,y=1000,z=7},
{x=1005,y=1005,z=7}
}
function onStartup()
    for i, pos in ipairs(hunterpos) do
        if math.random(1, 100) <= config.chance then
            doCreateMonster(monster, pos)
        else
           doCreateMonster(boss, pos)
        end
    end
end
this will spawn monsters for you at startup, then ideally you want a creaturescript that will make them respawn later on with onDeath and addEvent
 
i
This is probably not the correct way to achieve what you want, instead make a globalevent:
XML:
    <globalevent type="startup" name="hunters" script="hunters.lua" />

Lua:
local config = {
    chance = 40, 
    monster = 'Hunter'
    boss = 'Hunter2'
}
local hunterpos = {
{x=1000,y=1000,z=7},
{x=1005,y=1005,z=7}
}
function onStartup()
    for i, pos in ipairs(hunterpos) do
        if math.random(1, 100) <= config.chance then
            doCreateMonster(monster, pos)
        else
           doCreateMonster(boss, pos)
        end
    end
end
this will spawn monsters for you at startup, then ideally you want a creaturescript that will make them respawn later on with onDeath and addEvent


i must add all hunter pos in map??
 
In fact he doesn't even need to do this, all he really needs is the creaturescript, I will do it in a minute
EDIT: actually yes he does, since there no other way I can think of to avoid double spawning..
 
You need a creaturescript, put
XML:
      <script>
        <event name="hunterspawn"/>
    </script>
in hunter.xml and hunter2.xml
then
XML:
    <event type="death" name="hunterspawn" script="hunterspawn.lua" />
in creaturescripts.xml
then in hunterspawn.lua
Lua:
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
local config = {
    respawntime = 2*60*1000
    chance = 40,
    monster = 'Hunter'
    boss = 'Hunter2'
}
    addEvent(function()
        if math.random(1, 100) <= config.chance then
            doCreateMonster(monster, getCreaturePosition(cid))
        else
           doCreateMonster(boss, getCreaturePosition(cid))
        end
    end,respawntime)
end

But I warn you, this will make a monster spawn in the location the one previous was slain, NOT the original spawn location, this makes it open for some big abuse.
EDIT: I am currently working up a fix

Ok, in globalevents put a script
Lua:
hunterpos = {
    {x=1000,y=1000,z=7},
    {x=1005,y=1005,z=7}
}
hunterconfig = {
    respawntime = 2*60*1000
    chance = 40,
    monster = 'Hunter'
    boss = 'Hunter2'
}
hunters = {}
function spawnhunter(pos)
        if math.random(1, 100) <= hunterconfig.chance then
            doCreateMonster(hunterconfig.monster, pos)
        else
           doCreateMonster(hunterconfig.boss, pos)
        end
end
function onStartup()
    for i, pos in ipairs(hunterpos) do
        hunters[i] = spawnhunter(pos)
    end
end
then in creaturescripts put a file
Lua:
dofile('data/globalevents/scripts/FILENAME.lua')
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for i, hunterid in pairs(hunters) do
        if cid == hunterid then
            addEvent(function()
                hunterspawn(hunterpos[i])
            end,hunterconfig.respawntime)
        end
    end
end
This is the best I could do, I hope it works for you
 
Last edited by a moderator:
thx man real thx to try help me but i need when hunter spawn choose between normal hunter or hunter boss {hunter2} if chance 40% spawn hunter boss because i use monster lvl
normal hunter will be like this {hunter {lv.15} } hunter white skull will be hunter{lv.16} red skull will be Hunter {lv.20} black skull will be hunter {lv.25}

i need when hunter come to spawn choose between 4 hunters with chance
 
You really need to improve your English
1nf6g4.jpg

I can't even get started if I don't know what you want to happen
EDIT:
explain in your native tongue, maybe google translate can save us
EDIT:
unless your native tongue is English then we're screwed
 
Last edited:
You really need to improve your English
1nf6g4.jpg

I can't even get started if I don't know what you want to happen
EDIT:
explain in your native tongue, maybe google translate can save us
EDIT:
unless your native tongue is English then we're screwed
That meme deserves a like xD
 
You really need to improve your English
1nf6g4.jpg

I can't even get started if I don't know what you want to happen
EDIT:
explain in your native tongue, maybe google translate can save us
EDIT:
unless your native tongue is English then we're screwed
hhaahhaha i know my english is so baaaaaad but lets try it

nromal spawn is hunter i need when hunter come to spawn choose between hunter and hunter1 and hunter 2 and hunter 3 soemthing like this

local t = {'hunter','hunter1','hunter2','hunter3'}
doCreateMonster(t[math.random(#t)], pos)
 
So I think I understand what you're getting at:
if the player in the zone is under level 15, you want only hunters to spawn
if he is greater than 15 then hunter1 can spawn too,
if he is greater than 16 then hunter2 can spawn,
if he is greater than 20 then hunter2 can spawn,
and if he is greater than 25 then hunter4 can spawn
is that right?
 
hhaahhaha i know my english is so baaaaaad but lets try it

nromal spawn is hunter i need when hunter come to spawn choose between hunter and hunter1 and hunter 2 and hunter 3 soemthing like this

local t = {'hunter','hunter1','hunter2','hunter3'}
doCreateMonster(t[math.random(#t)], pos)
Have you tried to fix the script above on your own befor requesting and asking other people to do the work for you?

Update:
So I think I understand what you're getting at:
if the player in the zone is under level 15, you want only hunters to spawn
if he is greater than 15 then hunter1 can spawn too,
if he is greater than 16 then hunter2 can spawn,
if he is greater than 20 then hunter2 can spawn,
and if he is greater than 25 then hunter4 can spawn
is that right?

Actually he wants a rand. spawn of hunter1 to hunter4 (as higher the number at last, as more rare the creature is) something like, hunter1 drops shit and hunter4 some epic shit .. (I expect thats his idea)
 
Have you tried to fix the script above on your own befor requesting and asking other people to do the work for you?
yes i did

i tried something like this

Code:
local config = {
    chance = 40,                  
    bosses = {
        ["Hunter"] = "",
    },
}
local t = {'hunter','hunter2','hunter3','hunter4'}
function onSpawn(cid)
    if isMonster(cid) then
        addEvent(function()
            if isCreature(cid) then
                local boss = t[getCreatureName(cid)]
                if boss and math.random(1, 100) <= config.chance then
                    local pos = getThingPos(cid)
                    doRemoveCreature(cid)
                    doCreateMonster(t[math.random(#t)], pos)
                end
            end
        end, 5)
    end
    return true
end


and work but have one thing bad if hunter2 spawned after 60 sec will try to spawn again till spawn normal hunter and stop {normal hunter that monster i add from map editor}

Have you tried to fix the script above on your own befor requesting and asking other people to do the work for you?

Update:


Actually he wants a rand. spawn of hunter1 to hunter4 (as higher the number at last, as more rare the creature is) something like, hunter1 drops shit and hunter4 some epic shit .. (I expect thats his idea)
yes like u said
 
Last edited by a moderator:
Actually he wants a rand. spawn of hunter1 to hunter4 (as higher the number at last, as more rare the creature is) something like, hunter1 drops shit and hunter4 some epic shit .. (I expect thats his idea)
Well that's exactly what I told him to do should achieve
EDIT:
well ok theres a little more, one sec
EDIT:
change your shit to this:
Lua:
hunterconfig = {
    respawntime = 2*60*1000
    chance2 = 25,
    chance3 = 10,
    chance4 = 5,
    monster1 = 'Hunter',
    monster2 = 'Hunter2',
    monster3 = 'Hunter3',
    monster4 = 'Hunter4'
}
hunters = {}
function spawnhunter(pos)
    local chance = math.random(1, 100)
        if chance <= hunterconfig.chance4 then
            doCreateMonster(hunterconfig.monster4, pos)
        elseif chance <= hunterconfig.chance3 then
            doCreateMonster(hunterconfig.monster3, pos)
        elseif chance <= hunterconfig.chance2 then
            doCreateMonster(hunterconfig.monster2, pos)
        else
            doCreateMonster(hunterconfig.monster1, pos)
        end
end
 
Last edited:
Well that's exactly what I told him to do should achieve
EDIT:
well ok theres a little more, one sec
EDIT:
change your shit to this:
Lua:
hunterconfig = {
    respawntime = 2*60*1000
    chance2 = 25,
    chance3 = 10,
    chance4 = 5,
    monster1 = 'Hunter'
    monster2 = 'Hunter2'
    monster3 = 'Hunter3'
    monster4 = 'Hunter4'
}
hunters = {}
function spawnhunter(pos)
    local chance = math.random(1, 100)
        if chance <= hunterconfig.chance4 then
            doCreateMonster(hunterconfig.monster4, pos)
        elseif chance <= hunterconfig.chance3 then
            doCreateMonster(hunterconfig.monster3, pos)
        elseif chance <= hunterconfig.chance2 then
            doCreateMonster(hunterconfig.monster2, pos)
        else
            doCreateMonster(hunterconfig.monster1, pos)
        end
end
EVbGzjC.png




edite

i fixed it but now said event spawn not found what event i must wrrite in creatureevent.xml
 
Back
Top