pepperman35 Posted October 11, 2021 Share Posted October 11, 2021 [WIP] Still fleshing out some details but the concept seems to be working. Basically on consuming the moonshine, an random effect is place on the player. No moonshine was consumed in the creation of this script [hiccup]. I am sure there is plenty room for improvement. Scriptname MysticLake:MoonshineEffectScript extends activemagiceffect ;The script lives on an effect associated with PeppersMoonshine (potion) ;which is available in the Mystic Lake Settlement mod ;When the player drinks the moonshine, a random effect is placed on them ;+--------------------------+ ;¦ PROPERTIES ¦ ;+--------------------------+ Bool Property bPlayerOnly = False auto const {Set this if you only want this Imod to play if the player is the spell caster.} float property fDelay = 0.83 auto const {time to wait before switching to constant Imod} ImageSpaceModifier property IntroFX auto const {IsMod applied at the start of the spell effect} ImageSpaceModifier property LoopFX auto const {main isMod for spell} ImageSpaceModifier property OutroFX auto const {IsMod applied at the end of the spell effect} Float Property fImodStrength = 1.0 auto const {IsMod Strength from 0.0 to 1.0} sound Property DrinkingSound Auto Const Mandatory {plays each drink} sound Property ChokingSoundMale Auto Const Mandatory sound Property ChokingSoundFemale Auto Const Mandatory {Plays after drinking} Keyword Property PlayerConsumeJet Auto Const VisualEffect Property DLC03ScreenDistortFX Auto Const Mandatory {Player visual effect } VisualEffect Property CameraAttachFogFX Auto Const Mandatory {Player visual effect} VisualEffect Property CameraAttachGroggyWake01FX Auto Const Mandatory {Player visual effect} VisualEffect Property CameraAttachGroggySleep01FX Auto Const Mandatory {Player visual effect} Message Property pMLS_MoonshineDemiseMsg Auto Const Mandatory {Message to display if the player dies from consuming the moonshine} Message Property pMLS_MoonshineBlackoutMsg Auto Const Mandatory {Message to display if the player passess out from consuming the moonshine} ObjectReference Property MLS_PassoutMarkerRef Auto Const Mandatory {Player teleports to this location after passing out} ImageSpaceModifier Property MLS_DoubleVisionImod Auto Const ImageSpaceModifier Property FadetoBlackImod Auto Const ImageSpaceModifier Property FadefromBlackImod Auto Const ImageSpaceModifier Property HoldAtBlackImod Auto Const ImageSpaceModifier Property FadefromBlackSlowImod Auto Const Message Property pMLS_MoonshineBlackoutMsg02 Auto Const Mandatory {Message to display as the player begins to regain consciousness} Armor Property pPipboyDusty Auto Const Mandatory ObjectReference Property pMLS_PlayersComfyBed Auto Const Mandatory inputenablelayer Property MLS_MoonshineLayer Auto Conditional Bool bIsOkToPlay = true bool bIsFinishing = false int iEffectToApply ;+--------------------------+ ;¦ STATES AND EVENTS ¦ ;+--------------------------+ auto State AllowDrinking Event OnEffectStart(Actor Target, Actor Caster) Actor PlayerRef = Game.GetPlayer() GoToState("Busy") if Caster == PlayerRef Utility.Wait(2.0) ; Player the drinking sound DrinkingSound.play(Caster) Utility.Wait(2.7) ; The moonshine is very strong so the player coughes a bit If (Game.GetPlayer().GetBaseObject() as ActorBase).GetSex() == 1 ChokingSoundFemale.play(PlayerRef) else ChokingSoundMale.play(PlayerRef) EndIf utility.Wait(2.0) ; Player likes the moonshine PlayerRef.SayCustom(PlayerConsumeJet) if bPlayerOnly if Caster != game.GetPlayer() bIsOkToPlay = False endif endif if bIsOkToPlay ;Kill Imods from another cast, if running. IntroFX.remove() LoopFX.remove() OutroFX.remove() ; apply isMod at full strength introFX.apply(fImodStrength) utility.wait(fDelay) if bIsFinishing == False ;LoopFX.apply() introFX.PopTo(LoopFX,fImodStrength) ; Select a random number between 1 and 20 iEffectToApply = Utility.RandomInt(1, 20) ; Random effects ; 50% chance of blurred vision ; 20% chance of having a hallucination ; 15% chance of double vision ; 10% chance of blacking out ; 5% chance of dying If iEffectToApply == 20 TriggerPlayerDeath(PlayerRef) ElseIf iEffectToApply >= 18 && iEffectToApply <= 19 TriggerPlayerPassout(PlayerRef, 1) ElseIf iEffectToApply >= 15 && iEffectToApply <= 17 TriggerPlayerDoubleVision(1) ElseIf iEffectToApply >= 11 && iEffectToApply <= 14 TriggerPlayerTripin(PlayerRef, 1) EndIf endif endif endif GoToState("AllowDrinking") EndEvent Event OnEffectFinish(Actor Target, Actor Caster) Actor PlayerRef = Game.GetPlayer() bIsFinishing = True if bIsOkToPlay ; play OutroSoundFX sound from my self ;int instanceID = OutroSoundFX.play((target as objectReference)) ; play OutroSoundFX sound from my self introFX.remove() ;LoopFX.remove() LoopFX.PopTo(OutroFX,fImodStrength) If iEffectToApply == 20 TriggerPlayerDeath(PlayerRef) ElseIf iEffectToApply >= 18 && iEffectToApply <= 19 TriggerPlayerPassout(PlayerRef, 2) ElseIf iEffectToApply >= 15 && iEffectToApply <= 17 TriggerPlayerDoubleVision(2) ElseIf iEffectToApply >= 11 && iEffectToApply <= 14 TriggerPlayerTripin(PlayerRef, 2) EndIf endif GoToState("AllowDrinking") endEvent EndState State Busy Event OnEffectStart(Actor Target, Actor Caster) ;Do nothing EndEvent EndState ;+--------------------------+ ;¦ FUNCTIONS ¦ ;+--------------------------+ ;Function TriggerRandomNumberGenerator(int iEffect) ;iEffect = Utility.RandomInt(1, 20) ;EndFunction Function TriggerPlayerTripin(Actor oRef, int DesiredEffect) If DesiredEffect == 1 ; Add the effect DLC03ScreenDistortFX.Play(oRef) ;Trigger the a hallucination effect ; TriggerHallucination() Else ; remove the effect DLC03ScreenDistortFX.Stop(oRef) EndIf EndFunction Function TriggerPlayerPassout(Actor oRef, int DesiredEffect) If DesiredEffect == 1 ; Add the effect Utility.Wait(2.5) ;Display a message - blackout imminent pMLS_MoonshineBlackoutMsg.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) ; Visual effect to illustate the lose of consciousness Game.FadeOutGame(abFadingOut=True, abBlackFade=True, afSecsBeforeFade=0.0, afFadeDuration=7.5, abStayFaded=True) ;CameraAttachGroggySleep01FX.Play(oRef) Utility.Wait(5.8) ; Visual effect to represent the player hitting the ground Game.ShakeCamera(afStrength = 1.0, afDuration = 1.0) Utility.Wait(1) ; Diasable player controls so they can't run off MLS_MoonshineLayer = InputEnableLayer.Create() MLS_MoonshineLayer.DisablePlayerControls() ; Player is teleported to the penthouse LoopFX.PopTo(HoldAtBlackImod,fImodStrength) oRef.SetEssential(true) Utility.Wait(5) oRef.MoveTo(MLS_PassoutMarkerRef) oRef.SetEssential(False) Else ; Consider addding a hangover spell ;PlayerRef.AddSpell(MLS_Hangover, false) PassGameTimeHours(1) ; Display message - Player regains consciousness pMLS_MoonshineBlackoutMsg02.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) ; Fade the scene in from blackness HoldAtBlackImod.PopTo(FadefromBlackSlowImod,fImodStrength) ; Strip player ddown to their scivvies, but add the pipboy back Utility.Wait(1) oRef.UnequipAll() oRef.AddItem(pPipboyDusty, absilent=true) oRef.EquipItem(pPipboyDusty, absilent=true) Utility.Wait(0.5) Game.ForceThirdPerson() MLS_MoonshineLayer.EnablePlayerControls() Utility.Wait(1) IntroFX.remove() LoopFX.remove() OutroFX.remove() EndIf EndFunction Function TriggerPlayerDoubleVision(int DesiredEffect) If DesiredEffect == 1 ; Add the effect MLS_DoubleVisionImod.ApplyCrossFade() Else ; remove the effect MLS_DoubleVisionImod.Remove() EndIf EndFunction Function TriggerPlayerDeath(Actor oRef) pMLS_MoonshineDemiseMsg.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) oRef.DamageValue(Game.GetHealthAV(), 1000000) EndFunction Bool Function PassGameTimeHours(Int iHours) Global ; Credit DieFeM ; https://forums.nexusmods.com/index.php?/topic/10085108-script-advance-time/?hl=%2Bpassgametimehours#entry95092948 ;Game.FadeOutGame(true, true, 0.0, 2.5, true) GlobalVariable GameHour = Game.GetFormFromFile(0x00000038, "Fallout4.esm") As GlobalVariable Int i = iHours While i > 0 GameHour.Mod(1.0) Utility.Wait(2.5/iHours) i -= 1 EndWhile Debug.Notification("Time has past, returning from call") Utility.Wait(5) Return True EndFunction Link to comment Share on other sites More sharing options...
ReDragon2013 Posted October 19, 2021 Share Posted October 19, 2021 (edited) code snipet Scriptname MysticLake:MoonshineEffectScript extends activemagiceffect Bool bIsOkToPlay = true auto State AllowDrinking Event OnEffectStart(Actor Target, Actor Caster) Actor PlayerRef = Game.GetPlayer() ; *** GoToState("Busy") if Caster == PlayerRef ; *** ; ... if bPlayerOnly if Caster != game.GetPlayer() ; *** bIsOkToPlay = False endif endif ; ... endif GoToState("AllowDrinking") EndEvent EndState The variable "bIsOkToPlay" will be always TRUE. There is no working code inside the script or an external script, that would change the boolVar to False. for studying Scriptname MysticLake:MoonshineEffectScript extends ActiveMagicEffect ; https://forums.nexusmods.com/index.php?/topic/10595153-script-moonshine-related-script/ ; When the player drinks the moonshine, a random effect is placed on them. ; The script lives on an effect associated with PeppersMoonshine (potion) ; which is available in the Mystic Lake Settlement mod InputEnableLayer PROPERTY MLS_MoonshineLayer auto Hidden ; conditional ?? Keyword PROPERTY PlayerConsumeJet auto Const Mandatory Armor PROPERTY pPipboyDusty auto Const Mandatory Message PROPERTY pMLS_MoonshineDemiseMsg auto Const Mandatory ; {Message to display if the player dies from consuming the moonshine} Message PROPERTY pMLS_MoonshineBlackoutMsg auto Const Mandatory ; {Message to display if the player passess out from consuming the moonshine} Message PROPERTY pMLS_MoonshineBlackoutMsg02 auto Const Mandatory ; {Message to display as the player begins to regain consciousness} ; sounds Sound PROPERTY DrinkingSound auto Const Mandatory ; {plays each drink} Sound PROPERTY ChokingSoundMale auto Const Mandatory ; Sound PROPERTY ChokingSoundFemale auto Const Mandatory ; {Plays after drinking} ; Player visual effects VisualEffect PROPERTY CameraAttachFogFX auto Const Mandatory ; UnUSED VisualEffect PROPERTY CameraAttachGroggyWake01FX auto Const Mandatory ; UnUSED VisualEffect PROPERTY CameraAttachGroggySleep01FX auto Const Mandatory ; UnUSED VisualEffect PROPERTY DLC03ScreenDistortFX auto Const Mandatory ; ISMs ImageSpaceModifier PROPERTY IntroFX auto Const ; {IsMod applied at the start of the spell effect} ImageSpaceModifier PROPERTY OutroFX auto Const ; {IsMod applied at the end of the spell effect} ImageSpaceModifier PROPERTY LoopFX auto Const ; {main isMod for spell} ImageSpaceModifier PROPERTY FadetoBlackImod auto Const ImageSpaceModifier PROPERTY FadefromBlackImod auto Const ImageSpaceModifier PROPERTY FadefromBlackSlowImod auto Const ImageSpaceModifier PROPERTY HoldAtBlackImod auto Const ImageSpaceModifier PROPERTY MLS_DoubleVisionImod auto Const ObjectReference PROPERTY MLS_PassoutMarkerRef auto Const Mandatory ; {Player teleports to this location after passing out} ObjectReference PROPERTY pMLS_PlayersComfyBed auto Const Mandatory ; UnUSED by default Float PROPERTY fDelay = 0.83 auto Const ; {time to wait before switching to constant Imod} Float PROPERTY fImodStrength = 1.0 auto Const ; {IsMod Strength from 0.0 to 1.0} Bool PROPERTY bPlayerOnly auto Const ; [default=False], Set TRUE, if you only want this Imod to play if the player is the spell caster. Bool bIsOkToPlay = TRUE Bool bIsFinishing ; [default=False] Int iEffectToApply ; [default=0] ; -- EVENTs -- EVENT OnEffectStart(Actor akTarget, Actor akCaster) ; IF ( bPlayerOnly ) ; IF (akCaster == Game.GetPlayer()) ; ELSE ; bIsOkToPlay = False ; ENDIF ; ENDIF IF (akCaster == Game.GetPlayer()) gotoState("AllowDrinking") ; ### STATE ### handle MGEF finish event myF_Action(akCaster) ENDIF ENDEVENT ;===================================== State AllowDrinking ;================== EVENT OnEffectFinish(Actor akTarget, Actor akCaster) bIsFinishing = TRUE myF_FX(0) ENDEVENT ;======= endState ; -- FUNCTIONs -- 4 + 2 ;---------------------------------- FUNCTION myF_Action(Actor akCaster) ;---------------------------------- ; Select a random number between 1 and 20 iEffectToApply = Utility.RandomInt(1, 20) Utility.Wait(2.0) ; Player the drinking sound DrinkingSound.Play(akCaster as ObjectReference) Utility.Wait(2.7) ; The moonshine is very strong so the player coughes a bit If (akCaster.GetBaseObject() as ActorBase).GetSex() == 1) ChokingSoundFemale.Play(akCaster as ObjectReference) ELSE ChokingSoundMale.Play(akCaster as ObjectReference) ENDIF Utility.Wait(2.0) ; Player likes the moonshine player.SayCustom(PlayerConsumeJet) myF_FX(1) ENDFUNCTION ;--------------------- FUNCTION myF_FX(Int i) ;--------------------- IF ( bIsOkToPlay ) ; == TRUE IF ( i ) ;Kill Imods from another cast, if running. IntroFX.remove() LoopFX.remove() OutroFX.remove() IntroFX.Apply(fImodStrength) ; apply isMod at full strength Utility.Wait(fDelay) IF ( bIsFinishing ) ; == TRUE, OnEffectFinish() already called ELSE ; == False, go on with OnEffectStart() code ;LoopFX.apply() IntroFX.PopTo(LoopFX, fImodStrength) myF_Effect(0) ENDIF ELSE ; play OutroSoundFX sound from my self ;int instanceID = OutroSoundFX.play((target as objectReference)) ; play OutroSoundFX sound from my self IntroFX.Remove() ;LoopFX.remove() LoopFX.PopTo(OutroFX, fImodStrength) myF_Effect(1) ENDIF ENDIF ENDFUNCTION ;------------------------- FUNCTION myF_Effect(Int i) ;------------------------- ; Random effects ; 50% chance of blurred vision ; 20% chance of having a hallucination ; 15% chance of double vision ; 10% chance of blacking out ; 5% chance of dying actor player == Game.GetPlayer() IF (iEffectToApply == 20) ; TriggerPlayerDeath(PlayerRef) pMLS_MoonshineDemiseMsg.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) player.DamageValue(Game.GetHealthAV(), 1000000) RETURN ; - STOP - ENDIF ;--------------------- IF (iEffectToApply >= 18) TriggerPlayerPassout(player, i) ; 0 - OnEffectStart(), 1 - OnEffectFinish() RETURN ; - STOP - ENDIF ;--------------------- IF (iEffectToApply >= 15) ; TriggerPlayerDoubleVision(i+1) IF ( i ) ; remove the effect MLS_DoubleVisionImod.Remove() ELSE ; Add the effect MLS_DoubleVisionImod.ApplyCrossFade() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (iEffectToApply >= 11) ; TriggerPlayerTripin(PlayerRef, i+1) IF ( i ) ; remove the effect DLC03ScreenDistortFX.Stop(player as ObjectReference) ELSE ; Add the effect DLC03ScreenDistortFX.Play(player as ObjectReference) ;Trigger the a hallucination effect ; TriggerHallucination() ENDIF ENDIF ENDFUNCTION ;------------------------------------------------- FUNCTION TriggerPlayerPassout(Actor player, Int i) ;------------------------------------------------- IF ( i ) ; OnEffectFnish() ; Consider addding a hangover spell ;PlayerRef.AddSpell(MLS_Hangover, false) myF_GameTimePlus1() ;;; PassGameTimeHours(1) Debug.Notification("Time has past, returning from call") Utility.Wait(5.0) ; Display message - Player regains consciousness pMLS_MoonshineBlackoutMsg02.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) ; Fade the scene in from blackness HoldAtBlackImod.PopTo(FadefromBlackSlowImod, fImodStrength) Utility.Wait(1.0) ; Strip player ddown to their scivvies, but add the pipboy back player.UnequipAll() player.AddItem(pPipboyDusty, absilent=true) player.EquipItem(pPipboyDusty, absilent=true) Utility.Wait(0.5) Game.ForceThirdPerson() IF ( MLS_MoonshineLayer ) MLS_MoonshineLayer.EnablePlayerControls() ;;; MLS_MoonshineLayer = None ENDIF Utility.Wait(1.0) IntroFX.remove() LoopFX.remove() OutroFX.remove() ELSE ; OnEffectStart() ; Add the effect Utility.Wait(2.5) ;Display a message - blackout imminent pMLS_MoonshineBlackoutMsg.Show(0, 0, 0, 0, 0, 0, 0, 0, 0) ; Visual effect to illustate the lose of consciousness Game.FadeOutGame(abFadingOut=True, abBlackFade=True, afSecsBeforeFade=0.0, afFadeDuration=7.5, abStayFaded=True) ;CameraAttachGroggySleep01FX.Play(PlayerRef) Utility.Wait(5.8) ; Visual effect to represent the player hitting the ground Game.ShakeCamera(afStrength = 1.0, afDuration = 1.0) Utility.Wait(1.0) ; Diasable player controls so they cannot run off MLS_MoonshineLayer = InputEnableLayer.Create() ; create the layer MLS_MoonshineLayer.DisablePlayerControls() ; Player is teleported to the penthouse LoopFX.PopTo(HoldAtBlackImod, fImodStrength) player.SetEssential(TRUE) ; make player unvulnerable Utility.Wait(5.0) player.MoveTo( MLS_PassoutMarkerRef ) player.SetEssential(False) ; player can be killed! ENDIF ENDFUNCTION ;--------------------------- FUNCTION myF_GameTimePlus1() ; optimized version ;--------------------------- ; get GameHour without to set a property globalVariable GameHour = Game.GetFormFromFile(0x00000038, "Fallout4.esm") as GlobalVariable IF ( GameHour ) GameHour.Mod(1.0) ; modify by 1 threadsafe the vanilla game globalVar "gamehour" Utility.Wait(2.5) ENDIF ENDFUNCTION ;------------------------------------- FUNCTION PassGameTimeHours(Int iHours) ; bugfix ;------------------------------------- ; Credit DieFeM ; https://forums.nexusmods.com/index.php?/topic/10085108-script-advance-time/?hl=%2Bpassgametimehours#entry95092948 ;Game.FadeOutGame(true, true, 0.0, 2.5, true) ; get GameHour without to set a property globalVariable GameHour = Game.GetFormFromFile(0x00000038, "Fallout4.esm") as GlobalVariable ;;; globalVariable GameHour = Game.GetForm(0x00000038) as GlobalVariable : probably this is also working int i = iHours WHILE (i > 0) GameHour.Mod(1.0) ; modify the globalVar "gamehour", increase by 1 hour Utility.Wait(2.5 / iHours as Float) i = i - 1 ENDWHILE ENDFUNCTION Edited October 19, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
pepperman35 Posted October 19, 2021 Author Share Posted October 19, 2021 Thanks ReDragon2013, I'll study this a bit Appreciate the time and effort you spent. Link to comment Share on other sites More sharing options...
Recommended Posts