JediMaster76 Posted June 25, 2008 Share Posted June 25, 2008 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 More sharing options...
TriggerGod Posted June 25, 2008 Share Posted June 25, 2008 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 More sharing options...
JediMaster76 Posted June 25, 2008 Author Share Posted June 25, 2008 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. Link to comment Share on other sites More sharing options...
glovemaster Posted June 25, 2008 Share Posted June 25, 2008 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 More sharing options...
JediMaster76 Posted June 25, 2008 Author Share Posted June 25, 2008 Thanks glovemaster, worked perfectly EDIT: Ah, thanks for the alternative, stoffe. Whatever works, I suppose. Link to comment Share on other sites More sharing options...
stoffe Posted June 26, 2008 Share Posted June 26, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.