TobiaszPL Posted April 11, 2019 Share Posted April 11, 2019 (edited) This time something VERY hard xD Here is Script: Scriptname QLG_Script_SwitchLight extends ObjectReference { !:! This Script Support only 32 Objects !:! } Import Sound ;===- Base Info. -===; ;Created: 2019-03-17 ;Update: 2019-04-11 ;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 } ;================================================ ;===- Main Script -============================== ;***********************************************; Event OnInit() If( FirstUse ) Constructor() FirstUse = true EndIf If( QFired ) GoToState( "QState_Working" ) Else GoToState( "QState_Ready" ) EndIf EndEvent;==- Var. List -==; Bool FirstUse = true ; ;*************************; State Wait ; Do Nothing EndState ;================================================ ;***********************************************; State QState_Ready Event OnTriggerEnter( ObjectReference QRef ) If( ( QRef != QPlayer ) || ( !QFired ) ) Return EndIf QFired = true; QLFireUp() RegisterForSingleUpdateGameTime( QTurnOffDelay ) GoToState( "QState_Working" ) EndEvent EndState;==- Var. List -==; ;*************************; Bool QFired = false; ; ;================================================ ;***********************************************; State QState_Working Event OnUpdateGameTime() If( QLUpdateFire() ) RegisterForSingleUpdateGameTime( QTurnOffDelay ) Else QFired = false; UnregisterForUpdateGameTime() GoToState( "QState_Ready" ) 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.2 ) 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.3 ) ; Wait Data[1].Disable( true ) ; Disable Effect Data[2].Enable( true ) ; Enable Static Data[3].Enable() ; Enable Sound Marker Utility.Wait( 1.7 ) ; 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( 1.7 ) ; 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() DataSize /= 4 While ( T < DataSize ) QDataArray[ 4 * T + 0 ] = QData.GetAt( T ) as ObjectReference QDataArray[ 4 * T + 1 ] = QData.GetAt( T ) as ObjectReference QDataArray[ 4 * T + 2 ] = QData.GetAt( T ) as ObjectReference QDataArray[ 4 * T + 3 ] = 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 !... Anything to Fix ? :Di Mean how it work no how it look :smile: ReDragon <3 xDD //Edit:lel xD Few stupid misstakes :D//Edit2:Constructor was never in use xD//Edit3:More Fixes :D ! yey xDomfg i was working for last 11 h... even this small code take 3h xDi go 4 something to Eat and GL with looking for more bad in Code :D and TY 4 help if any1 want to help with this ugly code xD ugly cause lel... can't use classes and structures T_T Edited April 11, 2019 by TobiaszPL Link to comment Share on other sites More sharing options...
Evangela Posted April 11, 2019 Share Posted April 11, 2019 (edited) QDataArray[ 4 * T + 0 ] = QData.GetAt( T ) as ObjectReferenceQDataArray[ 4 * T + 1 ] = QData.GetAt( T ) as ObjectReferenceQDataArray[ 4 * T + 2 ] = QData.GetAt( T ) as ObjectReferenceQDataArray[ 4 * T + 3 ] = QData.GetAt( T ) as ObjectReference You may have problems with this. I know a guy way back who did. Papyrus arrays behave as expected which there is only 1 thing going on in the brackets(for lack of better term), but add a second thing and it gets weird from there. Basically Array[index, value, value] is buggy, unless it was fixed. Edited April 11, 2019 by Rasikko Link to comment Share on other sites More sharing options...
TobiaszPL Posted April 11, 2019 Author Share Posted April 11, 2019 QDataArray[ ( ( 4 * T ) + 0 ) ]Will be better ? xD or Int Temp 4 * TTemp += 0 ; or 1 2 3QDaraArray[ Temp ] Link to comment Share on other sites More sharing options...
ReDragon2013 Posted April 11, 2019 Share Posted April 11, 2019 yours Event OnInit() If( FirstUse ) Constructor() FirstUse = true EndIf If( QFired ) GoToState( "QState_Working" ) Else GoToState( "QState_Ready" ) EndIf EndEvent;==- Var. List -==; Bool FirstUse = trueshould be as follow Event OnInit() If( FirstUse ) else Constructor() FirstUse = true EndIf If( QFired ) GoToState( "QState_Working" ) Else GoToState( "QState_Ready" ) EndIf EndEvent;==- Var. List -==; Bool FirstUse = False Link to comment Share on other sites More sharing options...
ReDragon2013 Posted April 11, 2019 Share Posted April 11, 2019 (edited) You wrote: "i Mean how it work no how it look"Keep in mind If it looks better, its much better to maintain the code! I changed as follow, for studying only. That are technical changes, not really content improvements. ; https://forums.nexusmods.com/index.php?/topic/7559996-what-is-wrong-with-my-script-6/ Bool FirstUse = False Bool QFired = False ; -- EVENTs -- EVENT OnInit() IF ( FirstUse ) ELSE FirstUse = TRUE Constructor() ENDIF IF ( QFired ) gotoState("QState_Working") ; ### STATE ### ELSE gotoState("QState_Ready") ; ### STATE ### ENDIF ENDEVENT ;====================================== State Wait ;========= endState ;================================================ State QState_Ready ;================= EVENT OnTriggerEnter(ObjectReference triggerRef) IF ( QFired ) RETURN ; - STOP - already triggered by the player ENDIF ;--------------------- IF (triggerRef == Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - not the player ENDIF ;--------------------- QFired = TRUE QLFireUp() gotoState("QState_Working") ; ### STATE ### RegisterForSingleUpdateGameTime( QTurnOffDelay ) ENDEVENT ;======= endState ;================================================ State QState_Working ;=================== EVENT OnUpdateGameTime() IF QLUpdateFire() RegisterForSingleUpdateGameTime( QTurnOffDelay ) RETURN ; - STOP - update again ENDIF ;--------------------- QFired = False UnregisterForUpdateGameTime() gotoState("QState_Ready") ; ### STATE ### ENDEVENT ;======= endState ;--------------------------- Bool FUNCTION QLUpdateFire() ;--------------------------- int r = QChain_GetRandomID() ; r = Temp int c = QChain_GetAt(r) * 4 ; c = MyID objectReference[] b = new ObjectReference [4] ; b = TempArray int i = 0 WHILE (i < 4) b[i] = QDataArray[c+i] ; 0 = light, 1 = effect, 2 = static, 3 = sound i = i + 1 ENDWHILE QLPlayFireOut(b) QChain_RemoveID(r) IF (AMT > 0) Return TRUE ENDIF Return False ENDFUNCTION ; -- FUNCTIONs -- ObjectReference[] QDataArray ; -- Item Structure -- Int[] NextID ; Next ItemID Int[] PrevID ; Prev ItemID Int[] RefID ; Value to ObjectID ; -- Free Strusture -- Int[] List ; List of free ItemIDs Int FirstFree ; First free ItemID ; -- Variable 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 ;--------------------- FUNCTION Constructor() ;--------------------- NextID = new Int [ 32 ] PrevID = new Int [ 32 ] RefID = new Int [ 32 ] List = new Int [ 32 ] QDataArray = new ObjectReference [ 128 ] ; ---------------------------------------- int iMax = QData.GetSize() / 4 ; iMax = DataSize int i = 0 ; i = T WHILE (i < iMax) objectReference oRef = QData.GetAt(i) as ObjectReference IF ( oRef ) int n = i * 4 int nMax = n + 4 WHILE (n < nMax) QDataArray[n] = oRef n = n + 1 ENDWHILE ENDIF i = i + 1 ENDWHILE ; ---------------------------------------- FirstFree = Size - 1 ; ** set script variable ** i = 0 WHILE (i < Size) List[i] = FirstFree - i ; ( Size - i ) - 1 NextID[i] = 0 PrevID[i] = 0 RefID[i] = 1 i = i + 1 ENDWHILE AMT = 0 LastUsed = 0 FirstID = 0 LastID = 0 ENDFUNCTION ;---------------------------------------- Bool FUNCTION QChain_Add( Int iNewValue ) ;---------------------------------------- IF (AMT >= Size) Return False ; /1 ENDIF ;--------- int c = List[ FirstFree ] ; c = NewItemID PrevID[ FirstID ] = c NextID[ LastID ] = c NextID[c] = FirstID PrevID[c] = LastID RefID[c] = iNewValue LastID = c FirstFree -= 1 AMT += 1 Return TRUE ; /2 ENDFUNCTION ;-------------------------------- Int FUNCTION QChain_GetRandomID() ;-------------------------------- int iMax = Utility.RandomInt(0 , AMT) ; iMax = Rand int c = FirstID ; c = Temp int i = 0 WHILE (i < iMax) c = NextID[c] i = i + 1 ENDWHILE RETURN c ENDFUNCTION ;---------------------------------- Int FUNCTION QChain_GetAt( Int ID ) ;---------------------------------- int c = FirstID ; c = ItemID int i = 0 WHILE (i < AMT) c = NextID[ FirstID ] IF (c == ID) RETURN RefID[c] ; /1 ENDIF i = i + 1 ENDWHILE RETURN -1 ; /2 ENDFUNCTION ;-------------------------------------- Bool FUNCTION QChain_RemoveID( Int ID ) ;-------------------------------------- IF (AMT <= 0) Return False ; /1 ENDIF ;--------- int c = FirstID ; c = ItemID int i = 0 WHILE (i < AMT) IF (c == ID) AMT -= 1 FirstFree += 1 List[ FirstFree ] = c NextID[ PrevID[c] ] = NextID[c] PrevID[ NextID[c] ] = PrevID[c] IF (c == FirstID) FirstID = NextID[c] ENDIF IF (c == LastID) LastID = PrevID[c] ENDIF Return TRUE ; /2 ENDIF c = NextID[c] i = i + 1 ENDWHILE Return False ; /3 ENDFUNCTION Edited April 11, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
Recommended Posts