Jump to content

Home

Destroy Object upon Exiting module?


Patriarch

Recommended Posts

How can this be done? I would prefer if i could be user as a UserDefine script? I have been trying this one....as a userdefine... the "else" part works fine. I am guessing that this mothod does not work since transition takes place before it executes....The forceheartbeat does not seem to be an option either...

 

I was wondering if anybody perhaps could show me a wildcard script where "DestroyObject" occurs when you get close to a trigger with "to_XXXX" in it?

 

void main() {

int nEvent = GetUserDefinedEventNumber();
if (nEvent == 1001){
object oPC= GetFirstPC();
object oKUS =GetObjectByTag("power", 0);
if (((GetIsObjectValid(oKUS))) && ((!GetIsObjectValid(oPC)))) {
DestroyObject(oKUS, 0.0, 0, 0.0, 0);
}



else {
object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_FRIEND, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
if (GetIsObjectValid(oTarget)){
ActionDoCommand(SetFacingPoint(GetPosition(oTarget)));
ActionWait(1.0);
ExecuteScript("pa_loc", OBJECT_SELF);
}
}
}
}

Link to comment
Share on other sites

How can this be done? I would prefer if i could be user as a UserDefine script? I have been trying this one....as a userdefine... the "else" part works fine. I am guessing that this mothod does not work since transition takes place before it executes....The forceheartbeat does not seem to be an option either...

 

I was wondering if anybody perhaps could show me a wildcard script where "DestroyObject" occurs when you get close to a trigger with "to_XXXX" in it?

 

void main() {

int nEvent = GetUserDefinedEventNumber();
if (nEvent == 1001){
object oPC= GetFirstPC();
object oKUS =GetObjectByTag("power", 0);
if (((GetIsObjectValid(oKUS))) && ((!GetIsObjectValid(oPC)))) {
DestroyObject(oKUS, 0.0, 0, 0.0, 0);
}



else {
object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_FRIEND, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
if (GetIsObjectValid(oTarget)){
ActionDoCommand(SetFacingPoint(GetPosition(oTarget)));
ActionWait(1.0);
ExecuteScript("pa_loc", OBJECT_SELF);
}
}
}
}

Link to comment
Share on other sites

How can this be done? I would prefer if i could be user as a UserDefine script? I have been trying this one....as a userdefine... the "else" part works fine. I am guessing that this mothod does not work since transition takes place before it executes....The forceheartbeat does not seem to be an option either...

 

The only way I can think of to do something when the player is leaving the module would be to put the script in the OnExit event script of the Area that the module contains. Don't forget to check that the exiting creature is the player though, since OnEnter/OnExit events run for ALL creatures, not just the player or party.

 

You can't really handle this from the object's own scripts since the module is completely unloaded from the game the moment you transition to another area. Since those objects will no longer be loaded by the game engine they can't run their scripts to be able to detect if the player is still in the area.

Link to comment
Share on other sites

If you use the OnExit event, you could try with something like that:

void main()
{
object oExiting = GetExitingObject(); 
object oPC=GetFirstPC();
object oKUS =GetObjectByTag("power");
if (GetIsPC(oExiting))
   {
     if (GetIsObjectValid(oKUS))
       {
          DestroyObject(oKUS);
       }
   }
}

 

Or, instead of using the OnEnxit event, you could also simply check the distance between your NPC and the PC and destroy the NPC once the pc is x meters away.

Link to comment
Share on other sites

Okay Thanks...

 

But what if it is a puppet and I am using DakVesser' HB/ Userdefined(and yours) then i imagine there would be some way for the object to constantly check the location of the pc.....(as far as i understand the puppet thing...it moves by constantly getting informations about the PC's whereabouts throuhg the HBScript or UD)

 

I want to do like this

 

if PC get close to a Trigger or wp to eg the ebon hawk a vector or whatever, then the userdef would fire the destroyobjectself command.

 

I have an Idea how to do this.... i just need the actual syntax for:

 

 

object oTransition = GetTransitionTarget(oTransition);< Have to specify this as the nearest transition point or trigger if you get my point ...

 

hmmm just got to think of darth333 tutorial regarding spawning items on placeables with no specific tag.....

 

All modules has a trigger that starts with "to_(sTag)"

 

I feel a solution is comming to me

Link to comment
Share on other sites

But what if it is a puppet and (snip)

 

Puppets automatically follow their owner, meaning that they transition along with the party when you go to a new area. You shouldn't have to remove those manually, the game moves them to the new area for you (just as the Puppet automatically vanishes if you remove the owner from the active party).

Link to comment
Share on other sites

I now all about the puppets, thanks to you stoffe;-)

 

