Jump to content

Could someone look at my Stealth Boy script and tell me why it's not working?


Recommended Posts

Trying to make a simple mod that adds a "Drained Stealth Boy" miscellaneous item to the player's inventory after they have finished using a Stealth Boy (with an extended duration of 300 seconds). The idea is that they can then recharge the Drained Stealth Boy to get a "new" one using the drained one + 100 small energy cells.

 

This was my basic script, but for a reason that I'm not seeing, it isn't adding the Drained Stealth Boy misc object to my inventory after using it in game. Any help as to why would be much appreciated. The issue is clearly with my timer not working as without it the script adds the drained misc item just fine, but I'm not familiar enough to know what's broken.

scn DrainedStealthBoyScript

float timer
short init

begin ScriptEffectStart
    if init == 0
        set timer to 300
        set init to 1
    else
    
        if timer > 0
            set timer to timer - GetSecondsPassed

        else
            additem MiscDrainedStealthBoy 1
        endif
    endif
end
Link to comment
Share on other sites

Please see 'TIP Timers' under the "Scripting" section of the wiki "Getting started creating mods using GECK" article. In particular, the last line about "ScriptEffect".

 

Also note the "GetSecondsPassed" function counts UP. So you are subtracting an ever increasing number of elapsed seconds each frame, which is not what you want. (You are ending prematurely.) Instead compare your "timer" variable to the function result and "set timer to 0" when that threshold is met.

 

-Dubious-

Link to comment
Share on other sites

Please see 'TIP Timers' under the "Scripting" section of the wiki "Getting started creating mods using GECK" article. In particular, the last line about "ScriptEffect".

 

Also note the "GetSecondsPassed" function counts UP. So you are subtracting an ever increasing number of elapsed seconds each frame, which is not what you want. (You are ending prematurely.) Instead compare your "timer" variable to the function result and "set timer to 0" when that threshold is met.

 

-Dubious-

Thank you! So like...

EDIT: No, that isn't giving me the item after the stealth effect wears off.

scn DrainedStealthBoyScript

float Timer

begin ScriptEffectUpdate
    if player.isspelltargetalt StealthBoy
        set Timer to Timer + ScriptEffectElapsedSeconds
    endif

    if ScriptEffectElapsedSeconds >= 300
        set Timer to 0
        additem MiscDrainedStealthBoy 1
    endif
end
Link to comment
Share on other sites

More like (not tested):

scn DrainedStealthBoyScript

float Timer
short Init

begin ScriptEffectUpdate
    if player.isspelltargetalt StealthBoy
       set Init to 1
       set Timer to 1
    else
       ; Stealthboy not in use; the following should not be needed but for safety/testing
       set Timer to 0
       set Init to 0
    endif

    if (0 < Init)
       ; Stealthboy in use
       if (300 < Timer)
          set Timer to 0
          set Init to 0
          additem MiscDrainedStealthBoy 1
       elseif (0 < Timer)
          set Timer to ScriptEffectElapsedSeconds
       endif
    endif
end

* Don't worry about conserving variables. Trying to make one serve "double duty" can cause confusion.

* Avoid using functions in conditional tests; use variables compared to constants whenever possible instead.

* Placing constants on the left side of the comparison is a better practice/habit but not required. I did it here to show how it can be done.

 

-Dubious-

Link to comment
Share on other sites

* Don't worry about conserving variables. Trying to make one serve "double duty" can cause confusion.

* Avoid using functions in conditional tests; use variables compared to constants whenever possible instead.

* Placing constants on the left side of the comparison is a better practice/habit but not required. I did it here to show how it can be done.

 

-Dubious-

Thank you for the advice. Much appreciated. I saved this script in the Geck, however, but sadly, in game, after I used a Stealth Boy and the effect wore off, it did not give me the item the way that it does when I don't have any qualifiers about time.

 

I even tried using gamemode instead, like:

scn DrainedStealthBoyScript

float Timer
short Run

begin GameMode
    if player.isspelltargetalt StealthBoy
        set Run to 1
        set Timer to 1
    else ;(not using Stealth Boy)
        set Run to 0
        set Timer to 0
    endif

    if Run == 1 ;(Using Stealth Boy)
        if Timer == 1
            set Timer to Timer + GetSecondsPassed
        endif
    endif
    if Timer >= 120
        additem MiscDrainedStealthBoy 1
        set Run to 0
        set Timer to 0
    endif
end

But so far nothing has worked.

Link to comment
Share on other sites

Thank you for the help and good advice when scripting. Someone else pointed out that my custom base effect the script was tied to didnt have a duration set. Once I fixed that, I didnt even need to set a timer in the script and could just ScriptEffectFinish for the game block. So it's working now. Thanks!
Link to comment
Share on other sites

  • Recently Browsing   0 members

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