[NOOB] Need help dynamically attaching scripts.

Post » Sun Nov 18, 2012 7:25 am

Hi , I have been using the tutorial on dynamically attaching scripts in the wiki to try to get the town guards to give out to the player if the player is detected while sneaking by the guards.

So I created a formlist and filled it with the generic guards (and my own test npc),
I created a trigger box around my actors and attached this script to it:

ScriptName SneakingSuspisionScript extends ObjectReferenceQuest Property CrimeOverhaul AutoEvent OnTriggerEnter(ObjectReference PlayerRef)				if Game.GetPlayer()==PlayerRefCrimeOverhaul.Start()elseendIfEndEventEvent OnTriggerLeave(ObjectReference PlayerRef)if Game.GetPlayer()==PlayerRefCrimeOverhaul.Stop()elseendIfEndEvent

I created a new quest called CrimeOverhaul, created an alias, chose Find Matching Reference and ticked the In Loaded Area and Closest boxes, created a match condition "IsInList GuardFormList == 1" and attached this script:

ScriptName GuardSuspisous extends ReferenceAliasint iIndexActor PlayerRefActor GuardFormList Property GuardFormList autoQuest Property CrimeOverhaul autoEvent OnInit()   PlayerRef = Game.GetPlayer()		while CrimeOverhaul.IsRunning()==true				while PlayerRef.IsSneaking()==true						 iIndex = GuardFormList.GetSize()						 while iIndex > 0								  iIndex -= 1								  Guard = GuardFormList.GetAt(iIndex) as Actor								  if PlayerRef.IsDetectedBy(Guard)==true										  Utility.Wait(3)										  if PlayerRef.IsDetectedBy(Guard)==true												   Guard.SendTrespassAlarm(PlayerRef)										  else										  endIf								   else								   endIf						  endWhile				  endWhile	  	   endWhileEndEvent

Can anyone can point out the (probably) obvious mistakes, please? Because its not working and I cannot figure out why.

P.S. Sorry about the awful indenting, its very late and I am really tired.
User avatar
WYatt REed
 
Posts: 3409
Joined: Mon Jun 18, 2007 3:06 pm

Post » Sun Nov 18, 2012 8:55 am

This first thing i see :

You use an oninit and OniNit is started when the game is lauch
Using Quest start/stop have no effect on OnInit

use an OnUpdate for 2 raison
http://www.creationkit.com/OnUpdate_-_Form

1 - You can start and stop the quest for clear information
2 - You don't need your While it's take to much computer memorie you can just update your script every 0s



if Game.GetPlayer()==PlayerRef
CrimeOverhaul.Start()
CrimeOverhaul.RegisterForUpdate(0)
endIf


If your script don't work, use Debug.messagebox for now what is probleme
http://www.creationkit.com/MessageBox_-_Debug


iIndex = GuardFormList.GetSize()
Debug.messagebox(iIndex) ; return Iindex value





PS you don't need ELSE if you have no action with it
User avatar
Sophie Louise Edge
 
Posts: 3461
Joined: Sat Oct 21, 2006 7:09 pm

Post » Sun Nov 18, 2012 12:15 pm

Ok, thanks. For some reason I thought OnInit runs every time the quest starts. I was using message boxes and I figured it had something to do with the first script but I didnt know what.
User avatar
Bethany Short
 
Posts: 3450
Joined: Fri Jul 14, 2006 11:47 am


Return to V - Skyrim