how would you locate a trigger with a Tag that starts with "to_something" and ONLY those...

 

By looking at the a_move_wp in the source it suggests a sWaypoint to be "wp_+sTag" ....i can understand so much but as far as subtracting everything else from the trigger tag but "to_" I am pretty much clueless....

 

would it be something like string sWaypoint = ((to_- "sTag") + (to_+ "sTag"));

The on exit stuff doesn't seem to work.....even with no otherthings defined (and with force heartbeat)

Link to comment
Share on other sites

Do you mean something like this? http://www.lucasforums.com/showthread.php?p=1986971 Instead of GetModuleName, just use the tag. Depending on what you want to do, this post by Stoffe may also be useful: http://www.lucasforums.com/showpost.php?p=1987106&postcount=6

 

 

Btw, the exit stuff is for use on the area's OnExit event. Of course, I<ve never tried it :D

Link to comment
Share on other sites

how would you locate a trigger with a Tag that starts with "to_something" and ONLY those...

 

If this should work in all areas and not just a particular one, the problem is that not all transition triggers have a tag starting with a "to_" prefix. Transitions can also be placed on doors, and transitions are not the only means of travelling between areas. It happens from a dialog, cutscene or other scripted events throughout the game as well.

 

Anyway, if you just want to find a trigger with a tag starting with "to_" within a specified radius, you could write a function like:

 

object GetToTrigger(float fRadius, object oSource=OBJECT_SELF) {
   location lLoc = GetLocation(oSource);
   object oTrigger = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_TRIGGER);

   while (GetIsObjectValid(oTrigger)) {
       if (GetStringLowerCase(GetStringLeft(GetTag(oTrigger), 3)) == "to_") {
           return oTrigger;    
       }
       oTrigger = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_TRIGGER);       
   }
   return OBJECT_INVALID;
}

 

That wouldn't necessarily mean that anyone has to trip that trigger, only that one is nearby.

 

 

The on exit stuff doesn't seem to work.....even with no otherthings defined (and with force heartbeat)

 

The OnExit stuff? How does the script look, and which OnExit event are you using? The area's, set in the .ARE file? If so you'll have to do what needs to be done directly in that script, since there is no guarantee that any signalled user-defined events have the time to fire before the area is unloaded.

 

Why would you want to use ForceHeartbeat() in an exit script? It only runs, once, when a creature leaves the associated object (in this case the area).

Link to comment
Share on other sites

Great, I'm sorry about all the questions but how would I use that script?

tried doing it like this:

 

#include "k_inc_tr"

 

void main(){
if ((GetGlobalNumber("powerpup_owner") == 15)){
int nEvent = GetUserDefinedEventNumber();
if (nEvent == 1001){
//main function  starts here.....

object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_FRIEND, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
int nParam1 = 4;
float fFloat1 = IntToFloat(nParam1);
object oPC =GetFirstPC();
object oTrigger =  GetToTrigger(fFloat1, oPC);

if (GetIsObjectValid(oTarget)){
	ActionDoCommand(SetFacingPoint(GetPosition(oTarget)));
	ActionWait(1.0);
	ExecuteScript("pa_droid", OBJECT_SELF);
// I would like to put the near to trigger here as a  
// if ((GetIsObjectValid(oTrigger)) DestroyObject(OBJECT_SELF, 0.0, 0, 0.0, 0);

				}
				}
		}


else {
int nEvent = GetUserDefinedEventNumber();
if (nEvent == 1001){
object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_FRIEND, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
if (GetIsObjectValid(oTarget)){
	ActionDoCommand(SetFacingPoint(GetPosition(oTarget)));
	ActionWait(1.0);
	ExecuteScript("pa_droid", OBJECT_SELF);
					}
			}
	}
}

 

 

If i include your script above (i called it "k_inc_tr") it states that there is a return value specified for void function and that a declaration and initial value type mismatch.

 

Could you explain it to me how exactly this should be specified?

Link to comment
Share on other sites

Hey finally i solved my problem: thx stoffe and darth....for the inspiration

 

void main () 
{
location lPC = GetLocation(GetFirstPC());
object oPower = GetObjectByTag("power",0);
object oCheck = GetNearestObjectToLocation(4, lPC, 1);
location lTrigger = GetLocation(oCheck);
float float1 =GetDistanceBetween2D(GetFirstPC(), oCheck);
if (((GetIsObjectValid(oCheck))) && ((GetStringLowerCase(GetStringLeft(GetTag(oCheck)  , 3)) == "to_")) && (float1 <= 6.1)) {
DestroyObject(oPower, 0.0, 0, 0.0, 0);        

}
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...