emeryrik Posted December 28, 2016 Share Posted December 28, 2016 This is my first stab at scripting with Papyrus, but I'm having trouble getting something to work. I've been working on making a mod that plays sounds based on the player's hunger, thirst, and sleep levels. I went about this by adding a new scripted magic effect to the hunger, thirst, and sleep potions in the Creation Kit. Here's what I started with: Scriptname Hardcore:HC_VitalEffect_SoundScript extends ActiveMagicEffect Group Data Sound Property SoundToPlay const auto mandatory{sound to be played} float Property SoundTimerInterval = 0.0 const auto{how often sound will play} EndGroup Event OnEffectStart(Actor akTarget, Actor akCaster)SoundToPlay.Play(Game.GetPlayer())startTimer(SoundTimerInterval)EndEvent Function PlaySoundAndStartTimer()if IsBoundGameObjectAvailable()SoundToPlay.Play(Game.GetPlayer())startTimer(SoundTimerInterval)endifEndFunction Event OnTimer(int aiTimerID)PlaySoundAndStartTimer()EndEvent This works great, but only if a unisex sound is played; that is, it can only play one sound regardless if the player is female or male. Therefore, this is what I came up with: Scriptname Hardcore:HC_VitalEffect_SoundScript extends ObjectReference Group Data Sound Property FemaleSound const auto mandatory{sound to be played for female player} Sound Property MaleSound const auto mandatory{sound to be played for male player} float Property SoundTimerInterval const auto mandatory{how often sound will play} EndGroup Event OnInit()if (Game.GetPlayer().GetBaseObject() as ActorBase).GetSex() == 1FemaleSound.play(Game.GetPlayer()) elseMaleSound.play(Game.GetPlayer()) endifstartTimer(SoundTimerInterval)EndEvent Function PlaySoundAndStartTimer()if IsBoundGameObjectAvailable()if (Game.GetPlayer().GetBaseObject() as ActorBase).GetSex() == 1FemaleSound.play(Game.GetPlayer()) elseMaleSound.play(Game.GetPlayer()) endifstartTimer(SoundTimerInterval)endifEndFunction Event OnTimer(int aiTimerID)PlaySoundAndStartTimer()EndEvent This, however, does not work. I copied the GetSex function from drinkFromFountainScript.psc, and because my script extends the same parent script it should work correctly. Can someone with more knowledge of Papyrus be able to diagnose this? Thank you,Akanto10 Link to comment Share on other sites More sharing options...
scrivener07 Posted December 28, 2016 Share Posted December 28, 2016 Try it on a Quest form with start game enabled. If you create a new quest in the creation kit, it will be setup the way you need without changing anything. Keep in mind too that Sounds have their own conditions in the creation kit.Scriptname Hardcore:HC_VitalEffect_SoundScript extends Quest Actor Player int SoundTimer = 1 const int SoundInstance int Male = 0 const int Female = 1 const Event OnInit() Player = Game.GetPlayer() EndEvent Event OnQuestInit() StartTimer(SoundInterval) EndEvent Event OnQuestShutdown() CancelTimer(SoundTimer) Sound.StopInstance(SoundInstance) EndEvent Event OnTimer(int aiTimerID) Sound.StopInstance(SoundInstance) SoundInstance = SFX.Play(Player) StartTimer(SoundInterval, SoundTimer) EndEvent Group Data Sound Property FemaleSound const auto mandatory {sound to be played for female player} Sound Property MaleSound const auto mandatory {sound to be played for male player} float Property SoundInterval const auto mandatory {how often sound will play} EndGroup Group Sound Sound Property SFX Hidden {returns the sound for the players gender} Sound Function Get() If (IsFemale) return FemaleSound Else return MaleSound EndIf EndFunction EndProperty bool Property IsFemale Hidden {returns true if the player is female} bool Function Get() int iGender = (Player.GetBaseObject() as ActorBase).GetSex() If (iGender == Female) return true Else return false EndIf EndFunction EndProperty EndGroup Sorry for being lazy, I dont know if it compiles. Link to comment Share on other sites More sharing options...
emeryrik Posted December 28, 2016 Author Share Posted December 28, 2016 Hi scrivener07! Thanks for your reply. It compiles, but I have a few questions about how to apply it. I created a new quest that runs at the start of the game with one stage that runs on start. I set a couple of log entries with conditions for the corresponding actor values. I loaded the script in the scripts section. Now, how would I go about running the script with unique property values for each log entry? Should I use kmyQuest somehow? I appreciate your help! Link to comment Share on other sites More sharing options...
scrivener07 Posted December 29, 2016 Share Posted December 29, 2016 I dont have enough details about what exactly your trying to even do. Why did you make a new stage that runs at the start? What are these log entries intended for and what are the conditions? Lay out the big picture for me. Link to comment Share on other sites More sharing options...
emeryrik Posted December 29, 2016 Author Share Posted December 29, 2016 Okay, so basically I am trying to make sounds play at smaller and smaller intervals as hunger, thirst, and sleepiness increase. That is, if you are 'peckish' a very small stomach rumble will play every 5 minutes, if you are 'hungry' a louder, different sound will play every 4 minutes, etc. I created a crude flow chart with a minimal example concerning thirst: http://akanto10.weebly.com/uploads/9/2/3/9/923988/untitled_orig.jpg To address the way I set up the quest, I have no idea what I'm doing. I used log entries because it looks like you can use conditions for them and they can run their own scripts. That means, I could satisfy actor value conditions for each stage of hunger, thirst, and sleepiness and then run a script with its own sound properties. Here's what I have: http://akanto10.weebly.com/uploads/9/2/3/9/923988/screen_orig.jpg Link to comment Share on other sites More sharing options...
emeryrik Posted January 13, 2017 Author Share Posted January 13, 2017 Alright, just to bump this thread and give an update, I realized how scripts work when they're attached to a quest, so I made a quest with the script attached and the properties pointing to sounds and a time interval, but still nothing happens. I've tried all types of methods, including having the quest run at start, manually starting it via console, and starting it with a trigger, but nothing works. Does anyone have any insight on why my methods of getting this to work aren't working or why the script itself may not work (I'm not sure what else could be wrong). Thanks in advance to anyone who can help me along a little further! Link to comment Share on other sites More sharing options...
Starwaster Posted January 14, 2017 Share Posted January 14, 2017 Alright, just to bump this thread and give an update, I realized how scripts work when they're attached to a quest, so I made a quest with the script attached and the properties pointing to sounds and a time interval, but still nothing happens. I've tried all types of methods, including having the quest run at start, manually starting it via console, and starting it with a trigger, but nothing works. Does anyone have any insight on why my methods of getting this to work aren't working or why the script itself may not work (I'm not sure what else could be wrong). Thanks in advance to anyone who can help me along a little further!One way of doing it is by adding it to the SM Event Node, but I can only ever get that to work by setting the node type to a single event (i.e. OnStoryIncreaseLevel) that the script contains but other events in the script never seem to fire for which is what it looks like what you need to have happen... I'm having the same problem and I've looked at existing scripts (such as HC_ManagerScript which FO4 uses for Survival mode and basically just sits there handling events) but I can't figure it out either. I bet it's something really basic though :( Link to comment Share on other sites More sharing options...
Recommended Posts