Jump to content

Need help playing a sound when the player get's hungry, thirsty or tired.


Recommended Posts

Hi, I've been trying for a good while to make a mod that plays certain sounds when a player's needs advance, I found the player needs are applied with potions (magic>potions>HC_SleepEffect_Tired for example), so I figured I should use the Event OnItemEquipped since as far as I know it detects when a potion is consumed.

I made properties for the player, the sound descriptors and the potions, these seem to be working fine as the sounds play in the OnInit code and I made sure to set them.

But in game, when I wait and my needs advance, nothing plays, I get the notification that confirms the even is triggered but I also get "Equipped item not by player" notification which means the "if akReference == PlayerRef" is not working?

I have tried a lot of stuff but just can't get it to work, the sound descriptors, the quest and everything else seems to be fine.

This is also my first mod and my first time ever using papyrus or the creation kit for that matter.

I attached the text of the script

Script_SNS.txt

Link to comment
Share on other sites

Game.GetPlayer() returns an Actor, but akReference is an ObjectReference, I'd say you need to cast the player to an ObjectReference: if akReference == (PlayerRef As ObjectReference)

but there's another thing, akReference is not meant to be the Actor who equiped the object, but the reference of the object that was equiped by the actor.

https://falloutck.uesp.net/wiki/OnItemEquipped_-_Actor

  • akReference: The reference that the actor just equipped - if the reference is persistant. Otherwise, None.
Link to comment
Share on other sites

2 hours ago, DieFeM said:

Game.GetPlayer() returns an Actor, but akReference is an ObjectReference, I'd say you need to cast the player to an ObjectReference: if akReference == (PlayerRef As ObjectReference)

but there's another thing, akReference is not meant to be the Actor who equiped the object, but the reference of the object that was equiped by the actor.

https://falloutck.uesp.net/wiki/OnItemEquipped_-_Actor

  • akReference: The reference that the actor just equipped - if the reference is persistant. Otherwise, None.

So I don't need to specify that the event applies to the player? since it is on an alias already attached to the player?

Or am I misunderstanding? haha

Should I just check if akBaseObject is the potion like I did in the other ifs and that's it? or should I put something else in akReference?

I'm gonna try it just skipping the if akReference == PlayerRef and see what happens, thx for the help

Link to comment
Share on other sites

12 minutes ago, Dyrohc said:

So I don't need to specify that the event applies to the player? since it is on an alias already attached to the player?

Or am I misunderstanding? haha

Should I just check if akBaseObject is the potion like I did in the other ifs and that's it? or should I put something else in akReference?

I'm gonna try it just skipping the if akReference == PlayerRef and see what happens, thx for the help

It worked, now the sounds play.

Now the problem is that  the thirst and fatigue sound play twice and most importantly, it triggers every time hunger or thirst advance even if the state doesn't change

Like you are parched, the sound plays, you wait 2 hours, you are still parched but the sound still plays and I honestly have no idea how to fix that

Link to comment
Share on other sites

looking around the effects of the potion, I saw there are these things called "Actor Value" with stuff like "HC_ThirstEffect" and similar and these "global" things with values like "HC_TE_Parched".

For example the potion that applies the Parched, the effects on it have a condition that checks if the Actor Value "HC_ThirstEffect" equals "HC_TE_Parched".

Alongside the event that checks if the player consumes the potions, could I use that actor value to determine if the state actually changed?.

Like "If player drinks "HC_ThirstEffect_Parched", get actor valur for "HC_ThirstEffect" and if that is not equal to "HC_TE_PARCHED" then play the sound ?.

I am asking because I don't really know what exactly actor values are or if they can be used that way.

Link to comment
Share on other sites

Check the first example here: https://falloutck.uesp.net/wiki/RegisterForMagicEffectApplyEvent_-_ScriptObject

Note that it registers a single event, so you'd need to re-register on every event to continuously checking for magic effects applied.

For example:

Event OnInit()
	RegisterForMagicEffectApplyEvent(Game.GetPlayer())
EndEvent

Event OnMagicEffectApply(ObjectReference akTarget, ObjectReference akCaster, MagicEffect akEffect)
	;/ do your thing /;
	Debug.Trace(akCaster + " applied the " + akEffect + " on " + akTarget)
	;/ re-register for next effect /;
	RegisterForMagicEffectApplyEvent(Game.GetPlayer())
EndEvent

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...