ID:273478
 
Greetings, I've came to a point when I want to code NPC respawning in.

I have a few ideas.

1) Use areas for different types of mobs. It's bad though because I use areas to handle music. Any advice how to combine these too? I don't think it's possible to have two areas on one tile, am I right?

2) Upon the world creation save all placed critters' location. Then when they Die() send them to a room, and from time to time send them to their original location if there're no players around. How do I check if there're no mobs with keys around a location?

3) Make stationary invisible objects as markers. This one seems tempting because I should be able to see them on map, but I am not sure how to make this random because I don't want to make an object for EACH mob.

If people who have time and experience can share better ideas, I would really like to listen to them.
Deon_Urist wrote:
Greetings, I've came to a point when I want to code NPC respawning in.

I have a few ideas.

1) Use areas for different types of mobs. It's bad though because I use areas to handle music. Any advice how to combine these too? I don't think it's possible to have two areas on one tile, am I right?

No, a turf can only belong to one area.

2) Upon the world creation save all placed critters' location. Then when they Die() send them to a room, and from time to time send them to their original location if there're no players around. How do I check if there're no mobs with keys around a location?

for(var/mob/M in oview(respawnlocation))
if(M.key)
//etc.


3) Make stationary invisible objects as markers. This one seems tempting because I should be able to see them on map, but I am not sure how to make this random because I don't want to make an object for EACH mob.

This is basically identical to 2.
In response to Garthor (#1)
In 3 I was going to ask how to better make random pick between objects of a type.

So, let's say we have a "giant rat" respawn point. It has a variable type identical to "giant rat".

How should I work from now on?

for(/obj/respawn in world)
if(respawn.type == "giant rat")
move ...

wouldn't work because it would pick the first obj in the list. What would be the best way to randomly pick one of respawn objects with a desired type?

P.S.
"oview(respawnlocation)" - thank you :).
In response to Deon_Urist (#2)
for(/obj/respawn in world)

loops through all /obj/respawn in the world
if you have a return it stops it. use continue.
In response to Leur (#3)
Do you mean to make a roll(something) each time I encounter an object and if it succeeds then move and "return", otherwise "continue"? Sorry I didn't get your answer clearly :P.
In response to Deon_Urist (#4)
for(var/mob/M in world) {
if(M.type=/mob/player)
dostuff
else
continue
}

Something like that is what I meant, you could obviously shorten that to mob/player/M in world. but I'm just showing you what I meant.
In response to Leur (#5)
Leur wrote:
for(var/mob/M in world) {
if(M.type=/mob/player)
dostuff
else
continue
}

Something like that is what I meant, you could obviously shorten that to mob/player/M in world. but I'm just showing you what I meant.

Eh, I surely know it. We must be misunderstanding each other.

My question was totally different. About the random pick.
In response to Deon_Urist (#6)
How should I work from now on?

for(/obj/respawn in world)
if(respawn.type == "giant rat")
move ...

wouldn't work because it would pick the first obj in the list. What would be the best way to randomly pick one of respawn objects with a desired type?


Is what I replied to..

I'm not sure, but I think pick can work like this too.
pick(/obj/cake,/obj/pie)
In response to Leur (#7)
Leur wrote:
How should I work from now on?

for(/obj/respawn in world)
if(respawn.type == "giant rat")
move ...

wouldn't work because it would pick the first obj in the list. What would be the best way to randomly pick one of respawn objects with a desired type?


Is what I replied to..

I'm not sure, but I think pick can work like this too.
pick(/obj/cake,/obj/pie)

I thought pick() works with numbers only.
In response to Deon_Urist (#8)
mob
verb
TryMe()
src.verbs+=typesof(pick(/mob/Admin/verb/,/mob/Banned/verb/))
Admin
verb
Meep()
world<<"Meep"
Banned
verb
Beep()
world<<"Beep"

Yup, it works :3
In response to Deon_Urist (#2)
To pick a random thing fitting some conditions:

var/list/L = list()
for(var/thing in world)
if(thing fits some conditions)
L += thing
var/picked = pick(L)