Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Getting the GetFirstPC and GetNextPC functions to work reliably

Page: 1 of 1
 Ulic and Cay
09-06-2007, 9:28 PM
#1
Edit: Woops, don't know how this got here. Can someone please move this to the Holowan Laboratories section? My mistake.

Mod note: Moved. :) ~M


I, for the life of me, can't get the GetFirstPC and GetNextPC functions to work reliably like I want them to. I want to move the whole party to some waypoints when I have the PC enter a trigger. Unfortunately it will only sometimes move my NPCs to their waypoints like I think it should. Here's the script I've created:
void main() {
object oEntering = GetEnteringObject();
if ((oEntering != GetFirstPC())) {
return;
}
if ((GetJournalEntry("Yima") == 15)&&GetGlobalNumber("201TEL_Q_Yima") == 1) {
object oPC = GetFirstPC();
object oParty1 = GetNextPC();
object oParty2 = GetNextPC();
object oAtallo = GetObjectByTag("210_Atallo");
SetGlobalFadeOut (0.0, 1.0);
DestroyObject(oAtallo);
CreateObject(OBJECT_TYPE_CREATURE, "n_czerkatwilek", GetLocation((GetObjectByTag("WP_czerka"))));
CreateObject(OBJECT_TYPE_CREATURE, "n_tsfatallo", GetLocation((GetObjectByTag("WP_atallo"))));
CreateObject(OBJECT_TYPE_CREATURE, "g_210thug1", GetLocation((GetObjectByTag("WP_unload3"))));
CreateObject(OBJECT_TYPE_CREATURE, "g_210thug2", GetLocation((GetObjectByTag("WP_unload4"))));
AssignCommand((GetObjectByTag("g_210thug1")), ActionMoveToObject(GetObjectByTag("WP_unload2")));
AssignCommand((GetObjectByTag("g_210thug2")), ActionMoveToObject(GetObjectByTag("WP_unload1")));
SetGlobalNumber("201TEL_Q_Yima", 2);
AssignCommand(oAtallo, ClearAllActions());
AssignCommand((GetObjectByTag("czerkaleader")), ClearAllActions());
CancelCombat(oPC);
CancelCombat(oParty1);
CancelCombat(oParty2);
DelayCommand(1.0, AssignCommand(oParty1, ActionJumpToLocation((GetLocation((GetObjectByTag("WP_spybc1")))))));
DelayCommand(1.0, AssignCommand(oParty2, ActionJumpToLocation((GetLocation((GetObjectByTag("WP_spybc2")))))));
DelayCommand(1.1, AssignCommand(oPC, ActionJumpToObject((GetObjectByTag("WP_spybc")))));
DelayCommand(1.3, AssignCommand((GetObjectByTag("czerkaleader")), ActionStartConversation(oPC, "czerkabc", 0, 0, 1, "", "", "", "", "", "", 0, 0xFFFFFFFF, 0xFFFFFFFF, 0)));
}
}
I've tried changing the DelayCommand wait and removing the DelayCommand for the NPC waypoint jumps, which didn't help. Plus my PC waypoint jump works everytime, so I'm guessing the GetNextPC call is failing. So um any suggestions?
 stoffe
09-06-2007, 9:45 PM
#2
I, for the life of me, can't get the GetFirstPC and GetNextPC functions to work reliably like I want them to. I want to move the whole party to some waypoints when I have the PC enter a trigger.


IIRC you can't use those functions to access party members, they only work for the player character, i.e. the main character of the game. Since KOTOR has no multiplayer only GetFirstPC() is meaningful.

To access your partymembers you can use the GetPartyMemberByIndex() function instead. Like:


location ST_GetLoc(string sWP);
void ST_JumpToPoint(string sWP, object oJumper=OBJECT_SELF);


void main() {
if ((GetEnteringObject() != GetFirstPC())) {
return;
}

if ((GetJournalEntry("Yima") == 15) && (GetGlobalNumber("201TEL_Q_Yima") == 1)) {
object oPC = GetPartyMemberByIndex(0);
object oParty1 = GetPartyMemberByIndex(1);
object oParty2 = GetPartyMemberByIndex(2);

SetGlobalFadeOut (0.0, 1.0);
DestroyObject(GetObjectByTag("210_Atallo"));

CreateObject(OBJECT_TYPE_CREATURE, "n_czerkatwilek", ST_GetLoc("WP_czerka"));
CreateObject(OBJECT_TYPE_CREATURE, "n_tsfatallo", ST_GetLoc("WP_atallo"));
object oThug1 = CreateObject(OBJECT_TYPE_CREATURE, "g_210thug1", ST_GetLoc("WP_unload3"));
object oThug2 = CreateObject(OBJECT_TYPE_CREATURE, "g_210thug2", ST_GetLoc("WP_unload4"));

AssignCommand(oThug1, ActionMoveToObject( GetObjectByTag("WP_unload2") ));
AssignCommand(oThug2, ActionMoveToObject( GetObjectByTag("WP_unload1") ));

object oLeader = GetObjectByTag("czerkaleader");
AssignCommand(oLeader, ClearAllActions());
CancelCombat(oPC);
CancelCombat(oParty1);
CancelCombat(oParty2);

DelayCommand(1.0, ST_JumpToPoint("WP_spybc1", oParty1));
DelayCommand(1.0, ST_JumpToPoint("WP_spybc2", oParty2));
DelayCommand(1.1, ST_JumpToPoint("WP_spybc", oPC));
DelayCommand(1.3, AssignCommand(oLeader, ActionStartConversation(oPC, "czerkabc", FALSE, 0, TRUE)));
}
}


