ThiagoAlex Posted September 9, 2019 Share Posted September 9, 2019 (edited) Someone, Please Help!I'm Trying to Write a Script(Based on Sleeping Ghouls Mod Resource) so Ghouls Can Oly Die By Destroying Their Heads or Random% Chance With a Head Shot, Also Add a Timer For Then to Resurrect so They don't Instantly Get up, But I'm New to Scripting and Can't Understand Why It Isn't Working. Ps: I Manage To Get It Almost 100% Working, But I Lost the esp Due to a Windows Update, I Can´t Remeber How I Did, But The Only Thing Not Working Was The Timer to Resurrect. float GhoulFloatfloat HSFloatfloat Secondsbegin OnDeath Set HSFloat to GetRandomPercent Set Seconds to GetRandomPercentEndBegin GameModeif getdead ==1 if GhoulFloat ==0 if player.issneaking ==0 if getdistance player <350 ;if getsecondspassed >= Seconds SetHealth 100 resurrect 1 ;endif endif endif endifendifendBegin GameModeif getdead ==1 if GhoulFloat ==0 if player.issneaking ==1 if getdistance player <150 ;if getsecondspassed >=Seconds SetHealth 100 resurrect 1 ;endif endif endif endifendifendBegin Gamemodeif isLimbGone 2||1 Set GhoulFloat To 1 endif endBegin Gamemodeif GetKillingBlowLimb == 2||1 if HSFloat >=49 Set GhoulFloat To 1 endif endifend;begin onhit;if getsecondspassed >= Seconds ;if GhoulFloat ==0 ;if getdead ==1 ;setHealth 100 ;resurrect 1 ;endif ;endif ;endif;end Edited September 9, 2019 by ThiagoAlex Link to comment Share on other sites More sharing options...
dubiousintent Posted September 9, 2019 Share Posted September 9, 2019 Regarding your timer: [Edit: Your variable names are too vaguely similar and confusing. I have to heavily rewrite this to correct it.] "Seconds" is not your timer; it's your "test condition value". You need a new "fElapsed" timer variable to track how much time has elapsed since death. You need to explicitly initialize your timer "fElapsed" to zero in the "On Death" block. You need to add a line there such as "set fElapsed to 0". (It's better to be explicit than rely upon an implication that it was initialized at definition because the GameMode block(s) containing the timer tests run every frame while "OnDeath" is a single frame processing occurrence that can happen multiple times. Please see the 'TIP Block Types Multiple vs Single Frame processing' under the "Scripting" section of the wiki "Getting started creating mods using GECK" article.) Change your "If getsecondspassed" test statements to "if fSeconds < fElapsed". Now you are testing if sufficient time has elapsed to exceed the random number of seconds since death. getsecondspassed function: "Returns the number of real life seconds that have passed since this function was last called by the calling script." IT does not "accumulate" time; it measures that elapsed between calls to the function. Your timer variable has to do the "accumulating" between calls. Then in the "GameMode" blocks you need to have an "Else" condition to your recast "if getsecondspassed" statements so that when that test fails (because enough time has NOT passed), you then update the "fElapsed" variable with how many seconds HAVE passed by that point in time with "set fElapsed to fElapsed + getsecondspassed". The basic timer tutorial is located here. There is another example of a timer in 'Tip Random NPC Comments' under the "Dialogue and Lipsynch" section as well. Some suggestions: It is a "best practice" to put "constant values" and "variables" to the left side of a comparison test instead of a "function", and if the comparison is only a single type (i.e. "=") instead of a compound type (i.e. "<=" is "less than OR equal"). So your timer condition test would be better structured as: if Seconds > getsecondspassedBetter yet would be to assign the current value of the function "getsecondspassed" to a variable ("fElapsed") so that function only gets called once in the frame and the storage variable is used in all subsequent tests. Variables declared OUTSIDE the BEGIN blocks retain their value between runs, and in save games. Variables declared INSIDE a BEGIN block will be reset to 0 each time the script is run. As a general practice: Declare all your variables at the top. If you declare them all over the place when you need them, you'll eventually regret it. You are using variable names that closely resemble function names. This leads to confusion. Please see the 'TIP Best Practice Type prefixes for Variables' and other "TIPs" under the "Scripting" section. See also 'TIP AI Packages and Distance' under the "Custom NPCs" section. The following can wait until you have the basics of the above script working correctly. Instead of multiple "GameMode" blocks that are all testing the same basic conditions, structure the tests as a series of "If / ElseIf / Else" nested conditions. Everything that only needs to be tested "if 1 == getdead" should be nested under that condition's "true" branch. Don't try to test changing condition variables within the same frame (such as "Set GhoulFloat" by using multiple "GameMode" blocks unless it is essential. You need to give them time to register their new state. Waiting until the next frame for the "If / ElseIf / Else" block to proceed to the next "true" condition usually won't matter. And the "Scripting" section has links to various tutorials. -Dubious- Link to comment Share on other sites More sharing options...
Recommended Posts