Jump to content

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


Recommended Posts

What is wrong with my Script? xD

i finally had some time so i was able to test my script

 

annnnnddd its not working... half working half not

 

Script "ToDo"

1) Turn Lights on

2) Wait

3) Turn Light off

4) if any lights left go to 2)

5) turn off

 

lights turn ON fine but disabling them are not working...

 

Amount of lights change so script is working fine but light and fire are still enabled but they should be disabled xD

 

here is script, few of you know this script already :D

 

 

Scriptname QLG_Script_SwitchLight extends ObjectReference  
{ Script to Light Up all Lights in List and turn them out after Time
	This script is created by TobiPL for Braverock 3 }
Import Sound
;===- Base Info. -===;
 ;Created: 2019-03-17
 ;Update: 2019-04-19
 ;Author: TobiPL
 ;Unit: M.PC<1>
;===- Var. setup -============================================
	Actor Property QPlayer Auto
	{ Player Ref. }
;===- Items Var. -===============================
;***********************************************;
	FormList Property QData auto
	{ List of Used items
		<< Order >>
		 :0: - Light
		 :1: - Light Effect
		 :2: - Static
		 :3: - Sound Marker }
	ObjectReference[] QDataArray
	
	Sound Property QSoundFireUp Auto
	{ Sound to Play on fire activate }
	
	Sound Property QSoundFireOut Auto
	{ Sound to Play on fire deactivate }

	Float Property QTurnOffDelay auto
	{ Time in GameH to Off Light, 0.5 Mean 30 Min }
	
	Float Property QTrunOffMin Auto
	{ Min. in GameH time to Off Light, after this use only Delay }
	
	GlobalVariable Property QDebug Auto
	{ Global, true/false to show Debug Notifications ! 
		please, use "QLG_DEBUG_SCRIPT" }
;================================================
;===- Main Script -==============================
;***********************************************;
Event OnInit()
	If( QDebug as bool )
		Debug.Notification( "Starting Initialization" )
			EndIf
	;*********************************;
	If( FirstUse )
			Constructor()
			FirstUse = false
	EndIf
	If( QFired )
		GoToState( "QState_Working" )
			Else
		GoToState( "QState_Ready" )
	EndIf
	;*********************************;
	If( QDebug as bool )
		Debug.Notification( "Initialization Finished" ) 
			EndIf
EndEvent;==- Var. List -==;
	Bool FirstUse = true
	;
;*************************;
	State Wait
		; Do Nothing
	EndState
;================================================
;***********************************************;
State QState_Ready
	Event OnTriggerEnter( ObjectReference QRef )
		If( QRef != QPlayer )
			Return
		EndIf
		
		If( QDebug as bool )
		Debug.Notification( "Triggered QLG_Script_SwitchLight" ) 
			EndIf
	
		QFired = true;
		GoToState( "QState_Working" )
		QLFireUp()
		RegisterForSingleUpdateGameTime( QTurnOffDelay + QTrunOffMin )
		
	EndEvent
EndState;==- Var. List -==;
;*************************;
	Bool QFired = false;
	;
;================================================
;***********************************************;
State QState_Working
	Event OnUpdateGameTime()
		If( QLUpdateFire() )
			RegisterForSingleUpdateGameTime( QTurnOffDelay )
			
			If( QDebug as bool )
				Debug.Notification( "Update Fire, Fires left: " + AMT )
			EndIf
		Else
			QFired = false;
			UnregisterForUpdateGameTime()
			GoToState( "QState_Ready" )
			
			If( QDebug as bool )
				Debug.Notification( "Fire out" )
			EndIf
		EndIf
	EndEvent
EndState;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Bool Function QLUpdateFire()
	Int Temp = QChain_GetRandomID()
	Int MyID = QChain_GetAt( Temp )
	
	ObjectReference[] TempArray
	TempArray = new ObjectReference [ 4 ]	; Light, Effect, Static, Sound
	
	TempArray[ 0 ] = QDataArray[ 4 * MyID ]
	TempArray[ 1 ] = QDataArray[ 4 * MyID + 1 ]
	TempArray[ 2 ] = QDataArray[ 4 * MyID + 2 ]
	TempArray[ 3 ] = QDataArray[ 4 * MyID + 3 ]
	
	QLPlayFireOut( TempArray )
	QChain_RemoveID( Temp )
	
		If( AMT == 0 )
			Return False
		EndIf
	Return true
