Sign in to follow this  
RageBoxMan

Need help with a run script

Recommended Posts

Hey yall! In short, I'm trying to get some tach to run from one area to another. There's 5 of them all with the same tag. This is the script I wrote but I think maybe it only works for 1 npc at a time..

void main() {

 

object oTach = GetObjectByTag("c_tach");

int  bRun = TRUE;


location lPath1Run = Location(Vector(327.34, 206.69, 7.71), 0.0);


DelayCommand(2.0, AssignCommand(oTach, ActionForceMoveToLocation(lPath1Run, TRUE)));

 

}

I'm still a novice at this so any help is greatly appreciated!

If it helps I'm in the upper shadowlands module and from what I can tell the tach are not obstructed in anyway... I just need them to run to the coordinates.

Edited by RageBoxMan

Share this post


Link to post
Share on other sites

There are two options if you want to apply a command to multiple NPCs with the same tag. The first is a loop iterating through every creature in the level (useful if you need to deal with multiple sets of tags), the second is to call the GetObjectByTag function multiple times, each with a different nth index to grab each creature. Check the full command:

// 200: Get the nNth object with the specified tag.
// - sTag
// - nNth: the nth object with this tag may be requested
// * Returns OBJECT_INVALID if the object cannot be found.
object GetObjectByTag(string sTag, int nNth=0);

Identifiers are 0 indexed, so the first creature is 0, the second 1, and so forth. So to get the 5th Tach, the command would be GetObjectByTag("c_tach", 4). Since you didn't specify an index, the compiler is pulling in the default index 0.

In this case, I'd actually go with a combined variation so you can add a bit of randomness to things. Like so:

void main() {
    
    object oTach;
    int i;
    location lPath1Run = Location(Vector(327.34, 206.69, 7.71), 0.0);
    
    for (i = 0; i < 5; i++)
    {
        oTach = GetObjectByTag("c_tach", i);
        DelayCommand(1.5 + IntToFloat(Random(3)), AssignCommand(oTach, ActionForceMoveToLocation(lPath1Run, TRUE)));
    }
}

Since pathfinding is pretty terrible, you may have to introduce additional delay between each to prevent them running into each other. You could probably just pad it by also adding in IntToFloat(i) in the delay value, which should force each subsequent value to increase while still retaining some randomness.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this