ID:160269
 
All I need is a coder who can do this:
make all npcs respawn where they started when they revive.

If someone could give me a code for that, that would be great.
This isn't a code requests forum. If you want someone to program for you, look for a dedicated programmer in Classified Ads.
I get the feeling this isn't a "if somebody could give me the code for it that would be great" kind of forum. We prefer people be actively learning to be better coders themselves.

It's sort of the "Give the man a fish, and he'll eat for a day. Teach a man to fish and he'll eat for the rest of his life" sort of thing.

Anywho, to answer your question, it's somewhat more complicated action than anyone could any one bit of code for because we don't know enough about your particular game's code. However, it goes something like this:

First, you'd have to take into consideration what happens to NPCs when they die. If they get deleted, you've essentially a situation where you have to store externally (probably in a global variable) what NPCs were deleted and where they started. If you don't delete your NPCs after they're killed, the job is a bit easier, you just switch them back to their default state after awhile.

Second, you'd have to store where they started on each NPC. That, at least, is fairly easy to do. Just create a /turf variable on the NPC and when the New() proc for that NPC is called the variable's value is assigned.
In response to Geldonyetich
If he placed them on the map, a simple world.Repop() would do the trick.
In response to Geldonyetich
For the deletion part, it is not really necessary to keep track of what NPC is deleted through a simple trick: if you overwrite Del() with no parent procedure, the object (mind you that object does not refer to /obj) remains. So if the NPC is del'd, Del() can be overwritten to take it to THE VOID (z=0), wait for a while, and relocate it back with the health stored.

As for relocating back to the turf: if they were placed on the map (.dmm/.dmp), then you can return them back through initial(NPC.loc), which is the location they were originally placed at. However, if that NPC was spawned, then they will remain in THE VOID (as initial(src.loc) = null) until the GARBAGE COLLECTOR comes by... hm, the GARBAGE COLLECTOR reminds me of the cleaning thing in Bleach when they tried going to heaven o.O
In response to GhostAnime
GhostAnime wrote:
For the deletion part, it is not really necessary to keep track of what NPC is deleted through a simple trick: if you overwrite Del() with no parent procedure, the object (mind you that object does not refer to /obj) remains. So if the NPC is del'd, Del() can be overwritten to take it to THE VOID (z=0), wait for a while, and relocate it back with the health stored.

Good thinking about overriding the Del() to handle the NPC respawning behavior. I could make it even easier than moving them to THE VOID and back:

Just set the NPC to invisiblity 101, opaque 0, density 0, mouse_opacity 0 and make sure any processes that run their behavior are terminated. Then, they're still there but essentially not an active piece in the game - you can even keep them visible but replace their icon with a corpse if you prefer. At the appropriate time, they move back to their start point, reset all their variables to the appropriate amount (including starting location, invisibility, opacity, and density) and restart their AI process: voila respawned. Write a global proc that does all this and you'll have it done in one line.
In response to Geldonyetich
Geldonyetich wrote:
Good thinking about overriding the Del() to handle the NPC respawning behavior.

It's actually not very effective or robust. Such a thing is better simply left for your Death() proc (or DeathCheck() if you don't have one) - what if the NPC is supposed to be deleted? etc.

I could make it even easier than moving them to THE VOID and back:
Just set the NPC to invisiblity 101, opaque 0, density 0, mouse_opacity 0 and make sure any processes that run their behavior are terminated.

Gee, that's so much easier than setting a single variable. =P It's also less robust, since as long as the NPC is on the map it is still highly interact-able by common code.
In response to Kaioken
I suppose, when it comes right down to it, we're arguing coding philosophy at this point.

The tricky thing about overriding Del is (last I checked) BYOND doesn't allow arguments to be passed to Del (). So you couldn't pass an argument to decide whether or not the mob really does respawn. You'd have to handle that through a variable, and that's just extra memory being spent. A custom death proc probably would prove more flexible.
Whatever happened to the world.Repop() proc or something? Whenever it was ran, anything that doesn't exist on the map compared to the .dmm file, it would be created/re-created. And of course it would be looped.
Easy enough to do. I'm not a "give you the code" kinda guy, but here are the pieces you'll need.

This will allow you to place your NPCs on the map in the map editor. When the game boots up, their spawn location is stored automatically:

<code> mob/npc var/turf/start_turf New() ..() spawn() src.start_turf = src.loc </code>

Easy enough. So when they die, let's not delete them. Instead, here is how you get rid of them:

<code> src.invisibility = 101 src.density = 0 src.hit_points = 0 //Or whatever you use to track HP. </code>

If you have any Artificial Intelligence loops running, shut them down automatically by adding something like this in the loop:

<code> if(!src.hit_points) return </code>

Now let's put them on a timer to respawn. At the end of whatever Death procs you have, put something like this:

<code> spawn(respawn_time) src.loc = src.start_turf //Warp the NPC back to where they started src.invisibility = 0 src.density = 1 src.hit_points = src.max_hit_points //Reset the HP to max! src.AI() //restart the AI loop. </code>


The NPC lives again!