EndFunction;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Function QLFireUp()
	ObjectReference[] TempArray
	TempArray = new ObjectReference [ 4 ]	; Light, Effect, Static, Sound
	
	Int DataSize = QData.GetSize()
		DataSize /= 4
	Int i = 0
	While ( i < DataSize )
		TempArray[ 0 ] = QDataArray[ 4 * i ]
		TempArray[ 1 ] = QDataArray[ 4 * i + 1 ]
		TempArray[ 2 ] = QDataArray[ 4 * i + 2 ]
		TempArray[ 3 ] = QDataArray[ 4 * i + 3 ]
		
		QChain_Add( i )
		QLPlayFireUp( TempArray )
		Utility.Wait( 0.1 )
		
		i += 1
	EndWhile
EndFunction;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Function QLPlayFireUp( ObjectReference[] Data )
	Int SoundTemp = QSoundFireUp.Play( Data[2] )
		Data[0].Enable( true )		; Enable Light
		Data[1].Enable( true )		; Enable Effect
	
		Utility.Wait( 0.1 )		; Wait
	
		Data[1].Disable( true )		; Disable Effect
		Data[2].Enable( true )		; Enable Static
		Data[3].Enable()			; Enable Sound Marker
		
		Utility.Wait( 0.2 )		; Wait
	StopInstance( SoundTemp )
EndFunction;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Function QLPlayFireOut( ObjectReference[] Data )
	Int SoundTemp = QSoundFireOut.Play( Data[2] )
		Data[2].Disable( true )		; Disable Static
		
		Utility.Wait( 0.3 )		; Wait
		
		Data[0].Disable( true )		; Disable Light
		Data[3].Disable( true )		; Disable Sound Marker
		
		Utility.Wait( 0.3 )		; Wait
	StopInstance( SoundTemp )
EndFunction
;==========================================================
;*******************************************************************;
;===- Class QChain -=================================================
;*******************************************************************;
;==========================================================
		; Item Structure ;		;
			Int[] NextID		; Next Item ID
			Int[] PrevID		; Prev Item ID
			Int[] RefID			; Value to Object ID
	;*******************************************;
		; Free Strusture ;		;
			Int[] List			; List of Free IDs
			Int First			; First Free ID
	;*******************************************;
		; Var. List ;			;
			Int LastUsed		; Last Used Item
			Int FirstID			; First Item
			Int LastID			; Last Item
			Int AMT				; Amount Of Items
			Int Size = 32		; Size of Array
	;*******************************************;
;================================================
;***********************************************;
Int Function QChain_GetRandomID()
	Int Temp = FirstID
	Int Rand = Utility.RandomInt( 0 , AMT )
	Int i = 0
		While ( I < Rand )
			Temp = NextID[ Temp ]
			i += 1
		EndWhile
	Return Temp
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Int Function QChain_GetAt( Int ID )
	Int i = 0
	Int ItemID = FirstID
		While ( I < AMT )
			ItemID = NextID[ FirstID ]
			If( ItemID == ID )
				Return RefID[ ItemID ]
			EndIf
			i += 1
		EndWhile
	Return -1
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Bool Function QChain_Add( int NewValue )
		If( AMT == Size )
			Return false
		EndIf
		
		int NewItemID = List[ First ]
		
		PrevID[ FirstID ] = NewItemID
		NextID[ LastID ] = NewItemID
		
		NextID[ NewItemID ] = FirstID
		PrevID[ NewItemID ] = LastID
		RefID[ NewItemID ] = NewValue
		
		LastID = NewItemID;
    
		First -= 1
		AMT += 1
		
		Return true
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Bool Function QChain_RemoveID( int ID )
		If( AMT == 0 )
			Return false
		EndIf
		int ItemID = FirstID
		Int i = 0
		While ( i < AMT )
			If( ID == ItemID )
				
				AMT -= 1
				First += 1
				List[ First ] = ID
				NextID[ PrevID[ ItemID ] ] = NextID[ ItemID ]
				PrevID[ NextID[ ItemID ] ] = PrevID[ ItemID ]
				
				If( ItemID == FirstID )
						FirstID = NextID[ ItemID ]
					EndIf
				If( ItemID == LastID )
						LastID = PrevID[ ItemID ]
					EndIf
				Return true
			EndIf
			ItemID = NextID[ ItemID ]
			i += 1
		EndWhile
	Return false
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Function Constructor()
	NextID = new Int [ 32 ]
	PrevID = new Int [ 32 ]
	RefID = new Int [ 32 ]
	List = new Int [ 32 ]
	QDataArray = new ObjectReference [ 128 ]

	Int T = 0
	Int DataSize = QData.GetSize()
	While ( T < DataSize )
		QDataArray[ T ] = QData.GetAt( T ) as ObjectReference
		T += 1
	EndWhile
	
	First = Size - 1
	
	Int i = 0
		While ( i < Size )
			List[i] = ( Size - i ) - 1 ;
			NextID[i] = 0;
			PrevID[i] = 0;
			RefID[i] = 1;
			i += 1
		EndWhile
	AMT = 0;
	LastUsed = 0;
	FirstID = 0;
	LastID = 0;
