I was working on my AI and wanted to have an area for the NPCs to stay in and that area would also control when the NPCs AI would get turned on and off (referencing Lummox's topic in his Green Programming). But i have it where there is one big area with smaller NPC areas in it and was wondering how to seperate the areas cause right now they are all treated as one area. Heres a pic to show what i mean.
the blue areas are both NPC areas and are the same code. What I would like is to be able to have those treated as different areas without having to code them all in, because right now they are treated as the same.
ID:159973
Dec 10 2008, 8:12 am
|
|
Areas are not like other atoms; they're not a simple existence in the sense that they encompass a single tile. A single area encompasses multiple tiles, possibly the whole map. When you lay an area type through the Map Editor, you're only ever laying a single area instance of that type - even if you lay them in separate places that aren't connected. Generally this is considerably convenient and saves on resources by not creating new areas that are not needed. So this is why your areas are treated the same - it's not areas, it's really an area.
To lay separate area instances through the Map Editor, you indeed have to use multiple types, each different type amounting to a single instance. The other way to create a separate area instance is at runtime, by calling new /area(null) (or leaving the parentheses empty), but this isn't what you want of course. (Note the above is all documented in the DM Reference under the entry for 'area'.) |
In response to Kaioken
|
|
Ok I new all that and new that all areas (as in the spots on the map not the area atom) with the same atom/area are treated as the same area.
So then ill ask a different question which this one was actually for. How would you start and stop AI so that its not constantly running and saves on resources |
In the map editor, right-click the area in the Object box and select New Instance. Then give that instance a unique tag. Now it'll treat that instance as a separate area from any other instances of that type with different tags. When you click an instance in the Object box, it'll display the tag along with the type below the box, so you can easily see which areas are which before laying them down.
|
In response to NightJumper88
|
|
Basically put, you'll look up and use the areas' Entered() and Exited() procs. When a player leaves an area, if there are no more players there, you could turn AI there off (this could be accomplished by having your AI loop check the area's activity var, or have a separate one of its own if wanted). When a player enters an area, if it is currently sleeping, then activate the AI there.
|
In response to Xooxer
|
|
Thank you that works exactly how i want it to now.
|
In response to Xooxer
|
|
That's good thinking and experimenting there. I've found you don't actually have to set the tag, any variable should work, as to just separate the instance, so it's enough if you set eg the name, as you probably want to. The downside is that your instances could be lost if you meddle with your map or create a new one, though.
|
In response to Xooxer
|
|
Wow, that's an excellent idea. I was always under the assumption that the only way to separate areas was to use separate type paths!
|
In response to Kaioken
|
|
Um, it was no experiment. And the reason you'd want to set the tag over any other variable is because it is shown in the map editor. That way, you can't lose track of your instances. But then again, I said all that in the post you just replied to....
|
In response to Xooxer
|
|
Sure, but I always thought the name is also displayed in the map editor, and more conveniently at that. But then again... :P
|
In response to Kaioken
|
|
You know, I'm not sure setting the name would make it unique. The tag works because anything with a unique tag can be located()ed. Areas follow that rule too, but I don't know if just changing any var would give you a truly unique area. It probably does, but still might be something to test.
|
In response to Xooxer
|
|
Yeah, I tested it after learning this from you, it works, and looks like every variable would. That makes it quite useful, but I may end up filling my code file instead anyway. >,>
|
As you can see, you wouldn't program much, but the mapping would be a little tougher.