ID:1906436
 
(See the best response by Ter13.)
Hey guys, I wanted to make a spawner that disappeared after it spawned its monsters. My programming is not the best, but here is my snippet of working code. I have had no problems with it, and I rather like the disappearing spawner instead of an area. And the monsters randomly appear in your general area.

To get rid of the tile on top, I used an area with the same icon underneath so the user never sees or suspects the traps coming.

turf
monsterspawn
icon = 'TUT.dmi'
icon_state= "Path1"
Entered(mob/M)
var/mob/P = new/mob/Enemy/BasicMob
P.loc=locate(M.x+rand(-3,3),M.y+rand(-1,1),M.z)
var/mob/R = new/mob/Enemy/BasicMob
R.loc=locate(M.x+rand(-3,3),M.y+rand(-1,1),M.z)

view(10) << "Monsters have appeared!"
del src


At least use <dm> tags. Gosh.

All this code does is create an enemy if you step on it. It's better to use area "states" to spawn enemies if you want to provide a better feel without static mobs. Though I don't think you want to delete the turf at the end.
My first forum post, Sorry about the DM tags.

And yes, it creates an enemy when stepped on, and deletes the spawning tile so that you cannot spawn more in the general area. Areas are more effective normally, but not for this purpose. At least in my opinion. And using an icon area tile underneath keeps the user from noticing the deletion.
No, it deletes the turf, so it can only spawn 1 mob... period. So it's rather useless long term. You'd want a spawner to have continued action. Plus if you wanted to control spawn numbers it's easy enough to do that without deleting the spawner.
You just said the same thing as me, it deletes the turf so only one spawn can occur. Which in my particular case is what I wanted XD.
Best response
This is a nice idea, but I think you'd do better with an object rather than a turf. For one, there's no need to use the area to hide the fact that the turf is disappearing. Two, there's no need to change turfs (which generates a bit more overhead than just destroying an object), and three, you don't have to make different trap pictures for different terrain. You can use whatever images you want and not have to worry about what's underneath.

obj
trap
proc
Trigger(mob/M)

Crossed(mob/M)
if(istype(M))
Trigger(M)

monsterspawn
var
spawn_type = /mob/Enemy/BasicMob
spawn_number = 1
spawn_range = 3

Trigger(mob/M)
var/list/turfs = block(locate(x-spawn_range,y-spawn_range,z),locate(x+spawn_range,y+spawn_range,z))
var/turf/t
var/mob/e
var/total = 0
for(var/count in 1 to spawn_number)
e = new spawn_type()
while(!e.loc&&turfs.len)
t = pick(turfs)
turfs -= t
e.Move(t,get_dir(t,M))
if(!(M in oview(e,spawn_range)))
e.loc = null
if(e.loc) total++
if(total==1)
range(10) << "A monster has appeared!"
else if(total)
range(10) << "Monsters have appeared"
else
M << "You have a bad feeling, but it suddenly passes."
loc = null


Also, I've genericized some of the behavior to make trap objects more flexible and extensible so you can make different types of traps but treat them all the same. Then I made locating the mobs a bit more complicated. It could do with some work, but what it's supposed to do is make sure that the monster doesn't wind up spawning behind a wall or something and can't see the player. Plus, it will attempt to follow movement rules for making certain that the mob doesn't spawn on something that it's not allowed to stand on, like another mob, the player, water, lava, etc.
Had not considered objects, that is a neat way to approach it. I will have to play with it some. I appreciate the feedback.
No problem.