TobiaszPL Posted June 23, 2019 Share Posted June 23, 2019 (edited) Hey... i create Small script for campfires Script have to do:1) Enable Fire Animation and Light2) Wait random time3) Disable Fire Animation and Light it seems easy to do but my Script is not working :c...Not working all time... it is working for first 2/3 activations but after 2/3 activationsLight show normaly but Fire Animation dont... Maybe important to know, on Screen i have around 10/15 "campfires"is that bad ? ;x... Skyrim can't support so many scripts at once???? lol??? Here is script that i use: ( and which i test ) Scriptname QLG_SimpleScript_Campfire extends ObjectReference { Simple script to enable Fire for while :x... } Import Sound ;===- Base Info. -===; ;Created: 2019-06-22 ;Update: 2019-06-23 ( TobiPL ) ;Author: TobiPL ;Unit: M.PC<3> ;===- Var. setup -==================================================; ObjectReference Property QFireRef Auto { Object Ref. to Fire ( Enable/Disable ) } ObjectReference Property QFireSrc Auto { Object Ref. to Fire Light source } Sound Property QFireUp Auto { Sound to play on Fire Up } Sound Property QFireOut Auto { Sound to play on Fire Out } ;===============================================; ;===- Main Script -=============================; ;***********************************************; Event OnActivate( ObjectReference QRef ) Int SoundINS = QFireUp.Play( self ) QFireRef.enable( true ) QFireSrc.enable( true ) self.disable() Utility.Wait( 3 ) StopInstance( SoundINS ) Utility.Wait( Utility.RandomInt( 120 , 360 ) ) SoundINS = QFireOut.Play( self ) QFireRef.disable( true ) QFireSrc.disable( true ) Utility.Wait( 3 ) StopInstance( SoundINS ) self.enable() EndEvent ;The End And Here is script that i think ill be using ( cause its less... bad :x... ) Scriptname QLG_SimpleScript_Campfire extends ObjectReference { Simple script to enable Fire for while :x... } Import Sound ;===- Base Info. -===; ;Created: 2019-06-22 ;Update: 2019-06-24 ( TobiPL ) ;Author: TobiPL ;Unit: M.PC<3> ;===- Var. setup -==================================================; ObjectReference Property QFireRef Auto { Object Ref. to Fire ( Enable/Disable ) } ObjectReference Property QFireSrc Auto { Object Ref. to Fire Light source } Sound Property QFireUp Auto { Sound to play on Fire Up } Sound Property QFireOut Auto { Sound to play on Fire Out } ;===============================================; ;===- Main Script -=============================; ;***********************************************; Event OnInit() GoToState( "Ready" ) EndEvent ;***********************************************; State Ready Event OnActivate( ObjectReference QRef ) GoToState( "Wait" ) QLFireUp() Utility.Wait( Utility.RandomInt( 120 , 360 ) ) QLFireOut() GoToState( "Ready" ) EndEvent EndState ;***********************************************; State Wait ; Do Nothing EndState ;***********************************************; ;===- Sound and Animation Fire Up -===**********; Function QLFireUp() self.disable() Int SoundINS = QFireUp.Play( self ) QFireRef.enable( true ) QFireSrc.enable( true ) Utility.Wait( 3 ) StopInstance( SoundINS ) EndFunction ;***********************************************; ;===- Sound and Animation Fire Out -===*********; Function QLFireOut() self.enable() Int SoundINS = QFireUp.Play( self ) QFireRef.disable( true ) QFireSrc.disable( true ) Utility.Wait( 3 ) StopInstance( SoundINS ) EndFunction ;The End Why after 2/3 Uses Fire Animation don't show?im using vanilla Fire Animation from Movable Objets //Edit:can any1 change title to: "What is wrong with my script ? :) [10]"[9] index is already in use xDDDDDD Edited June 23, 2019 by TobiaszPL Link to comment Share on other sites More sharing options...
IsharaMeradin Posted June 24, 2019 Share Posted June 24, 2019 10 ~ 15 campfires in one cell? I would say that there is a bit of lag going on there. By using the Wait function you are making each instance pause for that amount of time. While paused the script still takes up a processing thread and this will eventually lead to issues. I recommend registering for either a single game time update or real time update.RegisterForSingleUpdate paired with OnUpdateRegisterForSingleUpdateGameTime paired with OnUpdateGameTime Link to comment Share on other sites More sharing options...
ReDragon2013 Posted June 24, 2019 Share Posted June 24, 2019 (edited) Keep in mind there is a chance that a campfire will be detaching during the waittime, so we have to use the holder of sound instances as script variables. You could use something like this:QLG_SimpleCampfireScript Scriptname QLG_SimpleCampfireScript extends ObjectReference { Simple script to enable Fire for while :x... } ; https://forums.nexusmods.com/index.php?/topic/7760353-what-is-wrong-with-my-script-9/ ;===- Base Info. -===; ;Created: 2019-06-22 ;Update: 2019-06-24 ( TobiPL ) ;Author: TobiPL ;Unit: M.PC<3> ObjectReference PROPERTY QFireRef auto { ObjectRef to Fire ( Enable/Disable ) } ObjectReference PROPERTY QFireSrc auto { ObjectRef to Fire Light source } Sound PROPERTY QFireUp auto ; to play on Fire Up Sound PROPERTY QFireOut auto ; to play on Fire Out Int i1 Int i2 ;===- Main Script -=============================; EVENT OnInit() Debug.Trace("OnInit() has been reached.. " +self) ENDEVENT EVENT OnActivate(ObjectReference akActionRef) gotoState("Busy") ; ### STATE ### QLFireUp() Utility.Wait(3.0) myF_Stop(i1) ; * i1 = 0 ; * ENDEVENT ;======================= State Busy ;========== EVENT OnActivate(ObjectReference akActionRef) ENDEVENT EVENT OnCellDetach() UnRegisterForUpdate() ; throw away the current waiting for OnUpdate() event myF_Stop(i1) ; * safety first i1 = 0 ; * QFireRef.Disable(TRUE) QFireSrc.Disable(TRUE) myF_Stop(i2) ; ** safety first i2 = 0 ; ** gotoState("") ; ### STATE ### back to no state ENDEVENT EVENT OnUpdate() gotoState("") ; ### STATE ### back to no state QLFireOut() Utility.Wait(3.0) myF_Stop(i2) ; ** i2 = 0 ; ** ENDEVENT ;======= endState ; -- FUNCTIONs -- 3 ;----------------------- FUNCTION myF_Stop(Int i) ;----------------------- IF (i > 0) Sound.StopInstance(i) ; stop sound instance, if any exists ENDIF ENDFUNCTION ;------------------ FUNCTION QLFireUp() ;------------------ ;;; self.Disable() i1 = QFireUp.Play(self as ObjectReference) ; play "fire up" sound float f = Utility.RandomFloat(120.0, 360.0) ; wait about 2..6 min RegisterForSingleUpdate(f) QFireRef.Enable(TRUE) QFireSrc.Enable(TRUE) ENDFUNCTION ;------------------- FUNCTION QLFireOut() ;------------------- ;;; self.Enable() i2 = QFireOut.Play(self as ObjectReference) ; play "fire out" sound QFireRef.Disable(TRUE) QFireSrc.Disable(TRUE) ENDFUNCTION Edited June 24, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
TobiaszPL Posted June 24, 2019 Author Share Posted June 24, 2019 (edited) IsharaMeradinIll try with OnUpdate but srsl... Games normaly can use up to 200/400 that small scripts at once...It Just Works =_= egh... https://www.youtube.com/watch?v=YPN0qhSyWy8 I never had so many problems with UE4 or Unity or my Own Engine ( Silent Dream Engine < whut a name :o )CK is broken T_T how they even create wor.... ahh right... Skyrim is also not working fine :x... lel ReDragon2013You change Your write style or i learn already how to read your Code :tongue:but your code is missing self.enable() / self.disable() << this line enable / disable trigger box that allow player to use script How about this Code: ? Scriptname QLG_SimpleScript_Campfire extends ObjectReference { Simple script to enable Fire for while :x... } Import Sound ;===- Base Info. -===; ;Created: 2019-06-22 ;Update: 2019-06-24 ( TobiPL ) ;Author: TobiPL ;Unit: M.PC<3> ;===- Var. setup -==================================================; ObjectReference Property QFireRef Auto { Object Ref. to Fire ( Enable/Disable ) } ObjectReference Property QFireSrc Auto { Object Ref. to Fire Light source } Sound Property QFireUp Auto { Sound to play on Fire Up } Sound Property QFireOut Auto { Sound to play on Fire Out } Int SoundINS = 0 ;===============================================; ;===- Main Script -=============================; ;***********************************************; Event OnInit() ; nothing atm. ( Edit :D ) EndEvent ;***********************************************; Event OnActivate( ObjectReference QRef ) GoToState( "Wait" ) QLFireUp() EndEvent ;***********************************************; State Wait Event OnCellDetach() UnRegisterForUpdate() QLFireOut() GoToState( "" ) EndEvent ;=**********************=; Event OnUpdate() QLFireOut() GoToState( "" ) EndEvent EndState ;***********************************************; ;===- Sound and Animation Fire Up -===**********; Function QLFireUp() self.disable() float Temp = Utility.RandomFloat(120.0, 360.0) RegisterForSingleUpdate( Temp ) SoundINS = QFireUp.Play( self ) QFireRef.enable( true ) QFireSrc.enable( true ) Utility.Wait( 2.0 ) StopInstance( SoundINS ) EndFunction ;***********************************************; ;===- Sound and Animation Fire Out -===*********; Function QLFireOut() SoundINS = QFireUp.Play( self ) QFireRef.disable( true ) QFireSrc.disable( true ) Utility.Wait( 2.0 ) StopInstance( SoundINS ) self.enable() EndFunction ;The End I change it to OnUpdate like Ishara saysand i add OnCellDetach like ReDragon shows :x... can't test it now :c... Edited June 24, 2019 by TobiaszPL Link to comment Share on other sites More sharing options...
Recommended Posts