Jump to content

[LE] What is wrong with my script ? :) [4]


Recommended Posts

I just want to know your opinion about my Events

i Never before use so many Events in single Script and so many States

 

 

im doing good or bad ? :tongue:

 

my Script:

 

 

Scriptname QLG_Script_SwitchLight extends ObjectReference  
{ Usage tutorial:
	1) Create 3 FormList
	2) Import Objects from "Cell View" Window to FormLists
	- One for Lights
	- One for Static while lights are ON
	- One for Static while lights are OFF
	3) Attach this script to any TriggerBox or Activator
	4) Save your changes in Creation Kit
	
This script support up to 120 Lights !

  
  Warrning:
   Remember that Light and Static OFF and ON have to be this same ID
   for example if we have 3 lights and let's call them:
    = Light 1, Static 1 ( in one location )
    = Light 2, Static 2 ( in other location )
    = Light 3, Static 3 ( in even other location )
   Form list need to have this same Order !...
   if we had for example Form Lists
    = FormLights >> Light 1, Light 2, Light 3
    = FormStatic >> Static 2, Static 1, Static 3
   Like you can see we have bad items order Light 1 is attach to Static 2
  

This Script was Create to Switch Many lights in same time 
 Want to Switch single light? 
 - QLG_Script_SwitchLightSignel
 - QLG_Script_SwitchLightAdvance }
;===- Base Info. -===;
 ;Created: 2019-03-17
 ;Update: 2019-03-23
 ;Author: TobiPL
 ;Unit: M.PC<3>
;===- Var. setup -============================================


;===- Items Var. ===

	FormList Property QLights auto
	{ List of Used Lights }
	
	FormList Property QStaticON auto
	{ List of Used Static Meshes that show on Enable }
	
	FormList Property QStaticOFF auto
	{ List of Used Static Meshes that show on Disable }
	
	Bool Property QPlayerOnly auto
	{ If set to True only Player can Activate Script }
	

;===- TurnOff Var. ===
	
	Float Property QTurnOffDelay auto
	{ Time in Game Hours after Light go off 
		: Set this to 0 for random !... 
		: Value 0.5 mean 30 Game Min !... }
	
	Float Property QTurnOff auto
	{ If this set to True Lights go off after time }
	
	Int Property QTurnOffAMT auto
	{ This value decide how many lights go off each refresh }
	
	Bool Property QAllowRe auto
	{ Set this value to True if Lights should Turn ON
		Once Player Enter this same Trigger Again }

	Bool QIsBussy = false
	; Only for Time Regiesters // Do not change !...
	
	Int QLightsLeft = 0
	; Control how many lights left to Turn off



;===- Script -Main- -================================================
Event OnInit()
	If ( QIsBussy ) 
		GoToState( "QState_Bussy" )
	Else 
		GoToState( "QState_Waiting" )
	EndIf
EndEvent
;====================================================================



; State - Waiting for player to enter Trigger
State QState_Waiting
	Event OnTriggerEnter( ObjectReference QRef )
		If ( !QPlayerOnly )
			Return
		EndIf
		
		
		
		If ( QTurnOffDelay <= 1 )
			RegisterForUpdateGameTime( Utility.RandomInt( 0 , 120 ) )
		Else
			RegisterForUpdateGameTime( QTurnOffDelay )
		EndIf
		
		
		
		QL_TurnLightsON()
		QIsBussy = true
		GoToState( "QState_Bussy" )
		
	EndEvent
EndState



; State - ights Activated, waiting to Turn them OFF or Enter Player
State QState_Bussy
	Event OnTriggerEnter( ObjectReference QRef )
		If ( QAllowRe )
			
			QL_TurnLightsON()
			
		Else
			
			; Do Nothing if already working
			; Or Write anything You want
			
		EndIf
	EndEvent
EndState



; Event on Game Time - Turn off few lights etc.
Event OnUpdateGameTime()
	QL_TurnFewLightsOff()
	
	If ( QLightsLeft <= 0 )
		
		GoToState( "QState_Waiting" )
		QIsBussy = false
		UnregisterForUpdateGameTime()
		
	EndIf
EndEvent





;====================================================================
Function QL_TurnFewLightsON()

EndFunction



Function QL_TurnLightsON()
	int I = QLights.GetSize()
	
	QLightsLeft = I
	
	While ( I >=0 )
		I -= 1
		
		   ( QLights.GetAt(I) as ObjectReference ).Enable( true )
		 ( QStaticON.GetAt(I) as ObjectReference ).Enable( true )
		( QStaticOFF.GetAt(I) as ObjectReference ).Disable( true )
		
	EndWhile
EndFunction





; Special value for TurnOffLighsts Functions
	Int ReFreshLimit = 32
	; Limit for ReFresh
	; After this time Lights goes off

