• 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
 
Sorry, I missed some commas
You need to do this:
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
but with this addition
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
You're 1 line of code in creaturescripts.xml would be
XML:
    <event type="death" name="hunterdeath" script="FILENAME.lua" />
so long as you put
XML:
         <script>
        <event name="hunterdeath"/>
    </script>
in your hunter.xml and hunter1.xml etc
 
Sorry, I missed some commas
You need to do this:

but with this addition

You're 1 line of code in creaturescripts.xml would be
XML:
    <event type="death" name="hunterdeath" script="FILENAME.lua" />
so long as you put
XML:
         <script>
        <event name="hunterdeath"/>
    </script>
in your hunter.xml and hunter1.xml etc
5kZCUf.png



Code:
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

function onStartup()
    for i, pos in ipairs(hunterpos) do
        hunters[i] = spawnhunter(pos)
    end
end


and hunter don't die look to this
SSzQEtZ.png
 
Sorry I don't know why I keep forgetting things,
you also need
Lua:
hunterpos = {
    {x=1000,y=1000,z=7},
    {x=1005,y=1005,z=7}
}
with all the positions where you want hunters to spawn
 
yes and remove them from yourmap_spawns.xml
EDIT: if its a lot of work test it out with a couple of spawns first to see if it works as intended
 
lol sorry, put
Lua:
return true
before last
Lua:
end
in your creaturescripts lua

I.E. like this:
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
return true
end
 
lol sorry, put
Lua:
return true
before last
Lua:
end
in your creaturescripts lua

I.E. like this:
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
return true
end
when hunter die don't spawn again :S
 
Ok, after testing it myself I discovered many mistakes but I got it working for me on TFS 1.2
globalevents lua
Lua:
hunterpos = {
    {x=1011,y=1005,z=6},
    {x=1013,y=1005,z=6}
}
hunterconfig = {
    respawntime = 10*1000,
    chance2 = 25,
    chance3 = 10,
    chance4 = 5,
    monster1 = 'Hunter1',
    monster2 = 'Hunter2',
    monster3 = 'Hunter3',
    monster4 = 'Hunter4'
}
hunters = {}
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 onStartup()
    for i, pos in ipairs(hunterpos) do
        hunters[i] = spawnhunter(pos)
    end
end
creaturescripts lua
Lua:
dofile('data/globalevents/scripts/hunters.lua')
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for i, hunterid in pairs(hunters) do
        if cid.uid == hunterid then
            addEvent(function()
                hunters[i] = spawnhunter(hunterpos[i])
            end,hunterconfig.respawntime)
        end
    end
    return true
end
Don't forget to change the config
 
Ok, after testing it myself I discovered many mistakes but I got it working for me on TFS 1.2
globalevents lua
Lua:
hunterpos = {
    {x=1011,y=1005,z=6},
    {x=1013,y=1005,z=6}
}
hunterconfig = {
    respawntime = 10*1000,
    chance2 = 25,
    chance3 = 10,
    chance4 = 5,
    monster1 = 'Hunter1',
    monster2 = 'Hunter2',
    monster3 = 'Hunter3',
    monster4 = 'Hunter4'
}
hunters = {}
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 onStartup()
    for i, pos in ipairs(hunterpos) do
        hunters[i] = spawnhunter(pos)
    end