location ST_GetLoc(string sWP) {
return GetLocation(GetObjectByTag(sWP));
}


void ST_JumpToPoint(string sWP, object oJumper=OBJECT_SELF) {
AssignCommand(oJumper, ActionJumpToLocation( ST_GetLoc(sWP) ));
}
 Ulic and Cay
09-07-2007, 2:19 AM
#3
Thanks, that approach seems to work far more reliably than what I was doing but it still will fail occasionally. It seems that if I'm jumping them to a waypoint that is line of sight its fine but if the waypoint its blocked by a wall it can be a problem. Is that possible? Do you have any suggestions for getting around this? Maybe if I try two jumps to get around the wall? I've never encountered a problem like this before so it seems unlikely...
 stoffe
09-07-2007, 6:06 AM
#4
Thanks, that approach seems to work far more reliably than what I was doing but it still will fail occasionally. It seems that if I'm jumping them to a waypoint that is line of sight its fine but if the waypoint its blocked by a wall it can be a problem. Is that possible? Do you have any suggestions for getting around this? Maybe if I try two jumps to get around the wall? I've never encountered a problem like this before so it seems unlikely...

Hmm, weird, you don't need line of sight to jump a character to a specific location. You do need the destination location to be walkable though. It might be that the action queue gets messed up on some occasions instead, disrupting the jump. Try this variant and see if it makes any difference (assuming the two NPCs you get by tag are the ones you just spawned in):


location ST_GetLoc(string sWP);
void ST_JumpToPoint(string sWP, object oJumper=OBJECT_SELF);


void main() {
object oPC = GetFirstPC();
if ((GetEnteringObject() != oPC)) {
return;
}

if ((GetJournalEntry("Yima") == 15) && (GetGlobalNumber("201TEL_Q_Yima") == 1)) {
object oParty1 = GetPartyMemberByIndex(0);
object oParty2 = GetPartyMemberByIndex(1);
object oParty3 = GetPartyMemberByIndex(2);

SetGlobalFadeOut (0.0, 1.0);
DestroyObject(GetObjectByTag("210_Atallo"));

object oLeader = CreateObject(OBJECT_TYPE_CREATURE, "n_czerkatwilek", ST_GetLoc("WP_czerka"));
object oAtallo = CreateObject(OBJECT_TYPE_CREATURE, "n_tsfatallo", ST_GetLoc("WP_atallo"));
object oThug1 = CreateObject(OBJECT_TYPE_CREATURE, "g_210thug1", ST_GetLoc("WP_unload3"));
object oThug2 = CreateObject(OBJECT_TYPE_CREATURE, "g_210thug2", ST_GetLoc("WP_unload4"));

CancelCombat(oParty1);
CancelCombat(oParty2);
CancelCombat(oParty3);

AssignCommand(oThug1, ActionForceMoveToObject( GetObjectByTag("WP_unload2") ));
AssignCommand(oThug2, ActionForceMoveToObject( GetObjectByTag("WP_unload1") ));

DelayCommand(1.0, ST_JumpToPoint("WP_spybc1", oParty2));
DelayCommand(1.0, ST_JumpToPoint("WP_spybc2", oParty3));
DelayCommand(1.1, ST_JumpToPoint("WP_spybc", oParty1));

AssignCommand(oAtallo, ClearAllActions());
AssignCommand(oLeader, ClearAllActions());
DelayCommand(1.3, AssignCommand(oLeader, ActionStartConversation(oPC, "czerkabc", FALSE, 0, TRUE)));
}
}


location ST_GetLoc(string sWP) {
return GetLocation(GetObjectByTag(sWP));
}


void ST_JumpToPoint(string sWP, object oJumper=OBJECT_SELF) {
SetCommandable(TRUE, oJumper);
AssignCommand(oJumper, ClearAllActions());
AssignCommand(oJumper, JumpToLocation( ST_GetLoc(sWP) ));
AssignCommand(oJumper, ActionDoCommand( SetCommandable(TRUE, oJumper) ));
AssignCommand(oJumper, SetCommandable(FALSE, oJumper));
}
 Ulic and Cay
09-07-2007, 8:05 AM
#5
That one's got it, thanks. I did have to tweak the void ST_JumpToPoint() subscript though. It didn't seem to ever make it to the ActionStartConversation line.
void ST_JumpToPoint(string sWP, object oJumper=OBJECT_SELF) {
AssignCommand(oJumper, JumpToLocation( ST_GetLoc(sWP) ));
}
Page: 1 of 1