ID:164028
 
I set up a code where the player kills a monster and after a while, it creates a new one (I used spawn and sleep). The reason I made this code to make it simpler but it seems not to work, here it is:
del src //This is part of the attack verb, not the whole thing
spawn(20)
new/mob/bug(src.loc) //Create a new bug in place of the dead one

Any reasons why it won't work?

PS, the reason I didn't use demos is because I want something simplier. ;)


What are you deleting? If src is the bug you're killing, it won't work because the bug doesn't exist when you tell a new bug to be at its location.
In response to Mecha Destroyer JD
Ah, I see. Is it possible to still create the mob (bug) at the position?
In response to DadGun
DadGun wrote:
Ah, I see. Is it possible to still create the mob (bug) at the position?

Yes, you could do it two ways:

1. Recommended if you make the bug while the game is running(as in the bug wasn't placed on the map in Dream Maker):

var/x2 = src.x
var/y2 = src.y
var/z2 = src.z
del(src) // the bug
spawn(20)
var/mob/bug/B=new //create a bug that you can call B
B.loc = locate(x2,y2,z2) // make B(bug) go to x2,y2,z2


2. Recommended if you put the bug on the map and might be placing other monsters on the map:

//this would respawn EVERYTHING in the world that was deleted
//example: if bug was on the map and was deleted(killed) then the proc would make a new one where it was; if it wasn't killed, nothing would happen

world.Repop() // run this whenever you need to respawn the whole world..wouldn't recommend to do jus for one monster
When an object is deleted, all procs which use the object as src are deleted. So the proc you're calling, which refers to your object as src, will stop running the moment it is deleted. (Actually that's more of what I hear than what I know, since I've never fiddled with it much.)

Based on that, there are several possible solutions:
mob/monster
Del()
// remember where the monster first started
var/turf/T = initial(src.loc)

// move it to null so it 'looks' like it was deleted
src.loc = null

sleep(20)
new src.type(T) // create a new monster

del(src) // NOW delete the old monster


// Since this proc doesn't belong to any objects, it won't
// stop running when an object gets deleted.
proc/SpawnMonster(mob/monster/what, turf/where, when=20)
sleep(when)
new what (where)

mob/monster
proc/Death()

// before deleting the old monster, spawn the proc
// that'll create the new monster.
// (make sure you spawn() so it won't wait until it
// finishes before deleting the old monster)
spawn()
SpawnMonster(src.type, initial(src.loc), 20)
del(src)
In response to Mecha Destroyer JD
I used it and got 1 error and 1 warning dealing with B.
B :warning: variable defined but not used
error:B.loc:undefined var

Any reasons why there is errors?
In response to DadGun
Fixed it. Works now.
In response to DadGun
I fixed it but now I got the same error and warning.
In response to Foomer
Thanks. Works now.