end
creaturescripts lua
Lua:
dofile('data/globalevents/scripts/hunters.lua')
function onDeath(cid, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for i, hunterid in pairs(hunters) do
        if cid.uid == hunterid then
            addEvent(function()
                hunters[i] = spawnhunter(hunterpos[i])
            end,hunterconfig.respawntime)
        end
    end
    return true
end
Don't forget to change the config
not work when die hunter don't spawn again :S im use tfs 0.4
 
I can't think of any reason why it would work for me but not work for you
make sure everything is correct
and that you have
XML:
      <script>
        <event name="hunterdeath"/>
    </script>
after
XML:
<monster name="Hunter" nameDescription="a hunter" race="blood" experience="150" speed="195" manacost="530">
and in creaturescripts.xml
XML:
    <event type="death" name="hunterdeath" script="hunterdeath.lua" />
 
I can't think of any reason why it would work for me but not work for you
make sure everything is correct
and that you have
XML:
      <script>
        <event name="hunterdeath"/>
    </script>
after
XML:
<monster name="Hunter" nameDescription="a hunter" race="blood" experience="150" speed="195" manacost="530">
and in creaturescripts.xml
XML:
    <event type="death" name="hunterdeath" script="hunterdeath.lua" />
idk not work :S

bump
 
Last edited by a moderator:
Still wondering why don't you try yourself instead of copy pasting things from people who spend time to fix that stuff for you..
I gave him a script that works and he's still not happy
EDIT: on that note, does 0.4 have onDeath?
 
Let me be clear, it is important that you specified hunters spawn locations in
Lua:
hunterpos = {
    {x=1011,y=1005,z=6},
    {x=1013,y=1005,z=6}
}
and killed a hunter that was spawned from those locations
If you cast '/m hunter' and kill it IT WILL NOT RESPAWN

I found another solution for you, delete everything else and in creaturescripts.xml put
XML:
    <event type="spawn" name="hunterspawn" script="hunterdeath.lua" />
    <event type="death" name="hunterdeath" script="hunterdeath.lua" />
and in hunterdeath.lua
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
            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
and make sure you have
XML:
     <script>
        <event name="hunterdeath"/>
    </script>
in all your hunters
I can't test this because 1.2 doesn't have onSpawn for some reason, but this way means you don't have to put all hunter spawns manually in hunterpos (it will use hunters spawned on map)
 
Last edited by a moderator:
I found another solution for you, delete everything else and in creaturescripts.xml put
XML:
    <event type="spawn" name="hunterspawn" script="hunterdeath.lua" />
    <event type="death" name="hunterdeath" script="hunterdeath.lua" />
and in hunterdeath.lua
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
            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
and make sure you have
XML:
     <script>
        <event name="hunterdeath"/>
    </script>
in all your hunters
I can't test this because 1.2 doesn't have onSpawn for some reason, but this way means you don't have to put all hunter spawns manually in hunterpos (it will use hunters spawned on map)
PHgm1MV.png


Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Hunter" nameDescription="a hunter" race="blood" experience="150" speed="210" manacost="530">
    <health now="150" max="150"/>
    <look type="129" head="95" body="116" legs="121" feet="115" corpse="6080"/>
    <targetchange interval="5000" chance="8"/>
    <strategy attack="100" defense="0"/>
    <flags>
        <flag summonable="0"/>
        <flag attackable="1"/>
        <flag hostile="1"/>
        <flag illusionable="1"/>
        <flag convinceable="1"/>
        <flag pushable="0"/>
        <flag canpushitems="1"/>
        <flag canpushcreatures="0"/>
        <flag targetdistance="4"/>
        <flag staticattack="90"/>
        <flag runonhealth="10"/>
    </flags>
   
    <attacks>
        <attack name="melee" interval="2000" skill="10" attack="20"/>
        <attack name="physical" interval="2000" chance="40" range="7" min="-0" max="-100">
            <attribute key="shootEffect" value="arrow"/>
        </attack>
    </attacks>
    <defenses armor="8" defense="10"/>
    <elements>
        <element holyPercent="20"/>
        <element physicalPercent="-5"/>
    </elements>
    <voices interval="5000" chance="10">
        <voice sentence="Guess who we're hunting, haha!"/>
        <voice sentence="Guess who we are hunting!"/>
        <voice sentence="Bullseye!"/>
        <voice sentence="You'll make a nice trophy!"/>
    </voices>
    <loot>
    <item id="2544" countmax="22" chance="29125" /><!-- arrow -->
    <item id="2456" chance="31625" /><!-- bow -->
    <item id="2649" chance="15800" /><!-- leather legs -->
    <item id="2675" countmax="2" chance="15875" /><!-- orange -->
    <item id="5875" chance="1025" /><!-- sniper gloves -->
    <item id="2460" chance="5600" /><!-- brass helmet -->
    <item id="7394" chance="600" /><!-- wolf trophy -->
    <item id="2461" chance="10000" /><!-- leather helmet -->
    <item id="2690" countmax="2" chance="9000" /><!-- roll -->
    <item id="1987" chance="100000"><!-- bag -->
        <inside>
            <item id="2201" chance="3375" /><!-- dragon necklace -->
            <item id="2546" countmax="3" chance="3425" /><!-- burst arrow -->
            <item id="2465" chance="6350" /><!-- brass armor -->
            <item id="2050" chance="5400" /><!-- torch -->
            <item id="2545" countmax="4" chance="2975" /><!-- poison arrow -->
            <item id="2147" chance="650" /><!-- small ruby -->
            <item id="7400" chance="700" /><!-- lion trophy -->
        </inside>
    </item>
</loot>






    <script>
        <event name="hunterdeath"/>
    </script>












</monster>

f5
 
Last edited by a moderator:
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" />
 
Back
Top