PDA

View Full Version : [K1] Question about npc hostile script


JediMaster76
06-24-2008, 09:05 PM
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?

TriggerGod
06-24-2008, 09:08 PM
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.

JediMaster76
06-24-2008, 09:11 PM
No, that's not the problem, that's what I'm trying to solve. I realize I had two instances of "obj2" in there, because I have more than one object with the same tag. I'm trying to figure out a way for all the instances of "obj2" to turn hostile.

glovemaster
06-25-2008, 02:44 AM
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.

JediMaster76
06-25-2008, 05:43 PM
Thanks glovemaster, worked perfectly ;)

EDIT: Ah, thanks for the alternative, stoffe. Whatever works, I suppose. :)

stoffe
06-25-2008, 08:41 PM
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");
}