I’m using the following script to clean up bodybags in an area. However instead of all the bodybags in the whole area, I just want to use the same script inside a trigger. There will actually be multiple triggers in the same area each with the script, so I probably need something to work inside the closest trigger each script is running?
Maybe I should use GetFirstObjectInShape() and GetNextObjectInShape() instead? All my triggers are square. This script actually runs from objects that are inside each trigger, so where would the objects need to be placed for everything to line up?
I’m trying to grasp what you are intending to do here. You have this script on objects within each trigger? What do you need the trigger for then? Where on the objects is this script placed? I mean, how is the script activated?
When do you want the “BodyBag” to be cleaned? I’m sorry, but I’m quite confused by this, but I’ll try to help if I can.
So, the way I had it set up with areas was like this. When a player exits the area, an object would spawn. That object had this script run from that objects heartbeat. There are a few other things that get cleaned up along with the bodybags, but they all function the same, so posting those would be redundant. Once the heartbeat reaches 0, the object would destroy itself as well. Basically the whole area would be clean with nothing in it.
Now, I’m wanting to do the same thing but within triggers instead of the whole area at once. I’m trying to make areas that are 32x32 instead of 8x8 like in the past. So, I have this huge 32x32 area with 16 triggers inside it in a grid. So, it’s like having 16 8x8 areas all placed within one large area. If that makes sense? So, instead of cleaning up the whole area when a player exits… I’m wanting these individual triggers to clean up when players exit them instead.
The GetFirstObjectInArea(oArea) will only get objects in the actual Area, not a trigger or the calling object (if not an area). However, if you are dividing the area up into regular square shapes, you know what area it covers by X and Y. So you can maybe get if the object is inside the area of the trigger.
caveate - I haven’t compiled or tested this, just thinking with my fingers
float fX1 = 0.1;//Define min X coordinate for this trigger
float fX2 = 15.0;//Define max X coordinate for this trigger
float fY1 = 0.1;//Min Y
float fY2 = 15.0;//Max Y
//These can be variables defined on the trigger so you can reuse the script
//I'm not sure how to get the maximum and minimum x, y coordinates for a trigger
//otherwise I would use that instead.
vector vObject = GetPosition(oObject);//This can be vObject.x vObject.y and vObject.z
if(fX1<= vObject.x && fX2>= vObject.x && fY1<= vObject.y && fY2>= vObject.y)
{
//this object is inside and can be destroyed
}
//RWT-OEI 04/17/08
//Given an area ID and a position in that area, returns the first sub-area that is found at that position.
//SubAreas are triggers, AoEEffectObjects, and Encounters.
//Use with GetNextSubArea() to iterate over all the sub-areas at this position.
// oArea = The area to search
// vPosition = The position to evaluate for sub areas.
object GetFirstSubArea( object oArea, vector vPosition );
//RWT-OEI 04/17/08
//Given an area ID, returns the next subarea to be found at the position specified when GetFirstSubArea()
//was called. It is necessary to call GetFirstSubArea() before calling this function in order to get
//any results back.
// oArea = The area to return the next SubArea from.
object GetNextSubArea( object oArea );
just sayin, you’ll probly have to work something with Mannast’s suggestion, unless Beamdog came up with smth similar in EE
@kevL_s good idea, but NWN1 has just this, so it ain’t gonna work for a body bag:
// Is this creature in the given subarea? (trigger, area of effect object, etc..)
// This function will tell you if the creature has triggered an onEnter event,
// not if it is physically within the space of the subarea
int GetIsInSubArea(object oCreature, object oSubArea=OBJECT_SELF)
But I can see a possible workaround (untested). @TacticalERK:
When a creature enters the trigger, save this trigger in creature’s local var.
When it leaves the trigger, clear the var.
When the creature dies in the trigger (you know that because the var is set), wait for its body bag to appear (OnDeath modification), then save the trigger in body bag’s var.
When the trigger is doing the cleanup, scan for nearby body bags and see if their local var matches.
Alternative to 3: instead of using a local var (1 & 2), check in OnDeath all triggers in the area with GetIsInSubArea. EDIT: this is actually optimal approach - see my post below.
This OnDeath script can be used to "customize" a body bag (change description, portrait, etc). You may find it useful. Mind the hardcoded delay.
Shape would be: SHAPE_CUBE (so that it lines up with the square triggers?)
Size would be 50.0 (the trigger’s X is 0.00 and Y is 100) if I read correctly fSize is half the length of one of the sides of the cube, so the 50.0 should be correct?
Location: how is the cube drawn? does it draw a cube around a point (which I could spawn the object in the center of the trigger), or does the location start from the top left corner like my trigger’s placement (X is 0.00 and Y is 100)? If that’s the case maybe I could spawn my object in that top left corner of the trigger? Use the location of the waypoint that the object spawns on (waypoint=001)
Would I need the other things listed?
lTarget is at the center of the cube and the cube’s edges are always axis-aligned.
If your trigger is roughly a square with known size and center you can use that. Or you can save this data in trigger’s local vars as per @Mannast suggestion.
What I suggested works with triggers of any shape and size. Note: point 5 (GetIsInSubArea) is better than 3 because it circumvents possible issues with overlapping triggers.
Thanks for clarifying @TacticalERK! I understood a whole lot better after your second post. However, both NWShacker and Mannast are far more skilled at this than me (plus, I only work with NWN2), so I leave this to them to help you.
This seems logical to me and should work, but as usual you better test it.
Reading through all posts here again, I would have used NWShacker’s workaround with storing local variables if I was you. It seems the most solid to me at least.
So you are trying to see if there is another PC still in the trigger when another one exits it. So what you are actually seeing is if there is another PC within the cube object around the central waypoint or whose location is within the trigger parameters.
Scripts which look to see if there is a PC left in an Area won’t work for a trigger. You will need to define the space/object you are dealing with and see if there is a PC inside that space.
The GetFirstObjectInShape bit you have above is what I was referring to.
That one with the trigger be the calling object, and using the waypoint for the ObjectInShape check center, making sure the wp is centered in the same orientation as the square trigger.
For myself, unless you really can see into the next trigger area well, I opt for the smaller areas and use a seamless transition trigger to move into the adjacent area. Then you don’t need to try and craft a system for getting these sub-areas in NWN1. The other reason for me is less memory is eaten up by loading a larger area.
for example: Henesua’s or Olanders (from ORS)
Or you can just keep track of a count of PCs in each trigger on_enter/exit. Then you just check the variable on exit. Similar to what people do for the area itself in many cases.