lfnetwork.com mark read register faq members calendar

Thread: Destroy Object upon Exiting module?
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 03-20-2006, 07:29 AM   #1
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
Destroy Object upon Exiting module?

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?

Code:
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);
}
}
}
}
Patriarch is offline   you may: quote & reply,
Old 03-20-2006, 10:50 AM   #2
stoffe
Network Caretaker
 
stoffe's Avatar
 
Status: Administrator
Join Date: Apr 2002
Posts: 5,833
Helpful! 10 year veteran! Notable contributor 
Quote:
Originally Posted by Patriarch
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.

stoffe is offline   you may: quote & reply,
Old 03-20-2006, 11:21 AM   #3
Darth333
Administraterror
 
Darth333's Avatar
 
Status: Administrator
Join Date: Feb 2004
Location: In my secret dungeon...
Posts: 8,292
If you use the OnExit event, you could try with something like that:
Code:
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.
Darth333 is offline   you may: quote & reply,
Old 03-20-2006, 11:30 AM   #4
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
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
Patriarch is offline   you may: quote & reply,
Old 03-20-2006, 11:38 AM   #5
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
Goooood, the force is strooooooong with you Darth333
Patriarch is offline   you may: quote & reply,
Old 03-20-2006, 12:04 PM   #6
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
Actually, it does not work....think i have some problems with controllig the brackets....
Patriarch is offline   you may: quote & reply,
Old 03-20-2006, 12:18 PM   #7
stoffe
Network Caretaker
 
stoffe's Avatar
 
Status: Administrator
Join Date: Apr 2002
Posts: 5,833
Helpful! 10 year veteran! Notable contributor 
Quote:
Originally Posted by Patriarch
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).

stoffe is offline   you may: quote & reply,
Old 03-20-2006, 05:28 PM   #8
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
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)
Patriarch is offline   you may: quote & reply,
Old 03-20-2006, 06:04 PM   #9
Darth333
Administraterror
 
Darth333's Avatar
 
Status: Administrator
Join Date: Feb 2004
Location: In my secret dungeon...
Posts: 8,292
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....06&postcount=6


Btw, the exit stuff is for use on the area's OnExit event. Of course, I<ve never tried it
Darth333 is offline   you may: quote & reply,
Old 03-20-2006, 06:21 PM   #10
stoffe
Network Caretaker
 
stoffe's Avatar
 
Status: Administrator
Join Date: Apr 2002
Posts: 5,833
Helpful! 10 year veteran! Notable contributor 
Quote:
Originally Posted by Patriarch
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:

Code:
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.


Quote:
Originally Posted by Patriarch
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).


Last edited by stoffe -mkb-; 03-21-2006 at 06:37 AM. Reason: Fixed mental typo
stoffe is offline   you may: quote & reply,
Old 03-21-2006, 04:47 AM   #11
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
Great, I'm sorry about all the questions but how would I use that script?
tried doing it like this:

#include "k_inc_tr"

Code:
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?
Patriarch is offline   you may: quote & reply,
Old 03-22-2006, 10:05 AM   #12
Patriarch
Rookie
 
Join Date: Oct 2005
Posts: 77
I solved it

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

Code:
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);        

}
}
Patriarch is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Knights of the Old Republic > Editing / Modding > Holowan Laboratories > Destroy Object upon Exiting module?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:39 PM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.