Function QL_TurnFewLightsOff()
	int I = QLights.GetSize()
	int Loop = 0
	int Random = 0
	
	While ( Loop < QTurnOffAMT )
		Random = Utility.RandomInt( 0 , I )
		
		If ( ( QLights.GetAt( Random ) as ObjectReference ).IsEnabled() )
			
			  ( QLights.GetAt( Random ) as ObjectReference ).Disable( true )
			( QStaticON.GetAt( Random ) as ObjectReference ).Disable( true )
			
			Utility.Wait( 1.4 )
			
			( QStaticOFF.GetAt( Random ) as ObjectReference ).Enable( true )
			
		EndIf
		
		Utility.Wait( 4.3 )
	
		Loop += 1
	EndWhile
	
	ReFreshLimit -= 1
	If ( ReFreshLimit <=0 )
		QL_TurnLightsOFF()
	EndIf
EndFunction



Function QL_TurnLightsOff()
	int I = QLights.GetSize()
	
	QLightsLeft = 0
	
	While ( I >=0 )
		I -= 1
		
		   ( QLights.GetAt(I) as ObjectReference ).Disable( true )
		 ( QStaticON.GetAt(I) as ObjectReference ).Disable( true )
		( QStaticOFF.GetAt(I) as ObjectReference ).Enable( true )
		
	EndWhile
EndFunction



 

 

 

What Tobi want to know: ( lel xD )

1) if Event is OUT of any State it is possible to activate this event all time?

2) Better is using on Time update or Game Hours update?

3) Unregister event is in good place?

 

Anything that i should know to make this script good?

 

//Edit: Script Update !

//Edit2: Script Update ! < now im testing this script InGame >

//Edit3: Script Update ! < new Spoiler and left old Script >

 

New Script ( Edit 3 )

 

 

Scriptname QLG_Script_SwitchLight extends ObjectReference  
{ Usage tutorial:
	1) Create 3 FormList
	2) Import Objects from "Cell View" Window to FormLists
	- One for Lights
	- One for Static while lights are ON
	- One for Static while lights are OFF
	3) Attach this script to any TriggerBox or Activator
	4) Save your changes in Creation Kit
	
This script support up to 120 Lights !

  
  Warrning:
   Remember that Light and Static OFF and ON have to be this same ID
   for example if we have 3 lights and let's call them:
    = Light 1, Static 1 ( in one location )
    = Light 2, Static 2 ( in other location )
    = Light 3, Static 3 ( in even other location )
   Form list need to have this same Order !...
   if we had for example Form Lists
    = FormLights >> Light 1, Light 2, Light 3
    = FormStatic >> Static 2, Static 1, Static 3
   Like you can see we have bad items order Light 1 is attach to Static 2
  

This Script was Create to Switch Many lights in same time 
 Want to Switch single light? 
 - QLG_Script_SwitchLightSignel
 - QLG_Script_SwitchLightAdvance }
;===- Base Info. -===;
 ;Created: 2019-03-17
 ;Update: 2019-03-23
 ;Author: TobiPL
 ;Unit: M.PC<3>
;===- Var. setup -============================================


;===- Items Var. ===

	FormList Property QLights auto
	{ List of Used Lights }
	
	FormList Property QStatic auto
	{ List of Used Static Meshes }
	
	Bool Property QPlayerOnly auto
	{ If set to True only Player can Activate Script }
	

;===- TurnOff Var. ===
	
	Float Property QTurnOffDelay auto
	{ Time in Game Hours after Light go off 
		: Set this to 0 for random !... 
		: Value 0.5 mean 30 Game Min !... }

	
	Int Property QTurnOffAMT auto
	{ This value decide how many lights go off each refresh }
	
	Bool Property QTurnOff auto
	{ If this set to True Lights go off after time }
	
	Bool Property QAllowRe auto
	{ Set this value to True if Lights should Turn ON
		Once Player Enter this same Trigger Again }

	Bool QIsBussy = false
	; Only for Time Regiesters // Do not change !...
	
	Int QLightsLeft = 0
	; Control how many lights left to Turn off



;===- Script -Main- -================================================
Event OnInit()
	If ( QIsBussy ) 
		GoToState( "QState_Bussy" )
	Else 
		GoToState( "QState_Waiting" )
		QL_TurnLightsOff()
	EndIf
EndEvent
;====================================================================



; State - Waiting for player to enter Trigger
State QState_Waiting
	Event OnTriggerEnter( ObjectReference QRef )
		;If ( !QPlayerOnly )
		;	Return
		;EndIf
		
		
		
		If ( QTurnOffDelay <= 1 )
			RegisterForUpdateGameTime( Utility.RandomInt( 0 , 120 ) )
		Else
			RegisterForUpdateGameTime( QTurnOffDelay )
		EndIf
		
		
		
		QL_TurnLightsON()
		QIsBussy = true
		GoToState( "QState_Bussy" )
		
	EndEvent
