Skip to content

Instantly share code, notes, and snippets.

@osvein
Created November 26, 2017 18:36
Show Gist options
  • Select an option

  • Save osvein/4f86f728f0f413eac1decea906c4d64c to your computer and use it in GitHub Desktop.

Select an option

Save osvein/4f86f728f0f413eac1decea906c4d64c to your computer and use it in GitHub Desktop.
;/ DrinkFromWaterFountainScript for Finite Water
/ Copyright (c) 2017 Oskar Sveinsen
/
/ Permission is hereby granted, free of charge, to any person obtaining a copy
/ of this software and associated documentation files (the "Software"), to deal
/ in the Software without restriction, including without limitation the rights
/ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/ copies of the Software, and to permit persons to whom the Software is
/ furnished to do so, subject to the following conditions:
/
/ The above copyright notice and this permission notice shall be included in all
/ copies or substantial portions of the Software.
/
/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/ SOFTWARE.
/;
scriptname DrinkFromFountainScript extends ObjectReference
{Handles drink on activate for water fountains}
Sound property DrinkingSound auto const
Sound property FountainStart auto const
Sound property AhhhSoundMale auto const
{Plays after drinking clean water}
Sound property AhhhSoundFemale auto const
{Plays after drinking clean water}
Sound property ChockingSoundMale auto const
{Plays after drinking when the clean water is depleted}
Sound property ChockingSoundFemale auto const
{Plays after drinking when the clean water is depleted}
Spell property SpellOnDrink auto const
{set to WaterFountainCleanDrinking for refill functionality}
Quest property Tutorial auto const
; ugly for the sake of compatibility
ActorValue property RefillTimeAV hidden
ActorValue function get()
return Game.GetFormFromFile(0x000f99, "FiniteWater.esp") as ActorValue; WaterFountainRefillTime
endfunction
endproperty
Message property DepleteMessage hidden
Message function get()
return Game.GetFormFromFile(0x000f9a, "FiniteWater.esp") as Message; WaterFountainDepleteMessage
endfunction
endproperty
Keyword property WorkshopLink hidden
Keyword function get()
return Game.GetFormFromFile(0x054ba6, "Fallout4.esm") as Keyword; WorkshopItemKeyword
endfunction
endproperty
Form property BottleList hidden
Form function get()
return Game.GetFormFromFile(0x249f56, "Fallout4.esm"); HC_FillableWaterBottlesList
endfunction
endproperty
Sound property BottleSound hidden
Sound function get()
return Game.GetFormFromFile(0x249fca, "Fallout4.esm") as Sound; HC_UIModsComponentsWater
endfunction
endproperty
Form property FiniteIndicator hidden
Form function get()
return Game.GetFormFromFile(0x0b1ecd, "Fallout4.esm"); WaterFountainCleanDrinking
endfunction
endproperty
Form property ItemClean hidden
Form function get()
return Game.GetFormFromFile(0x0366c0, "Fallout4.esm"); WaterPurified
endfunction
endproperty
Form property ItemDirty hidden
Form function get()
return Game.GetFormFromFile(0x0366bf, "Fallout4.esm"); WaterDirty
endfunction
endproperty
bool property FillBottle auto hidden
float refillTime = 0.3333 const
float refillTimeFull = 1.0 const
int timer = 0 const
float timerDelay = 0.25 const
float timerInterval = 1.0 const
int dispensed
int dispensedSoundMin = 2 const
int toDispense
int toDispenseMax = 5 const
Actor user
auto state Idle
event OnBeginState(string oldState)
if self.GetBaseObject() is Furniture && user
self.Activate(user, true)
endif
toDispense = 0
user = NONE
self.FillBottle = false
self.SetAnimationVariableFloat("fDampRate", 0.03)
self.SetAnimationVariableFloat("fToggleBlend", 0.0)
endevent
event OnActivate(ObjectReference source)
if source == Game.GetPlayer() && !(self.GetBaseObject() is Furniture)
user = source as Actor
self.GotoState("Starting")
endif
endevent
function Dispense()
endfunction
endstate
state Buffer
endstate
state Starting
event OnBeginState(string newState)
dispensed = 0
toDispense = 1
self.SetAnimationVariableFloat("fDampRate", 0.08)
self.SetAnimationVariableFloat("fToggleBlend", 1.0)
self.FountainStart.Play(self)
self.StartTimer(timerDelay + timerInterval, timer)
self.Tutorial.SetStage(500)
endevent
endstate
state Clean
event OnEndState(string newState)
bool depleted
depleted = newstate == "Dirty"
if newState != "Clean" && !self.FillBottle
int sex
Sound snd
; ugly for the sake of compatibility
sex = user.GetActorBase().GetSex()
if sex == 0
if depleted
snd = self.ChockingSoundMale
else
snd = self.AhhhSoundMale
endif
elseif sex == 1
if depleted
snd = self.ChockingSoundFemale
else
snd = self.AhhhSoundFemale
endif
endif
if snd
snd.Play(user)
endif
endif
if depleted
self.DepleteMessage.Show()
self.GotoState("Idle")
endif
endevent
Form function GetDrink()
return self.ItemClean
endfunction
endstate
state Dirty
Form function GetDrink()
return self.ItemDirty
endfunction
endstate
event OnInit()
self.RegisterForRemoteEvent(Game.GetPlayer(), "OnSit")
debug.trace("drinkFromFountainScript says hi!")
endevent
Form function GetDrink()
return NONE
endfunction
event OnActivate(ObjectReference source)
if source == user && !(self.GetBaseObject() is Furniture) && toDispense < toDispenseMax
toDispense = toDispense + 1
endif
endevent
event Actor.OnSit(Actor source, ObjectReference object)
if object == self
user = source
self.GotoState("Starting")
endif
endevent
event OnExitFurniture(ObjectReference source)
if source == user
self.GotoState("Buffer")
user = NONE
self.GotoState("Idle")
endif
endevent
function Dispense()
Sound snd
user.AddItem(self.GetDrink(), 1, !self.FillBottle)
if self.FillBottle
snd = self.BottleSound
user.RemoveItem(self.BottleList, 1, true)
else
snd = self.DrinkingSound
user.EquipItem(self.GetDrink(), false, true)
endif
snd.Play(user)
if !(self.GetBaseObject() is Furniture)
toDispense = toDispense - 1
endif
dispensed = dispensed + 1
endfunction
event OnTimer(int id)
WorkshopScript workshop
if id != timer
return
endif
if self.FillBottle && !user.GetItemCount(self.BottleList)
self.GotoState("Idle")
return
endif
if self.SpellOnDrink != self.FiniteIndicator
; fall back to vanilla behaviour
self.GotoState("Clean") ; for vanilla sound effects behaviour
self.SpellOnDrink.Cast(user)
return
endif
workshop = self.GetLinkedRef(self.WorkshopLink) as WorkshopScript
if workshop && workshop.OwnedByPlayer
Form clean
string st
clean = self.ItemClean
if workshop.GetItemCount(clean)
workshop.RemoveItem(clean, 1, true)
st = "Clean"
else
st = "Dirty"
endif
self.GotoState(st)
else
ActorValue av
float diff
string st
av = self.RefillTimeAV
diff = self.GetValue(av) - Utility.GetCurrentGameTime()
if diff < 0
self.RestoreValue(av, diff)
endif
if diff < refillTimeFull - refillTime
self.DamageValue(av, refillTime)
st = "Clean"
else
st = "Dirty"
endif
self.GotoState(st)
endif
self.Dispense()
if toDispense > 0
self.StartTimer(timerInterval, timer)
else
self.GotoState("Idle")
endif
endevent
;/ HC_FillWaterBottlePerk fragments for Finite Water
/ Copyright (c) 2017 Oskar Sveinsen
/
/ Permission is hereby granted, free of charge, to any person obtaining a copy
/ of this software and associated documentation files (the "Software"), to deal
/ in the Software without restriction, including without limitation the rights
/ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/ copies of the Software, and to permit persons to whom the Software is
/ furnished to do so, subject to the following conditions:
/
/ The above copyright notice and this permission notice shall be included in all
/ copies or substantial portions of the Software.
/
/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/ SOFTWARE.
/;
;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
Scriptname Fragments:Perks:PRKF_HC_FillWaterBottlePerk_00249F55 Extends Perk Hidden Const
;BEGIN FRAGMENT Fragment_Entry_00
Function Fragment_Entry_00(ObjectReference akTargetRef, Actor akActor)
;BEGIN CODE
DrinkFromFountainScript fountain
fountain = akTargetRef as DrinkFromFountainScript
if fountain
fountain.FillBottle = true
fountain.Activate(akActor)
else
akActor.RemoveItem(self.Bottle, 1, true)
akActor.AddItem(self.ItemDirty)
endif
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
Form Property ItemDirty Auto Const Mandatory
Form Property Bottle Auto Const Mandatory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment