Creating a new faction for a more efficient script?

Post » Mon Nov 19, 2012 8:38 pm

In one of my scripts I have an OnHit() event that has multiple conditions. One of those conditions is a check to see if the NPC that has been hit is a member of any of the hold crime factions. Checking if the NPC is a member of each hold crime faction is inefficient so is there a faction that contains all the actors within the crime factions for each hold. If not is it advisable to create my own faction and put all these actors in it? I know it would be a lot of work but the resulting script would be much faster.
User avatar
Big Homie
 
Posts: 3479
Joined: Sun Sep 16, 2007 3:31 pm

Post » Mon Nov 19, 2012 1:08 pm

I don't think there is a global faction for Hold Crimes (wouldn't really make sense if there were)?

But you could make your own ... Question is whether placing all of the NPCs into it will effect anything vanilla, or anything being relied on by another mod. It will make all Actors you place in the one Faction have a friendly relationship ... that might not work out to well. though only teting it is going to determine if that is the case,
User avatar
Baylea Isaacs
 
Posts: 3436
Joined: Mon Dec 25, 2006 11:58 am

Post » Mon Nov 19, 2012 12:07 pm

Could you add all the factions you need into a formlist, then do a check in the on hit event that the actor is in a faction in the formlist?
User avatar
Elizabeth Falvey
 
Posts: 3347
Joined: Fri Oct 26, 2007 1:37 am

Post » Mon Nov 19, 2012 10:39 am

Adding all those NPCs to a faction woldn't suppose any problem related to making them friendly each other, as members of the same faction aren't friendly by default. The faction need to be friendly to itself for that. The problem is that you'll need to edit too many NPCs to finally not cover any mod added NPC.

B1gBadDaddy Idea is interesting. Formlists are generally quite slow, but checking if an element is inside one of them is really fast. But for using it, you would need to obtain the membership of a NPC to a faciton without asking for that faction specifically, which is not possible.

I think you'll need to stick to trying to optimize the check for those factions. If you put all the conditions on the same if, they will be checked everitime, while if you use a if, elseif, elseif... structure, once you found a fitting result the structure won't continue executing.

I would recommend you to check in the first if for three of the factions, then for other three on the first elseif and in the third one for the last three. In my opinion is the most efficient way to do it.
User avatar
Lory Da Costa
 
Posts: 3463
Joined: Fri Dec 15, 2006 12:30 pm

Post » Mon Nov 19, 2012 9:47 am

Thanks for the advice guys. My main worry about creating a faction and adding NPC's would be incompatibilities since I think if you modify an NPC in any way your mod (if loaded last or later) will completely overwrite any other mods changes to vanilla NPC's. But there may be other problems as h4event mentioned.

I would recommend you to check in the first if for three of the factions, then for other three on the first elseif and in the third one for the last three. In my opinion is the most efficient way to do it.

Ya, I guess that would be the best way to go for now. Thanks again.
User avatar
Curveballs On Phoenix
 
Posts: 3365
Joined: Sun Jul 01, 2007 4:43 am

Post » Mon Nov 19, 2012 2:03 pm

Do this in two steps. In some other script that runs outside of combat or at the start of combat the script checks the faction of the NPC.

This could be using the story manger or a AOE spell or a cloak spell what ever...


THEN if they are in the faction you are looking for put them in your new faction on the fly. NOW when they get hit you can check for that one faction quickly. I do this kind of thing all the time and it works well.
User avatar
Jack Walker
 
Posts: 3457
Joined: Wed Jun 06, 2007 6:25 pm


Return to V - Skyrim