EndFunction
;***********************************************;
;=============- QChain Class END -==============;
;***********************************************;
; Hello I'm Tobi and my Sexy Cat is Nicole !... 

 

 

 

but problem is probably around those functioons:

 

Function to Update fire: ( working fine, probably )

 

 

Bool Function QLUpdateFire()
	Int Temp = QChain_GetRandomID()
	Int MyID = QChain_GetAt( Temp )
	
	ObjectReference[] TempArray
	TempArray = new ObjectReference [ 4 ]	; Light, Effect, Static, Sound
	
	TempArray[ 0 ] = QDataArray[ 4 * MyID ]
	TempArray[ 1 ] = QDataArray[ 4 * MyID + 1 ]
	TempArray[ 2 ] = QDataArray[ 4 * MyID + 2 ]
	TempArray[ 3 ] = QDataArray[ 4 * MyID + 3 ]
	
	QLPlayFireOut( TempArray )
	QChain_RemoveID( Temp )
	
		If( AMT == 0 )
			Return False
		EndIf
	Return true
EndFunction 

 

 

 

Function to play OFF: ( not working, change Amount ( VAR AMT ) but objects are still enabled )

 

 

Function QLPlayFireOut( ObjectReference[] Data )
	Int SoundTemp = QSoundFireOut.Play( Data[2] )
		Data[2].Disable( true )		; Disable Static
		
		Utility.Wait( 0.3 )		; Wait
		
		Data[0].Disable( true )		; Disable Light
		Data[3].Disable( true )		; Disable Sound Marker
		
		Utility.Wait( 0.3 )		; Wait
	StopInstance( SoundTemp )
EndFunction 

 

 

 

 

any help pls? xD

why lights stay enabled???

 

 

//Edit:

ok something is bad with GetAt Function...

//Edit2:

ofc. with my GetAt xD QChain_GetAT()

//Edit3:

ok QChain_GetAT() is Good, its something wrong with QChain_GetRandom() xDD

//Edit4:

ok... GetAt was bad and GetRandom was good :D lel xD

 

anyway here is working code:

 

 

Scriptname QLG_Script_SwitchLight extends ObjectReference  
{ Script to Light Up all Lights in List and turn them out after Time
	This script is created by TobiPL for Braverock 3 }
Import Sound
;===- Base Info. -===;
 ;Created: 2019-03-17
 ;Update: 2019-04-19
 ;Author: TobiPL
 ;Unit: M.PC<1>
;===- Var. setup -============================================
	Actor Property QPlayer Auto
	{ Player Ref. }
;===- Items Var. -===============================
;***********************************************;
	FormList Property QData auto
	{ List of Used items
		<< Order >>
		 :0: - Light
		 :1: - Light Effect
		 :2: - Static
		 :3: - Sound Marker }
	ObjectReference[] QDataArray
	
	Sound Property QSoundFireUp Auto
	{ Sound to Play on fire activate }
	
	Sound Property QSoundFireOut Auto
	{ Sound to Play on fire deactivate }

	Float Property QTurnOffDelay auto
	{ Time in GameH to Off Light, 0.5 Mean 30 Min }
	
	Float Property QTrunOffMin Auto
	{ Min. in GameH time to Off Light, after this use only Delay }
	
	GlobalVariable Property QDebug Auto
	{ Global, true/false to show Debug Notifications ! 
		please, use "QLG_DEBUG_SCRIPT" }
