stacymichelle084 Posted November 11, 2018 Share Posted November 11, 2018 I've been trying to figure this out for hours but I don't know what else to try. I'm such a noob at coding. Long story short, I'm making a mod where diseases go through four different stages and at the end if you don't get cured, you begin to have permanent losses to health, magicka, or stamina (depends on which disease you have). The health part works fine because once you get to zero, you die. But when the stamina or magicka gets to zero, it won't stop registering for updates and the max stamina/magicka starts going into negative numbers! So the player ends up with 0/-20 or some such craziness. Code:https://codeshare.io/aJvjKn (If there's a better way for me to post the code, please let me know. I also attached a screenshot.) I'm pretty sure the problem with magicka is somewhere between lines 41 and 50 and stamina is between 52 and 61, but I have no idea what to change. I'm also not really even sure if I'm using the UnregisterForUpdate command correctly. >.> Another problem I'm not sure how to address is that I want the script to stop taking away max sta/mag when it reaches zero, but if the player levels up and gets 10 more points to sta/mag, then I need it to start running again so it takes the new points away. I guess I could add something that checks for player level and if it changes then start running the updates again? Thanks for any help/advice you guys have to offer. These scripts are the hardest part of modding! 0.0 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 11, 2018 Share Posted November 11, 2018 Tip: Each use of Game.GetPlayer() pauses the script while the thread has to go to the Game script to call the GetPlayer() function. It is generally accepted to use a variable of some sort to store the player data. This could be a property or local variable. Example: Actor PlayerRef Event OnEffectStart (Actor akTarget, Actor akCaster) ;at the beginning of stage 4 disease (chronic) PlayerRef = Game.GetPlayer() ;go get the data once and store it for use throughout the script If (PlayerRef.HasMagicEffectWithKeyword(DecreaseHealth)) ;etc... EndIf EndEvent As far as your issue at hand...ModActorValue is changing the current max but not the base.SetActorValue changes the base.As a result, checking the base will show that it is still at max value despite having modified it all the way to a displayed value of 10/10You want to use GetActorValue to see what ModActorValue is changing.Example: If PlayerRef.GetActorValue("Magicka") >= 10 PlayerRef.ModActorValue("Magicka",-10.0) ChronicDiseaseDecMagicka.Show() RegisterForSingleUpdateGameTime(HoursToWait) Else Float MAVM = (PlayerRef.GetActorValue("Magicka") * (-1) PlayerRef.ModActorValue("Magicka",MAVM) EndIf There may be edge cases where this example would result in a modification above 0 and below 10 in the final modification. This might happen should the player expend some of the value and it not fully recover by the time the update rolls around and makes its final modification. However, 10 is such a low amount that it will probably be recovered in 99.9% cases. As far as changes due to leveling, the story manager has a level up entry that you could hook a quest on and use that to restart the process. Link to comment Share on other sites More sharing options...
stacymichelle084 Posted November 11, 2018 Author Share Posted November 11, 2018 Oh, wow, thank you so much!! This is really helpful! I always learn so much doing stuff like this. Thanks for taking the time to help me out. =) Link to comment Share on other sites More sharing options...
Recommended Posts