Jump to content

Quick Questions, Quick Answers


Mattiewagg

Recommended Posts

Is it possible to set the in-game audio volume through scripting? For example, if you wanted to play a custom piece of music for a short amount of time.

Also, why isn't this thread stickied yet?

I very recently found something like this, but I can't recall the name. There IS a way to play music via script. I'd check the CK wiki. When I get home I'll check on my PC.

 

And I have no idea. I may contact a different mod. Perhaps they think there are already too many pinned, pinned threads aren't noticed as much, or they just haven't noticed this one.

Link to comment
Share on other sites

  • Replies 2.6k
  • Created
  • Last Reply

Top Posters In This Topic

 

Can anyone make me an example script that does this?:

 

After X hours of game time had passed, increase value of a variable by Y.

 

@Matt

 

 

 

 

Scriptname SkyEndWeight extends ObjectReference

 

Actor Property PlayerRef auto

Keyword Property Drink auto

Keyword Property Food auto

GlobalVariable Property FatGainedDay auto

GlobalVariable Property DaysWithoutEat auto

Float Property Starving auto

 

Float Property CountDrink auto

Float Property CountFood auto

Float Property Fat auto

 

;Function SetWeight(float weight) native

;float Function GetWeight() native

;Function QueueNiNodeUpdate() native

 

Keyword Property Vampire auto

 

Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)

 

if akBaseObject as Potion && akBaseObject.HasKeyword(Drink)

Fat= FatGainedDay.GetValue()

CountDrink=CountDrink+0.5

Fat=Fat+CountDrink

FatGainedDay.SetValue(Fat)

CountDrink=0

endif

 

if akBaseObject as Potion && akBaseObject.HasKeyword(FOOD)

Fat=FatGainedDay.GetValue()

CountFood=CountFood+1

Fat=Fat+CountFood

FatGainedDay.SetValue(Fat)

CountFood=0

endif

 

EndEvent

 

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)

PlayerRef.UnEquipAll()

 

if Starving>0

Debug.Messagebox("I'm starving, I have lost weight.")

elseif Starving == 0

Debug.Messagebox("I've gained " + FatGainedDay.GetValue()/10 + " kilograms.")

endif

 

EndEvent

 

Event OnSleepStop(bool abInterrupted)

 

if PlayerRef.HasKeyword(Vampire)==0

 

if FatGainedDay.GetValue()>9

FatGainedDay.SetValue(9)

PlayerRef.GetActorBase().SetWeight(PlayerRef.GetWeight()+FatGainedDay.GetValue()/10)

PlayerRef.QueueNiNodeUpdate()

float NeckDelta= PlayerRef.GetWeight()+FatGainedDay.GetValue()/10

PlayerRef.UpdateWeight(NeckDelta)

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()>=7.5 && FatGainedDay.GetValue()<=9

PlayerRef.GetActorBase().SetWeight(PlayerRef.GetWeight()+FatGainedDay.GetValue()/10)

PlayerRef.QueueNiNodeUpdate()

float NeckDelta= PlayerRef.GetWeight()+FatGainedDay.GetValue()/10

PlayerRef.UpdateWeight(NeckDelta)

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()>=6 && FatGainedDay.GetValue()<=7.5

PlayerRef.GetActorBase().SetWeight(PlayerRef.GetWeight()+FatGainedDay.GetValue()/10)

PlayerRef.QueueNiNodeUpdate()

float NeckDelta= PlayerRef.GetWeight()+FatGainedDay.GetValue()/10

PlayerRef.UpdateWeight(NeckDelta)

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()>=4.5 && FatGainedDay.GetValue()<=6

; Any value between 4.5 and 6 means you keep your current weight

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()>=3.5 && FatGainedDay.GetValue()<=4.5

PlayerRef.GetActorBase().SetWeight(PlayerRef.GetWeight()-FatGainedDay.GetValue()/10+0.5)

PlayerRef.QueueNiNodeUpdate()

float NeckDelta= PlayerRef.GetWeight()-FatGainedDay.GetValue()/10+0.5

PlayerRef.UpdateWeight(NeckDelta)

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()>=2 && FatGainedDay.GetValue()<=3.5

PlayerRef.GetActorBase().SetWeight(PlayerRef.GetWeight()-FatGainedDay.GetValue()/10+1)

PlayerRef.QueueNiNodeUpdate()

float NeckDelta= PlayerRef.GetWeight()-FatGainedDay.GetValue()/10+1

PlayerRef.UpdateWeight(NeckDelta)

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()>=0 && FatGainedDay.GetValue()<=2

PlayerRef.GetActorBase().SetWeight(PlayerRef.GetWeight()-FatGainedDay.GetValue()/10+2)

PlayerRef.QueueNiNodeUpdate()

float NeckDelta= PlayerRef.GetWeight()-FatGainedDay.GetValue()/10+2

