pepperman35 Posted May 28, 2021 Author Share Posted May 28, 2021 Thanks all. I think a slight adaption of DieFeM's script posted here should work nicely: https://forums.nexusmods.com/index.php?/topic/7904323-how-to-have-script-timer-reset-or-restart/ Now for implementation and testing :laugh: Interesting enough, I am actually starting to grasp this scripting stuff (sort off). The last code writing I did was in FORTRAN...oh my. Link to comment Share on other sites More sharing options...
pepperman35 Posted May 28, 2021 Author Share Posted May 28, 2021 Testing has went well. While I still need to develop the function for constructing sentry towers, here is the script as it currently stands. Scriptname MysticLake:MLS_ConstructProtocolScript extends ObjectReference ; ;-- Properties -------------------------------------- GlobalVariable Property pMLS_DormConstructState Auto Const Mandatory GlobalVariable Property pMLS_ATechConstructState Auto Const Mandatory GlobalVariable Property pMLS_SentryConstructState Auto Const Mandatory GlobalVariable Property pMLS_MysticLakeWSState Auto Const Mandatory Keyword Property pWorkshopItemKeyword Auto Const Mandatory Message Property pMLS_CmdCntrTerminalNoWorkshop Auto Const Mandatory Message Property pMLS_InsufficientResourcesMsg01 Auto Const Mandatory Message Property pMLS_InsufficientResourcesMsg02 Auto Const Mandatory Component Property c_Concrete Auto Const Mandatory Component Property c_Steel Auto Const Mandatory ObjectReference Property MLS_DormConstructEnabler Auto Const Mandatory ObjectReference Property MLS_ATechConstructEnabler Auto Const Mandatory ObjectReference Property MLS_DormCollision Auto Const Mandatory ; ;-- Variables --------------------------------------- ; Int PercentComplete = 0 Int ConstDuration = 30 ; duration of the timed event in hours (25% of 5 days) Int MyTimerID = 10 ; Unique ID for the time Int ATechConstFlag = 0 Int DormConstFlag = 0 Int SecurityConstFlag = 0 ; ;-- Functions --------------------------------------- ; ; Function to facilitate dormitory construction ; Function DormConstruct() ; Debug.Trace("MLS_ConstructionProtocolScript.DormConstruct Function has been called", 0) If (pMLS_DormConstructState.GetValue() == 0 as float) DormConstFlag = 0 ObjectReference ThisWorkshop = Self.GetLinkedRef(pWorkshopItemKeyword) If (ThisWorkshop == None) ;Debug.Trace("MLS_ConstructionProtocolScript.DormConstruct ERROR NoWorkshop", 0) pMLS_CmdCntrTerminalNoWorkshop.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) Else ; Test to see if player has requisite materials ObjectReference PlayerRef = Game.GetPlayer() If (PlayerRef.getitemcount(c_Concrete as Form) >= 3016 && PlayerRef.getitemcount(c_Steel as Form) >= 934) PlayerRef.removeitem(c_Concrete as Form, 3016, False, None) PlayerRef.removeitem(c_Steel as Form, 934, False, None) DormConstFlag = 1 ConstructionTimer() ElseIf (ThisWorkshop.getitemcount(c_Concrete as Form) >= 3016 && ThisWorkshop.getitemcount(c_Steel as Form) >= 934) ThisWorkshop.removeitem(c_Concrete as Form, 3016, False, None) ThisWorkshop.removeitem(c_Steel as Form, 934, False, None) DormConstFlag = 1 ConstructionTimer() Else ;Debug.Trace("MLS_ConstructionProtocolScript.DormConstruct ERROR InsufficientResources", 0) pMLS_InsufficientResourcesMsg01.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) EndIf EndIf EndIf EndFunction ; ; Function to facilitate sentry tower construction ; ;Function SentryConstruct() ;If (pMLS_SentryConstructState.GetValue() == 0 as float) ;EndFunction ; ; Function to facilitate construction of Aqua Technologies ; Function AquaTechConstruct() ; Debug.Trace("MLS_ConstructionProtocolScript.AquaTechConstruct Function has been called", 0) If (pMLS_ATechConstructState.GetValue() == 0 as float) ATechConstFlag = 0 ObjectReference ThisWorkshop = Self.GetLinkedRef(pWorkshopItemKeyword) If (ThisWorkshop == None) ;Debug.Trace("MLS_ConstructionProtocolScript.AquaTechConstruct ERROR NoWorkshop", 0) pMLS_CmdCntrTerminalNoWorkshop.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) Else pMLS_MysticLakeWSState.SetValue(1 as float) ; Test to see if player has requisite materials ObjectReference PlayerRef = Game.GetPlayer() If (PlayerRef.getitemcount(c_Concrete as Form) >= 4000 && PlayerRef.getitemcount(c_Steel as Form) >= 5000) PlayerRef.removeitem(c_Concrete as Form, 4000, False, None) PlayerRef.removeitem(c_Steel as Form, 5000, False, None) ; Call the construction functions ATechConstFlag = 1 ConstructionTimer() ElseIf (ThisWorkshop.getitemcount(c_Concrete as Form) >= 4000 && ThisWorkshop.getitemcount(c_Steel as Form) >= 5000) ThisWorkshop.removeitem(c_Concrete as Form, 4000, False, None) ThisWorkshop.removeitem(c_Steel as Form, 5000, False, None) ATechConstFlag = 1 ; Call the construction functions ConstructionTimer() Else ;Debug.Trace("MLS_ConstructionProtocolScript.AquaTechConstruct ERROR InsufficientResources", 0) pMLS_InsufficientResourcesMsg02.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) EndIf EndIf EndIf EndFunction ; ; Construction timer functions ; Function ConstructionTimer() PercentComplete = 0; Set the percent completion to 0 Debug.Notification("Construction at Mystic Lake has begun. Completion expected in " +(ConstDuration * 4)/24+ "days.") Debug.Trace("Construction at Mystic Lake has begun. Completion expected in " +(ConstDuration * 4)/24+ "days.") StartTimerGameTime(ConstDuration, MyTimerID); Start a timer. EndFunction ; ;-- Events --------------------------------------- ; Event OnTimerGameTime(int aiTimerID) If aiTimerID == MyTimerID ; if this is my timer (not necessary since this script only has 1 timer, but its a good practice). PercentComplete += 25; Increment by 25% Debug.Notification("Construction project at Mystic Lake is " +PercentComplete+ "%") Debug.Trace("Construction project at Mystic Lake is " +PercentComplete+ "%") If PercentComplete < 100; if percent complete is less than 100 start the timer again StartTimerGameTime(ConstDuration, MyTimerID) Else If (ATechConstFlag ==1) MLS_ATechConstructEnabler.Enable() ; Disable the collision marker so NPC can access dormitory ; MLS_DormCollision.disable() pMLS_ATechConstructState.SetValue(1 as float) ElseIf (DormConstFlag ==1) MLS_DormConstructEnabler.Enable() ; Disable the collision marker so NPC can access dormitory MLS_DormCollision.disable() pMLS_DormConstructState.SetValue(1 as float) ElseIf (SecurityConstFlag ==1) ; Do stuff ; Do more stuff EndIf EndIf EndIf EndEvent Link to comment Share on other sites More sharing options...
ReDragon2013 Posted May 30, 2021 Share Posted May 30, 2021 (edited) Probably you would have to use three different timer IDs to separate your construction, code as follow MysticLake:MLS_ConstructProtocolScript Scriptname MysticLake:MLS_ConstructProtocolScript extends ObjectReference ; https://forums.nexusmods.com/index.php?/topic/10071763-implementing-a-time-delay-to-emulate-building/page-2 GlobalVariable PROPERTY pMLS_DormConstructState auto GlobalVariable PROPERTY pMLS_ATechConstructState auto GlobalVariable PROPERTY pMLS_SentryConstructState auto GlobalVariable PROPERTY pMLS_MysticLakeWSState auto Const Mandatory ; ??? Message PROPERTY pMLS_CmdCntrTerminalNoWorkshop auto Message PROPERTY pMLS_InsufficientResourcesMsg01 auto ; dorm Message PROPERTY pMLS_InsufficientResourcesMsg02 auto ; atech ;Message PROPERTY pMLS_InsufficientResourcesMsg03 auto ; sentry Keyword PROPERTY pWorkshopItemKeyword auto Component PROPERTY c_Concrete auto Const Mandatory Component PROPERTY c_Steel auto Const Mandatory ObjectReference PROPERTY MLS_DormCollision auto ObjectReference PROPERTY MLS_DormConstructEnabler auto ObjectReference PROPERTY MLS_ATechConstructEnabler auto ;ObjectReference PROPERTY MLS_SentryConstructEnabler auto Float ConstDuration = 30.0 ; common linear duration of the timed event in hours (25% of 5 days, 24h * 5 = 120h / 4 = 30) Int[] aPC ; array to hold percentComplete values depends on constructed object Int tID_Dorm = 10 ; Unique ID for the timer Int tID_ATech = 20 Int tID_Secu = 30 ; -- EVENTs -- EVENT OnInit() aPC = new Int[3] ; aPC[0] - DormConstruct % ; aPC[1] - AquaTechConstruct % ; aPC[2] - SentryConstruct % ENDEVENT EVENT OnTimerGameTime(Int aiTimerID) ;==================== IF (aPC.Length <= 0) RETURN ; - STOP - array not initialized or mod has been removed! ENDIF ;--------------------- IF (aiTimerID == tID_Dorm) IF (myF_Percentage(0) < 100) ; percent complete is less than 100 start the timer again StartTimerGameTime(ConstDuration, aiTimerID) ELSE MLS_DormCollision.Disable() ; Disable the collision marker so NPC can access dormitory MLS_DormConstructEnabler.Enable() pMLS_DormConstructState.SetValue(1) ; Dorm constructed ENDIF RETURN ; - STOP - /1 ENDIF ;--------------------- IF (aiTimerID == tID_ATech) IF (myF_Percentage(1) < 100) StartTimerGameTime(ConstDuration, aiTimerID) ELSE ; Disable the collision marker so NPC can access dormitory ; MLS_DormCollision.disable() MLS_ATechConstructEnabler.Enable() pMLS_ATechConstructState.SetValue(1) ; ATech constructed ENDIF RETURN ; - STOP - /2 ENDIF ;--------------------- IF (aiTimerID == tID_Secu) IF (myF_Percentage(2) < 100) StartTimerGameTime(ConstDuration, aiTimerID) ELSE ENDIF ;;; RETURN ; - STOP - /3 ENDIF ;--------------------- ;; Debug.Trace(" OnTimerGameTime(" +aiTimerID+ ") - unknown timerID! " +self) ENDEVENT ; -- FUNCTIONs -- 3 + 3 ;--------------------------------- Int FUNCTION myF_Percentage(Int i) ; helper ;--------------------------------- int n = aPC[i] + 25 ; increase by 25 (percentage) --> 0, 25, 50, 75, 100 aPC[i] = n string s = "Construction project at Mystic Lake is " +n+ "%" Debug.Notification(s) Debug.Trace(s) RETURN n ; return new percentage ENDFUNCTION ;-------------------------------------- FUNCTION ConstructionTimer(Int timerID) ; helper ;-------------------------------------- StartTimerGameTime(ConstDuration, timerID) ; just a bit info here int i = ConstDuration / 6 ; (x * 4) / 24 == (x/6) --> 30 / 6 = 5 string s = "Construction at Mystic Lake has begun. Completion expected in " + i + "days." Debug.Notification(s) Debug.Trace(s) ENDFUNCTION ;----------------------------------------------------- FUNCTION myF_REM(ObjectReference oRef, Int nc, Int ns) ; helper ;----------------------------------------------------- oRef.RemoveItem(c_Concrete, nc, False, None) oRef.RemoveItem(c_Steel, ns, False, None) ENDFUNCTION ;----------------------- FUNCTION DormConstruct() ; to facilitate dormitory construction ;----------------------- ;; Debug.Trace("MLS_ConstructionProtocolScript.DormConstruct Function has been called", 0) IF (pMLS_DormConstructState.GetValue() == 0) ELSE RETURN ; - STOP - already under construction or constructed ENDIF ;--------------------- objectReference ThisWorkshop = self.GetLinkedRef(pWorkshopItemKeyword) IF ( ThisWorkshop ) ELSE ;; Debug.Trace("MLS_ConstructionProtocolScript.DormConstruct [ERROR-00] NoWorkshop", 0) pMLS_CmdCntrTerminalNoWorkshop.Show() ; <<< msg0 >>> RETURN ; - STOP - ENDIF ;===================== ; Test to see if player has requisite materials actor player = Game.GetPlayer() int nc = player.GetItemCount(c_Concrete) int ns = player.GetItemCount(c_Steel) IF (nc >= 3016) && (ns >= 934) myF_REM(player as ObjectReference, 3016, 934) ConstructionTimer( tID_Dorm ) pMLS_DormConstructState.SetValue(2) ; *2* under construction ELSE nc = ThisWorkshop.GetItemCount(c_Concrete) ns = ThisWorkshop.GetItemCount(c_Steel) IF (nc >= 3016) && (ns >= 934) myF_REM(ThisWorkshop, 3016, 934) ConstructionTimer( tID_Dorm ) pMLS_DormConstructState.SetValue(2) ; *2* under construction ELSE ;; Debug.Trace("MLS_ConstructionProtocolScript.DormConstruct [ERROR-01] InsufficientResources", 0) pMLS_InsufficientResourcesMsg01.Show() ; <<< msg1 >>> ENDIF ENDIF ENDFUNCTION ;--------------------------- FUNCTION AquaTechConstruct() ; to facilitate construction of Aqua Technologies ;--------------------------- ;; Debug.Trace("MLS_ConstructionProtocolScript.AquaTechConstruct Function has been called", 0) IF (pMLS_ATechConstructState.GetValue() == 0) ELSE RETURN ; - STOP - already under construction or constructed ENDIF ;--------------------- objectReference ThisWorkshop = self.GetLinkedRef(pWorkshopItemKeyword) IF ( ThisWorkshop ) ELSE ;; Debug.Trace("MLS_ConstructionProtocolScript.AquaTechConstruct [ERROR-00] NoWorkshop", 0) pMLS_CmdCntrTerminalNoWorkshop.Show() ; <<< msg0 >>> RETURN ; - STOP - ENDIF ;===================== pMLS_MysticLakeWSState.SetValue(1) ; *1* ??? ; Test to see if player has requisite materials actor player = Game.GetPlayer() int nc = player.GetItemCount(c_Concrete) int ns = player.GetItemCount(c_Steel) If (nc >= 4000) && (ns >= 5000) myF_REM(player as ObjectReference, 4000, 5000) ConstructionTimer( tID_ATech ) pMLS_ATechConstructState.SetValue(2) ; *2* under construction ELSE nc = ThisWorkshop.GetItemCount(c_Concrete) ns = ThisWorkshop.GetItemCount(c_Steel) IF (nc >= 4000) && (ns >= 5000) myF_REM(ThisWorkshop, 4000, 5000) ConstructionTimer( tID_ATech ) pMLS_ATechConstructState.SetValue(2) ; *2* under construction ELSE ;; Debug.Trace("MLS_ConstructionProtocolScript.AquaTechConstruct [ERROR-02] InsufficientResources", 0) pMLS_InsufficientResourcesMsg02.Show() ; <<< msg2 >>> ENDIF ENDIF ENDFUNCTION ;------------------------- FUNCTION SentryConstruct() ; to facilitate sentry tower construction ;------------------------- ;; Debug.Trace("MLS_ConstructionProtocolScript.SentryConstruct Function has been called", 0) IF (pMLS_SentryConstructState.GetValue() == 0) ELSE RETURN ; - STOP - already under construction or constructed ENDIF ;--------------------- objectReference ThisWorkshop = self.GetLinkedRef(pWorkshopItemKeyword) IF ( ThisWorkshop ) ELSE ;; Debug.Trace("MLS_ConstructionProtocolScript.SentryConstruct [ERROR-00] NoWorkshop", 0) pMLS_CmdCntrTerminalNoWorkshop.Show() ; <<< msg0 >>> RETURN ; - STOP - ENDIF ;===================== tID_Sentry, pMLS_InsufficientResourcesMsg03 ; code here ENDFUNCTION Edited May 30, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
pepperman35 Posted May 30, 2021 Author Share Posted May 30, 2021 Thanks ReDragon2013. Appreciate the time spent and code provided. A bit more sophisticated that mine to be sure. Link to comment Share on other sites More sharing options...
Recommended Posts