I am making a respawn proc, and right now i have 2 options, which one should i do? (and if possible, can you give me part of the code to do it?)
Option 1:
When a thing dies, it gets moved to a random place in a special z plane, then after x seconds it returns to it's origanal place with it's hp restored.
Option 2:
Thing is killed, and it's x y and z points are saved into variables. After x seconds, a new monster is made at that point.
ID:158987
Jun 1 2009, 1:16 pm
|
|
Jun 1 2009, 1:41 pm
|
|
I'd say that option 1 seems to be the better option in terms of efficiency. This way would avoid the resources it takes to reallocate the same data over and over. Just be sure to refill their HP and remove status effects, upon respawn. Also, when they're dead you'll want to turn off their AI. Dead things don't need to think!
|
In response to Vermolius
|
|
Thank you very much.
|
Neos300 wrote:
When a thing dies, it gets moved to a random place in a special z plane You shouldn't bother with that; a both better and easier approach is to just move the mob off the map (also known by various names such as The Void, Blackness, or Black Screen). This is done by setting a movable's loc to null. Though doing it more robustly would look more like this: atom/movable/proc/Move_off_map() (That would make sure that when a movable is relocated to null, if it's on a location with Exited() overrides, those are processed instead of ignored, which could've led to issues in such cases) Also, Option 2™ is really not necessarily the worse method. Recreating the mob has advantages, like:
And, maybe more, but I don't feel like pondering at the moment. Seemingly, a discussion like this belongs at Design Philosophy, as that's what it pretty much is. |
In response to Kaioken
|
|
Kaioken wrote:
You shouldn't bother with that; a both better and easier approach is to just move the mob off the map (also known by various names such as The Void, Blackness, or Black Screen). This is done by setting a movable's loc to null. Right, I failed to mention something about his special z-level. Also, you have to realize that by sending a mob to null you also have a chance of deleting it accidentally, since you're removing a reference to the mob. If somehow by sending it to the void removes the last reference the garbage collector will gobble it up. Also, Option 2™ is really not necessarily the worse method. Recreating the mob has advantages, like:
|
In response to Vermolius
|
|
Vermolius wrote:
Also, you have to realize that by sending a mob to null you also have a chance of deleting it accidentally, since you're removing a reference to the mob. I've already realized, but you have to realize that if you have code spawned to relocate the mob, it of course has a reference to that mob, which will prevent it from being deleted. ;P you'll have to worry about null references if you manage to delete a mob that is still in use. [...] Yes, that's how it is in DM programming, and it doesn't really change considerably by whether you delete defeated mobs or not. Whenever there's possibility of an object you're using having been deleted (or even modified, in some potential cases), you need to (or should) re-validate in any case. Which is where you'd check if the mob has a location, amongst your homing attacks and any other such procs, and cancel out if they don't. Sure, but that's unimportant, that was just a particular example. :P You could come up with hundreds. |