ID:152013
 
Whats the best method for respawning NPCs in an open-worldish game. I dont want NPCs magicaly coming back to life while youre in the middle of a mission, but i also dont want other players attempting the missions to be walking into rooms of corpses. And since its an open-world type game players will be able to cross paths so i cant really force respawn after mission completions, since there may be multiple players in the same area even if they may not be on the same exact mission

The game will be Hitman style where you have to stealth assassinate a certain target somewhere. But it will be in a city, instead of in preset mission areas. The city will function more in a GTA style with free roaming. A full day/night cycle and pathed NPCs that you have to track to find the best time to kill em! or just run up and shootem in the face, whatever u feel like doin <.<<br/>
anyway need ideas for how/when/where to best respawn the NPCs
You've got conflicting goals here. If you want missions to not be trivialized by other players having already finished them, then you should use LummoxJR's SwapMaps or a similar library to load instances of an area for each mission. If you want players to run into each other on missions (which is silly), then you are going to have to accept that things will be dead. My suggestion would be to give each mission an /area, and bring everything back to life on /area/Exited(), like so:

area/mission
var/clients = 0
Entered(var/mob/M)
if(M.client) clients++
..()
Exited(var/mob/M)
if(M.client)
clients--
if(clients == 0)
for(var/mob/M in src)
M.revive()

mob/proc/revive()
//so that it only affects mobs that were placed via the map editor:
if(initial(loc))
loc = initial(loc)
if(dead)
//assuming the AI proc stops when they're dead, rather than just sleeping
spawn() AI()
hp = initial(hp)
//anything else that might be needed, initial() will be useful here


Keep in mind that you can break things by moving players out in nonstandard ways. This means deleting and altering loc directly. You'll need to remember to call Entered() and Exited() as appropriate in those cases.
In response to Garthor (#1)
Garthor wrote:
>   if(initial(loc))
> loc = initial(loc)


Bad useless-double-proc-call-with-no-reason! Bad! =P
var/init_loc = initial(loc)
if(init_loc) loc = init_loc


Indeed, you must have just accidentally missed this. But still, bad!
In response to Kaioken (#2)
I feel that's slightly less clear. The point of the initial(loc) line is that it will be null if the mob was not placed using the map editor, and so it makes a reasonable "should this mob respawn?" check. An extra call to initial() isn't going to kill somebody.
In response to Garthor (#3)
Garthor wrote:
An extra call to initial() isn't going to kill somebody.

Shhhh. =P You can be wrong sometimes too, y'know. Just like every other human.