I want to create a system which will respawn monsters after a certain time (or amount) when some monsters are killed in a level (or area)
what is the best way to set this up?
It needs to be in a way so that is not directly exploitable, say for instance ... kill a monster, respawn, kill, respawn... to farm exp
But adds to the dynamics and atmosphere of the level.. in other words I don't want the level to be empty / dead when all monsters are killen
(I use this level as a connection between levels and the party will have to travel through it often)
Any tips on how to set this up ?
Brainstorm help (monster spawn)
- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Brainstorm help (monster spawn)
I use this in my project:
Every 10 seconds, if inside the current level, if the party is at least <distance> tiles away (euclidian), if it has not already spawned <number> entities (still "alive"), this object will spawn a new <entity>.
Also, I don't really get how you will make a respawn system useless for experience farming, unless you spawn monsters granting 0 exp of course.
SpoilerShow
Code: Select all
defineObject{
name = "spawner_script",
components = {
{
class = "Timer",
timerInterval = 10,
triggerOnStart = false,
currentLevelOnly = true,
onActivate = function(self)
local ent,dis = self.go.data:get("entity"),self.go.data:get("distance") or 6
if ent then
if party.level == self.go.level then
local dx, dy, dz = party.x-self.go.x, party.y-self.go.y, party.elevation-self.go.elevation
if dx*dx + dy*dy + dz*dz < dis*dis then return end
end
local num,old,new = self.go.data:get("number") or 3,self.go.data:get("children") or {}, {}
for _,id in ipairs(old) do if findEntity(id) then new[#new+1] = id end end
if #new<num then
local e = self.go:spawn(ent)
if e.monstergroup then
e.monstergroup:spawnNow()
for m in self.go.map:entitiesAt(self.go.x, self.go.y) do
if m.elevation == self.go.elevation and m.monster then
new[#new+1] = m.id
end
end
else
new[#new+1] = e.id
end
end
self.go.data:set("children", new)
end
end,
},
{
class = "Script",
name = "data",
source = [[
data = {entity="green_slime",number=3,distance=6}
function get(self,name) return self.data[name] end
function set(self,name,value) self.data[name] = value end
]],
},
},
placement = "floor",
tags = { "scripting" },
editorIcon = 80,
}Also, I don't really get how you will make a respawn system useless for experience farming, unless you spawn monsters granting 0 exp of course.
Re: Brainstorm help (monster spawn)
Marvelous !!!
This was what I was looking for , many thanks
This was what I was looking for , many thanks
- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Brainstorm help (monster spawn)
Note that this object works to spawn monsters groups too... But in this case, each individual monster counts as one entity when checking if the object should continue spawning.
Also, you can spawn non monsters objects with it, like periodic (and limited in number) fireballs to set up a trap for example.
Also, you can spawn non monsters objects with it, like periodic (and limited in number) fireballs to set up a trap for example.