Waypoint Sequence

Hello, I’m looking for a way to turn this script from a random waypoint jump to an ordered sequence for each use. A simple 1, 2, 3 and then back to 1 order. I’m only an amateur scripter, so I find myself a bit lost. Thanks.

{

object oPC = GetLastUsedBy();

if (!GetIsPC(oPC)) return;

object oTarget;
oTarget = OBJECT_SELF;

int nInt;
nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DIVINE_STRIKE_HOLY), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DIVINE_STRIKE_HOLY), GetLocation(oTarget));

nInt = GetObjectType(oTarget);

effect eEffect;
eEffect = EffectVisualEffect(VFX_FNF_SOUND_BURST);

if (nInt != OBJECT_TYPE_WAYPOINT)
   DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oTarget));
else
   DelayCommand(1.0, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eEffect, GetLocation(oTarget)));

oTarget = oPC;

nInt = GetObjectType(oTarget);

eEffect = EffectVisualEffect(VFX_FNF_SCREEN_SHAKE);

if (nInt != OBJECT_TYPE_WAYPOINT)
   DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oTarget));
else
   DelayCommand(1.0, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eEffect, GetLocation(oTarget)));

DelayCommand(2.0, SetCutsceneMode(oPC, TRUE));

DelayCommand(2.0, FadeToBlack(oPC));

location lTarget;
if(Random(3) >= 1)
oTarget = GetWaypointByTag("0SpireEnter1");
if(Random(3) >= 2)
oTarget = GetWaypointByTag("0SpireEnter2");
if(Random(3) >= 3)
oTarget = GetWaypointByTag("0SpireEnter3");

lTarget = GetLocation(oTarget);

if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

oTarget=GetFirstFactionMember(oPC, FALSE);
int nMember = 1;
while (GetIsObjectValid(oTarget))
{
    if(GetDistanceBetween(oPC, oTarget) < 10.0)
    {
        DelayCommand(1.0, AssignCommand(oPC, ClearAllActions()));
        DelayCommand(3.0, AssignCommand(oPC, ActionJumpToLocation(lTarget)));
    }
    oTarget=GetNextFactionMember(oPC, FALSE);
    nMember == (nMember + 1);
   }

DelayCommand(6.0, SetCutsceneMode(oPC, FALSE));

DelayCommand(6.0, FadeFromBlack(oPC, FADE_SPEED_SLOW));

}

Thats simple, change the code between the first and the last line of the following snippet

DelayCommand(2.0, FadeToBlack(oPC)); //This line is already there

int i = GetLocalInt (OBJECT_SELF, “NextSpireTarget”)

if(i == 1) oTarget = GetWaypointByTag(“0SpireEnter1”);
if(i == 2) oTarget = GetWaypointByTag(“0SpireEnter2”);
if(i == 3) oTarget = GetWaypointByTag(“0SpireEnter3”);
location lTarget = GetLocation(oTarget);

if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return; //This line is already there


Then you need to store a variable “NextSpireTarget” on the placable which triggers the script, it should contain the number of the next target.

Thank you for the response. Testing seemed to give me a compiling error.

6/3/2020 8:14:16 AM: Error. ‘su_spireenter’ did not compile.
su_spireenter.nss(44): ERROR: PARSING VARIABLE LIST

I’m not sure why. Correct me if I’m wrong, but wouldn’t there also need to be a section that tracks each use to change the variable between 1-3 to teleport in a sequence?

You probably need to fix the double quotes if you copy/pasted. Just retype them with real double quotes on the GetWayointByTag lines. And the “NextSpireTargets” ones…

I did manage to catch that the first time around but still the error.

Uhm, sorry, my scripting was made outside the toolset. Which line is highlighted? Line 44 doesn’t tell me anything …

I believe I have figured it and will post it for posterity. Thanks for the assistance.

void main()
{

object oPC = GetLastUsedBy();

if (!GetIsPC(oPC)) return;

if (GetLocalInt(OBJECT_SELF, "NextSpireTarget")!= 1)
   return;

object oTarget;
location lTarget;
oTarget = GetWaypointByTag("0SpireEnter1");

lTarget = GetLocation(oTarget);

if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

oTarget=GetFirstFactionMember(oPC, FALSE);

while (GetIsObjectValid(oTarget))
   {
   AssignCommand(oTarget, ClearAllActions());

   AssignCommand(oTarget, ActionJumpToLocation(lTarget));
   oTarget=GetNextFactionMember(oPC, FALSE);
   }

SetLocalInt(OBJECT_SELF, "NextSpireTarget", 2);

if (GetLocalInt(OBJECT_SELF, "NextSpireTarget")== 2)
   {
   oTarget = GetWaypointByTag("0SpireEnter2");

   lTarget = GetLocation(oTarget);

   if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

   oTarget=GetFirstFactionMember(oPC, FALSE);

   while (GetIsObjectValid(oTarget))
      {
      AssignCommand(oTarget, ClearAllActions());

      AssignCommand(oTarget, ActionJumpToLocation(lTarget));
      oTarget=GetNextFactionMember(oPC, FALSE);
      }

   SetLocalInt(OBJECT_SELF, "NextSpireTarget", 3);

   }
else if (GetLocalInt(OBJECT_SELF, "NextSpireTarget")== 3)
   {
   oTarget = GetWaypointByTag("0SpireEnter3");

   lTarget = GetLocation(oTarget);

   if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

   oTarget=GetFirstFactionMember(oPC, FALSE);

   while (GetIsObjectValid(oTarget))
      {
      AssignCommand(oTarget, ClearAllActions());

      AssignCommand(oTarget, ActionJumpToLocation(lTarget));
      oTarget=GetNextFactionMember(oPC, FALSE);
      }

   SetLocalInt(OBJECT_SELF, "NextSpireTarget", 1);

   }
}

I don’t think that will do what you described in the OP.

if (GetLocalInt(OBJECT_SELF, "NextSpireTarget")!= 1)
   return;

This part makes the script only work at all when NextSpireTarget == 1. But you wanted it to cycle on each use, this will prevent that.

SetLocalInt(OBJECT_SELF, "NextSpireTarget", 2);

if (GetLocalInt(OBJECT_SELF, "NextSpireTarget")== 2)

This part will always be true. It looks like you will jump to target 1 then jump to target 2 then
since you’ve set it to 3 it’ll never do anything again since NextSpireTarget is not 1.

Here is a shorter version that should do what you described. Take a look and see if it makes sense to you. In this one you don’t need to remember to set the variable initially.

void main() {
	object oPC = GetLastUsedBy();

	if (!GetIsPC(oPC)) return;

	int nTarget = GetLocalInt(OBJECT_SELF, "NextSpireTarget");
	if (nTarget <= 0 || nTarget > 3) 
		nTarget = 1;

	object oTarget = GetWaypointByTag("0SpireEnter" + IntToString(nTarget));
	location lTarget = GetLocation(oTarget);

	// Probably worth a sendmessage here for debugging
	if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;	

	oTarget=GetFirstFactionMember(oPC, FALSE);
	while (GetIsObjectValid(oTarget)) {
   		AssignCommand(oTarget, ClearAllActions());
   		AssignCommand(oTarget, ActionJumpToLocation(lTarget));
   		oTarget=GetNextFactionMember(oPC, FALSE);
   	}
	SetLocalInt(OBJECT_SELF, "NextSpireTarget", nTarget + 1);
}
1 Like

You’re right, it didn’t end up working the way I thought. I ended up making three separate scripts to save myself some headache, and that seems to be working. I may end up using yours for something else down the road. Thanks again.