PlayerRef.UpdateWeight(NeckDelta)

FatGainedDay.SetValue(0)

endif

 

if FatGainedDay.GetValue()==0

Starving = Starving + 1

elseif FatGainedDay.GetValue()!=0

Starving = 0

endif

 

if Starving == 14

PlayerRef.DamageActorValue("Health",9999999999)

endif

 

endif

EndEvent

 

; Function UpdateWeight(float neckDelta) native

Int Property Once auto

 

Event OnInit()

Once=1

Starving = 0

StatusChecks()

EndEvent

 

Event onRaceSwitchComplete()

Once=1

Starving = 0

StatusChecks()

EndEvent

 

Function StatusChecks()

RegisterForSingleUpdate(5.0)

EndFunction

 

 

Event OnUpdate()

if PlayerRef.HasKeyword(Vampire)==0

if Once==1

PlayerRef.UnEquipAll()

Float NeckDelta =0

PlayerRef.GetActorBase().SetWeight(0)

PlayerRef.QueueNiNodeUpdate()

PlayerRef.UpdateWeight(NeckDelta)

once==0

UnRegisterForUpdate()

endif

endif

EndEvent

 

 

 

This is the complete script, I was right, OnUpdate events are paused during showracemenu, so this works like a charm. And I did have to use the UpdateWeight function because the neck did look pretty odd =p, I don't know if QueueNiNode is still necessary or if it has any ramifications if kept there, but I'll just keep it there incase.

 

Because of the keywords I added to all the food items in the game it correctly checks if I'm drinking or eating. The only thing that I haven't tested yet is the OnSleepEnd and OnSleepStart events because I haven't had time XD, at this point I just wished I had testers.

 

Additional: Is it possible to advance the rate at which time passes in Papyrus? And how?


float X
int Y
int myVar 

Event OnInit()

     RegisterForSingleUpdateGameTime(X); X is a float for how many hours to wait

EndEvent

Event OnUpdateGameTime()

     myVar += Y
     RegisterForSingleUpdateGameTime(X); only have this line if you want to keep repeating this var change

EndEvent
As for changing in game passing time - yes it's possible. Check for a function to change Timescale on the CK Wiki. Or, it may be a Global the way GameTime is. If that is the case, look for Globals with Timescale in the name. You can use SetValue with this global to set the speed of time ingame. Don't go below 5 no matter what, though I'm not sure on the limit for how high.
Link to comment
Share on other sites

Two things:

 

DON'T use RegisterForUpdate of any kind. JUST RegisterForSingleUpdates in a loop (calling it again in the OnUpdate):

 

Secondly, DON'T call more than a couple of functions in the OnInit. It may overload and not be able to handle it all.

Link to comment
Share on other sites

I didn't, and I used RegisterForSingleUpdate then I Unregistered inside the OnUpdate event, but even if I don't call the Function for registering the event the OnUpdate event will still happen regardless, every 1 second or so, it eventually stops, but it runs a whopping 9 times or more when it is only supposed to run once or not at all, lol.

Event OnInit()
StatusChecks()
Debug.MessageBox("ATTENTION!: This overhaul allows you to manage your body weight by eating and drinking if you are not a vampire and/or undead. If you haven't eaten for 14 days and your weight is 0 you will die. The ratio for Drinks is 4 to 1, the ratio for Food is 1 to 1, you need to consume at least 4-6 food items or drink 4 times that much to keep your current weight, anything above that will increase your weight, anything less than that will decrease your weight. Your weight changes whenever you wake up after going to sleep. Your items are also unequipped when you go to sleep to avoid bugs.")
EndEvent

Function StatusChecks()
RegisterForUpdate(10.0)
EndFunction

Event OnUpdate()

if PlayerRef.HasKeyword(Vampire)==0
	PlayerRef.UnEquipAll()
	Float NeckDelta =0
	PlayerRef.GetActorBase().SetWeight(0)
	PlayerRef.QueueNiNodeUpdate()
	PlayerRef.UpdateWeight(NeckDelta)
	Debug.MessageBox("stuff")
endif
UnRegisterForUpdate()

EndEvent

This is all I have. This OnUpdate happens more than once.

Edited by Kerberus14
Link to comment
Share on other sites

No. You didn't use RegisterForSingleUpdate. You used RegisterForUpdate. Unregistering for it doesn't matter - just use a single update. Either you don't need it to unregister at all if you want to do it once, or you just call another Single Update inside the OnUpdate.
Link to comment
Share on other sites

Oh, I copied the wrong snippet, it's because I tested both versions with RegisterForUpdate and RegisterForSingleUpdate to check if that was the problem, but it still behaves completely the same. The other scripts that use the same event seem to work just fine...

 

I can confirm that this event stops one of my other script's OnUpdate events from working. What?

Edited by Kerberus14
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...