;================================================
;===- Main Script -==============================
;***********************************************;
Event OnInit()
	If( QDebug as bool )
		Debug.Notification( "Starting Initialization" )
			EndIf
	;*********************************;
	If( FirstUse )
			Constructor()
			FirstUse = false
	EndIf
	If( QFired )
		GoToState( "QState_Working" )
			Else
		GoToState( "QState_Ready" )
	EndIf
	;*********************************;
	If( QDebug as bool )
		Debug.Notification( "Initialization Finished" ) 
			EndIf
EndEvent;==- Var. List -==;
	Bool FirstUse = true
	;
;*************************;
	State Wait
		; Do Nothing
	EndState
;================================================
;***********************************************;
State QState_Ready
	Event OnTriggerEnter( ObjectReference QRef )
		If( QRef != QPlayer )
			Return
		EndIf
		
		If( QDebug as bool )
		Debug.Notification( "Triggered QLG_Script_SwitchLight" ) 
			EndIf
	
		QFired = true;
		GoToState( "QState_Working" )
		QLFireUp()
		RegisterForSingleUpdateGameTime( QTurnOffDelay + QTrunOffMin )
		
	EndEvent
EndState;==- Var. List -==;
;*************************;
	Bool QFired = false;
	;
;================================================
;***********************************************;
State QState_Working
	Event OnUpdateGameTime()
		If( QLUpdateFire() )
			RegisterForSingleUpdateGameTime( QTurnOffDelay )
			
			If( QDebug as bool )
				Debug.Notification( "Update Fire, Fires left: " + AMT )
			EndIf
		Else
			QFired = false;
			UnregisterForUpdateGameTime()
			GoToState( "QState_Ready" )
			
			If( QDebug as bool )
				Debug.Notification( "Fire out" )
			EndIf
		EndIf
	EndEvent
EndState;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Bool Function QLUpdateFire()
	Int Rand = QChain_GetRandomID()
	
	If( QDebug as bool )
		Debug.Notification( "Fire Update, ID: " + Rand )
	EndIf
	
	ObjectReference[] TempArray
	TempArray = new ObjectReference [ 4 ]	; Light, Effect, Static, Sound
	
	TempArray[ 0 ] = QDataArray[ 4 * Rand ]
	TempArray[ 1 ] = QDataArray[ 4 * Rand + 1 ]
	TempArray[ 2 ] = QDataArray[ 4 * Rand + 2 ]
	TempArray[ 3 ] = QDataArray[ 4 * Rand + 3 ]
	
	If( ( TempArray[0] ) || ( TempArray[1] ) || ( TempArray[2] ) || ( TempArray[3] ) )
		Debug.Notification( "Fire Update, All Objects are Good" )
			Else
		Debug.Notification( "Fire Update, Few Objects are Bad" )
	EndIf
	
	QLPlayFireOut( TempArray )
	QChain_RemoveID( Rand )
	
		If( AMT == 0 )
			Return False
		EndIf
	Return true
EndFunction;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Function QLFireUp()
	ObjectReference[] TempArray
	TempArray = new ObjectReference [ 4 ]	; Light, Effect, Static, Sound
	
	Int DataSize = QData.GetSize()
		DataSize /= 4
	Int i = 0
	While ( i < DataSize )
		TempArray[ 0 ] = QDataArray[ 4 * i ]
		TempArray[ 1 ] = QDataArray[ 4 * i + 1 ]
		TempArray[ 2 ] = QDataArray[ 4 * i + 2 ]
		TempArray[ 3 ] = QDataArray[ 4 * i + 3 ]
		
		If( ( TempArray[0] ) || ( TempArray[1] ) || ( TempArray[2] ) || ( TempArray[3] ) )
			Debug.Notification( "Fire UP, All Objects are Good" )
				Else
			Debug.Notification( "Fire UP, Few Objects are Bad" )
		EndIf
		
		QChain_Add( i )
		QLPlayFireUp( TempArray )
		Utility.Wait( 0.1 )
			
		i += 1
		If( QDebug as bool )
			Debug.Notification( "Fire Created, ID: " + i )
		EndIf
	EndWhile
EndFunction;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Function QLPlayFireUp( ObjectReference[] Data )
	Int SoundTemp = QSoundFireUp.Play( Data[2] )
		Data[0].Enable( true )		; Enable Light
		Data[1].Enable( true )		; Enable Effect
	
		Utility.Wait( 0.1 )		; Wait
	
		Data[1].Disable( true )		; Disable Effect
		Data[2].Enable( true )		; Enable Static
		Data[3].Enable()			; Enable Sound Marker
		
		Utility.Wait( 0.2 )		; Wait
	StopInstance( SoundTemp )
EndFunction;==- Var. List -==;
	;
	;
;================================================
;***********************************************;
Function QLPlayFireOut( ObjectReference[] Data )
	Int SoundTemp = QSoundFireOut.Play( Data[2] )
		Data[2].Disable( true )		; Disable Static
		
		Utility.Wait( 0.3 )		; Wait
		
		Data[0].Disable( true )		; Disable Light
		Data[3].Disable( true )		; Disable Sound Marker
		
		Utility.Wait( 0.3 )		; Wait
	StopInstance( SoundTemp )
EndFunction
;==========================================================
;*******************************************************************;
;===- Class QChain -=================================================
;*******************************************************************;
;==========================================================
		; Item Structure ;		;
			Int[] NextID		; Next Item ID
			Int[] PrevID		; Prev Item ID
			Int[] RefID			; Value to Object ID
	;*******************************************;
		; Free Strusture ;		;
			Int[] List			; List of Free IDs
			Int First			; First Free ID
	;*******************************************;
		; Var. List ;			;
			Int LastUsed		; Last Used Item
			Int FirstID			; First Item
			Int LastID			; Last Item
			Int AMT				; Amount Of Items
			Int Size = 32		; Size of Array
	;*******************************************;
;================================================
;***********************************************;
Int Function QChain_GetRandomID()
	Int Temp = FirstID
	Int Rand = Utility.RandomInt( 0 , AMT )
	Int i = 0
		While ( i < Rand )
			Temp = NextID[ Temp ]
			i += 1
		EndWhile
	Return RefID[ Temp ]
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Bool Function QChain_Add( int NewValue )
		If( AMT == Size )
			Return false
		EndIf
		
		int NewItemID = List[ First ]
		
		PrevID[ FirstID ] = NewItemID
		NextID[ LastID ] = NewItemID
		
		NextID[ NewItemID ] = FirstID
		PrevID[ NewItemID ] = LastID
		RefID[ NewItemID ] = NewValue
		
		LastID = NewItemID;
    
		First -= 1
		AMT += 1
		
		Return true
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Bool Function QChain_RemoveID( int ID )
		If( AMT == 0 )
			Return false
		EndIf
		int ItemID = FirstID
		Int i = 0
		While ( i < AMT )
			If( ID == ItemID )
				
				AMT -= 1
				First += 1
				List[ First ] = ID
				NextID[ PrevID[ ItemID ] ] = NextID[ ItemID ]
				PrevID[ NextID[ ItemID ] ] = PrevID[ ItemID ]
				
				If( ItemID == FirstID )
						FirstID = NextID[ ItemID ]
					EndIf
				If( ItemID == LastID )
						LastID = PrevID[ ItemID ]
					EndIf
				Return true
			EndIf
			ItemID = NextID[ ItemID ]
			i += 1
		EndWhile
	Return false
EndFunction
;_______________________________________________;
;===============================================;
;***********************************************;
Function Constructor()
	NextID = new Int [ 32 ]
	PrevID = new Int [ 32 ]
	RefID = new Int [ 32 ]
	List = new Int [ 32 ]
	QDataArray = new ObjectReference [ 128 ]

	Int T = 0
	Int DataSize = QData.GetSize()
	While ( T < DataSize )
		QDataArray[ T ] = QData.GetAt( T ) as ObjectReference
		T += 1
	EndWhile
	
	First = Size - 1
	
	Int i = 0
		While ( i < Size )
			List[i] = ( Size - i ) - 1 ;
			NextID[i] = 0;
			PrevID[i] = 0;
			RefID[i] = 1;
			i += 1
		EndWhile
	AMT = 0;
	LastUsed = 0;
	FirstID = 0;
	LastID = 0;
EndFunction
;***********************************************;
;=============- QChain Class END -==============;
;***********************************************;
; Hello I'm Tobi and my Sexy Cat is Nicole !... 

 

 

 

Ty all 4 help :D

 

lel xDD

 

and if anything is still wrong in my code you can post it here :D lel xD

 

#BadEnglish xD

Edited by TobiaszPL
Link to comment
Share on other sites

  • Recently Browsing   0 members

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