Alias Swapping Script Question

Post » Tue Jan 08, 2013 4:02 pm

Hey! I'm currently working on some custom script, and I've kind of hit a brick wall in my progress so I wanted to get some opinions and advice.

What I am essentially trying to do is to switch AI Packages between three unique NPCs that I have via dialogue. I have created a Start Game Enabled quest, and created an alias for each of these NPCs. I've put a custom AI Package into each of the aliases to fit what I would like the NPCs to do. These are three guards with specific duties (either to do a melee training, ranged training, or idle marker package), and the way this is supposed to work is that when you talk to guard A, you will be given the option through dialogue to tell him to either switch duties with guard B or guard C. This works the same way for all guards, and just by conditioning the different dialogue selections with alias checks they each have two options.

For each of these options, I have a very similar code that I use to swap these aliases between the two NPCs that are supposed to based on the dialogue selection, which I will post below.

Spoiler
;BEGIN FRAGMENT Fragment_0Function Fragment_0(ObjectReference akSpeakerRef)Actor akSpeaker = akSpeakerRef as Actor;BEGIN CODEif (MeleeTrainer.GetActorRef().GetDialogueTarget() == Game.GetPlayer())			 GuardToSwitch = RangedTrainer.GetRef()			 RangedTrainer.ForceRefTo(MeleeTrainer.GetRef())			 MeleeTrainer.ForceRefTo(GuardToSwitch)			 MeleeTrainer.TryToEvaluatePackage()			 RangedTrainer.TryToEvaluatePackage()			 GetOwningQuest().SetStage(0)endifif (BarracksCook.GetActorRef().GetDialogueTarget() == Game.GetPlayer())			 GuardToSwitch = RangedTrainer.GetRef()			 RangedTrainer.ForceRefTo(BarracksCook.GetRef())			 BarracksCook.ForceRefTo(GuardToSwitch)			 BarracksCook.TryToEvaluatePackage()			 RangedTrainer.TryToEvaluatePackage()			 GetOwningQuest().SetStage(0)endif;END CODEEndFunction;END FRAGMENT;END FRAGMENT CODE - Do not edit anything between this and the begin commentReferenceAlias Property MeleeTrainer  Auto  ReferenceAlias Property RangedTrainer  Auto  ReferenceAlias Property BarracksCook  Auto  ObjectReference Property GuardToSwitch  Auto  

So basically I have the three reference aliases defined, plus a placeholder variable to hold the Actor value of the NPC which will be switched after he is forced out of his original reference. Each of these are just fragments that I put at the end of the dialogue. I have the if statements to decipher which NPC the user is talking to before any switch occurs.

I've check out the code down to the finest point, and I can see no issues with it. However, the behavior in game is, well, odd to say the least. In various runs through with this particular dialogue (switching either the melee training guard or cook to the archer), I can successfully boot up the game walk up to the melee guard, talk to him, tell him to switch to the archer, and it works. The names switch on the aliases, their dialogue options change, and they change their package as well. Here is where it gets odd.

Say I boot up, run to the cook, tell him to switch to ranged training. He himself will switch to the ranged training, but when I inspect the other two guards, the ranged trainer changed to the melee alias, and the melee alias changes to the cooking alias. I am at a complete loss, as upon reviewing my code the melee trainer is not even present within the cooks if statement, yet somehow he gets tangled into this switch.

Another example: After sucessfully switching the ranged and melee aliases using this code, if I talk to the new melee NPC, and try to switch him back to the archer (effectively reversing the first, successful switch), the code just seems to break down like above, only this time the new melee NPC randomly becomes the cook, the cook becomes the archer, and the archer becomes the melee.

I feel like this is either my lack of understanding of this code I have begun to fiddle with, or some extremely minute detail that I am missing. I can't say that each of the three sets of dialogue all behave in the same way. Some are successful on their first attempts, and some are not, but what I can definitely say is that it appears that with multiple switches there always seems to be a breakdown. Is there something being stored in a variable or reference somewhere in the code that is being preserved somehow and then screwing up some of the switches? Is it an issue to use the same Property names for all of the dialogue options? Am I just using this script in some unorthodox way that is making the CK gods angry? There just seems to be no definitely pattern to the way its working so I feel like something is happening behind the scenes that I am overlooking, but I can't put my finger on it.

Its quite a complicated issue, but if anybody can give any advice, if you have perhaps done alias switching or used any of these seemingly less used scripts, it would be a huge help.

Thanks!
User avatar
Kat Ives
 
Posts: 3408
Joined: Tue Aug 28, 2007 2:11 pm

Post » Tue Jan 08, 2013 12:44 pm

JustinOther says do not use Game.GetPlayer(). Well, he says don't use it with intern referencs, only thoose existing outside. But in this case, it doesn't matter.

I think you should try it with Actor Propertys instead of Reference Aliases. Since you are using the actors on dialogue, you'll need to singularily define, right?
User avatar
Laura-Lee Gerwing
 
Posts: 3363
Joined: Fri Jan 12, 2007 12:46 am

Post » Tue Jan 08, 2013 11:27 pm

Thanks, I'm going to give this a shot and see. I've currently progressed to the stage where I can successfully switch the aliases for both of these instances I posted above on the first try, but it all goes to hell if I try any switches after that. I'll see if that change helps at all.
User avatar
Blackdrak
 
Posts: 3451
Joined: Thu May 17, 2007 11:40 pm


Return to V - Skyrim