EndState



; State - ights Activated, waiting to Turn them OFF or Enter Player
State QState_Bussy
	Event OnTriggerEnter( ObjectReference QRef )
		If ( QAllowRe )
			
			QL_TurnLightsON()
			
		Else
			
			; Do Nothing if already working
			; Or Write anything You want
			
		EndIf
	EndEvent
EndState



; Event on Game Time - Turn off few lights etc.
Event OnUpdateGameTime()
	QL_TurnFewLightsOff()
	
	If ( QLightsLeft <= 0 )
		
		GoToState( "QState_Waiting" )
		QIsBussy = false
		UnregisterForUpdateGameTime()
		
	EndIf
EndEvent





;====================================================================
Function QL_TurnFewLightsON()

EndFunction



Function QL_TurnLightsON()
	int I = QLights.GetSize()
	
	QLightsLeft = I
	
	While ( I >=0 )
		I -= 1
		
		 ( QLights.GetAt(I) as ObjectReference ).Enable( true )
		 ( QStatic.GetAt(I) as ObjectReference ).Enable( true )
		
	EndWhile
EndFunction





; Special value for TurnOffLighsts Functions
	Int ReFreshLimit = 32
	; Limit for ReFresh
	; After this time Lights goes off

Function QL_TurnFewLightsOff()
	int I = QLights.GetSize()
	int Loop = 0
	int Random = 0
	
	While ( Loop < QTurnOffAMT )
		Random = Utility.RandomInt( 0 , I )
		
		If ( ( QLights.GetAt( Random ) as ObjectReference ).IsEnabled() )
			
			( QLights.GetAt( Random ) as ObjectReference ).Disable( true )
			( QStatic.GetAt( Random ) as ObjectReference ).Disable( true )
			
		EndIf
		
		Utility.Wait( 4.3 )
	
		Loop += 1
	EndWhile
	
	ReFreshLimit -= 1
	If ( ReFreshLimit <=0 )
		QL_TurnLightsOFF()
	EndIf
EndFunction



Function QL_TurnLightsOff()
	int I = QLights.GetSize()
	
	QLightsLeft = 0
	
	While ( I >=0 )
		I -= 1
		
		( QLights.GetAt(I) as ObjectReference ).Disable( true )
		( QStatic.GetAt(I) as ObjectReference ).Disable( true )
		
	EndWhile
EndFunction


 

 

 

 

 

Script is working Fine light turn ON and turn OFF randomly

but idk why they turning ON one by one not all in same time :/...

Edited by TobiaszPL
Link to comment
Share on other sites

"Script is working Fine light turn ON and turn OFF randomly

but idk why they turning ON one by one not all in same time :/..."

That's the same problem i encountered with a similar Script i made for a cell with around 120 lights and their according static meshes (2 meshes per light).

The worst i encountered was that sometimes some lights (randomly) weren't synchronize with their according meshes, so you could see a light turning on but the actual lighted mesh would get in "enable state" a little bit later or vice versa..... - No Synchronization.

So i end up seperating the script and the functions to be handle by different activators and link lights & meshes to groups of xMarkers & xMarkers activators. Now everything works perfectly and synchronize, like a Swiss clock.

Sometimes is better not to let a single script handle everything, especially if you're dealing with a large - massive number of objects that they all need to do something at the same time.

Edited by maxarturo
Link to comment
Share on other sites

10 Lights and 10 Static :P

I dont have problem with Synchronization or i dont saw any while testing my script

 

but they should show in same second

Skyrim can't change 20 items in one sec ? :P OK xD

 

it should work like this:

<time> <des>

9:00 Player Enter Trigger and burn 5 Lights

10:00 One random light go OFF

12:00 Two random lights go OFF

13:00 One Random light go OFF

14:00 Last light go OFF

 

but if i enter Trigger lights go ON one by one

9:00 One Light go ON

9:01 One Light go ON

9:02 One Light go ON

...

...

 

this also look good but i want to add NICE *BOOM* effect to this when Lights got Fire up

Link to comment
Share on other sites

Question: Do all the lights in the form list eventually turn on?

 

If yes, the reason they do not all turn on at once is because the form list is being ran through and each light is turned on in sequence.

 

If you want, instantly, every light to turn on at the exact moment (barring any engine limitations to maximum number of lights) a different approach should be taken.

 

Place an xMarker and link all lights and corresponding statics. Be sure to set the xMarker as the "Enable State Parent" of each one.

Then instead of cycling the form list to turn on the lights, simply enable / disable the xMarker as needed. All the attached lights should turn on and off accordingly.

 

This is the same approach used by the game to enable all the objects associated with purchasing a home upgrade.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...