Jump to content

Home

[K1] Question about npc hostile script


JediMaster76

Recommended Posts

Alright. So, what I'm trying to do is turn a decent-sized group of NPC's hostile. A couple of these NPCs were spawned into the module and have different spawn-in locations but the same tag (like Sith troopers).

 

This script generally works for me...

 

void main() {
object oNPC=GetObjectByTag("baddie");
ChangeToStandardFaction(oNPC, 1);

object oThug1 = GetObjectByTag("obj1");
object oThug2 = GetObjectByTag("obj2");
object oThug3 = GetObjectByTage("obj2");

ChangeToStandardFaction(oThug1, 1);
ChangeToStandardFaction(oThug2, 1);
ChangeToStandardFaction(oThug3, 1);

ExecuteScript("k_ai_master",oNPC,1005);


}

 

... however, when I use that script, only one object with the "obj2" tag actually turns hostile, the other remains neutral and doesn't do anything. So basically what I'm asking is, what's the easiest way to work around this, simply give all my NPCs unique tags (which would take awhile in some cases), or is there a script where it turns ALL instances of "obj2" hostile?

Link to comment
Share on other sites

did you copy your script straight from the text editor(or whatever you used to make the script)? If so, I think I see the problem:

void main() {
object oNPC=GetObjectByTag("baddie");
ChangeToStandardFaction(oNPC, 1);

object oThug1 = GetObjectByTag("obj1");
object oThug2 = GetObjectByTag("obj2");
object oThug3 = GetObjectByTag("obj3");

ChangeToStandardFaction(oThug1, 1);
ChangeToStandardFaction(oThug2, 1);
ChangeToStandardFaction(oThug3, 1);

ExecuteScript("k_ai_master",oNPC,1005);


}

Now try the script.

Link to comment
Share on other sites

It will be something like:

void GM_ChangeAllToStandardFaction(string sTag, int StandardFaction)
{
   object oNPC = GetFirstObjectInArea();
   while (GetIsObjectValid(oNPC))
   {
       if (GetTag(oNPC) == sTag)
            ChangeToStandardFaction(oNPC, StandardFaction);
       oNPC = GetNextObjectInArea();
   }
}

void main() {
   object oNPC=GetObjectByTag("baddie");
   ChangeToStandardFaction(oNPC, 1);
   object oThug1 = GetObjectByTag("obj1");
   object oThug3 = GetObjectByTag("obj3");

   ChangeToStandardFaction(oThug1, 1);
   GM_ChangeAllToStandardFaction("obj2", 1);
   ChangeToStandardFaction(oThug3, 1);

   ExecuteScript("k_ai_master",oNPC,1005);
}

If you also have multiple instances of "obj1" and "obj3" then you can just use the same function with them.

Link to comment
Share on other sites

It will be something like:

 

You don't need to iterate through all objects in the area and find those that match your tag like that. It's more efficient to fetch the objects based on tag directly, like for example:

 

void ST_AggroAllByTag(string sTag, int iFac=STANDARD_FACTION_HOSTILE_1) {
   int iIdx = 0;
   object oNPC = GetObjectByTag(sTag, iIdx);

   while (GetIsObjectValid(oNPC)) {
       ChangeToStandardFaction(oNPC, iFac);
       ExecuteScript("k_ai_master", oNPC, 1005);

       oNPC = GetObjectByTag(sTag, ++iIdx);
   }
}

void main() {
   ST_AggroAllByTag("baddie");
   ST_AggroAllByTag("obj1");
   ST_AggroAllByTag("obj2");
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...