Jump to content

[Help] Scripting - How to make a spell have an 8 hour cooldown


Recommended Posts

Posted

I'm trying to write a script that allows a player to use a spell to add an item to their inventory based on their race and the spell has an 8 hour cooldown. I got the "add item" part already but I can't figure out how to script the cooldown part. Any help would be appreciated.

 

Sample script:

Spoiler

Scriptname MySpell extends ActiveMagicEffect  

 

;Defines the ingredients used in this script
Ingredient Property DaedraHeart Auto
Ingredient Property BriarHeart Auto

 

;Defines the races used in this script
Race Property ImperialRace Auto
Race Property ImperialRaceVampire Auto
Race Property NordRace Auto
Race Property NordRaceVampire Auto

 

;Defines the target actor
Actor Property PlayerREF Auto

 

Event onEffectStart(Actor akTarget, Actor akCaster)
    
    Race PlayerRace = PlayerREF.GetRace()
        
    If PlayerRace == ImperialRace || PlayerRace == ImperialRaceVampire
        PlayerREF.AddItem(DaedraHeart,1,true)
        debug.notification("Daedra Heart Added")

    Elseif PlayerRace == NordRace || PlayerRace == NordRaceVampire
        PlayerREF.AddItem(BriarHeart,1,true)
        debug.notification("Briar Heart Added")

    Endif
EndEvent

 

Posted
25 minutes ago, RangerEdas said:

I'm trying to write a script that allows a player to use a spell to add an item to their inventory based on their race and the spell has an 8 hour cooldown. I got the "add item" part already but I can't figure out how to script the cooldown part. Any help would be appreciated.

 

Sample script:

  Hide contents

Scriptname MySpell extends ActiveMagicEffect  

 

;Defines the ingredients used in this script
Ingredient Property DaedraHeart Auto
Ingredient Property BriarHeart Auto

 

;Defines the races used in this script
Race Property ImperialRace Auto
Race Property ImperialRaceVampire Auto
Race Property NordRace Auto
Race Property NordRaceVampire Auto

 

;Defines the target actor
Actor Property PlayerREF Auto

 

Event onEffectStart(Actor akTarget, Actor akCaster)
    
    Race PlayerRace = PlayerREF.GetRace()
        
    If PlayerRace == ImperialRace || PlayerRace == ImperialRaceVampire
        PlayerREF.AddItem(DaedraHeart,1,true)
        debug.notification("Daedra Heart Added")

    Elseif PlayerRace == NordRace || PlayerRace == NordRaceVampire
        PlayerREF.AddItem(BriarHeart,1,true)
        debug.notification("Briar Heart Added")

    Endif
EndEvent

 

 

Assuming you want to do this through script alone (not always the best, but should work fine for this), you'd ideally create two states (active/inactive) with inactive being the default state.

 

After consuming the ingredient, the spell goes to the active state, where it either tracks time internally ("registerforsingleupdate(28800.0)") or tracks current game time and checks every x amount of time to see if that has passed.

 

You will want a system in there for detecting sleep/wait events as well so that the system behaves appropriately.

 

If the spell is triggered again during the "active" state, it does nothing and no ingredient is consumed.

 

Once the active state finishes (8 hrs), it flips back to the inactive state and the spell effects terminate (either though built-in cooldown on the spell itself, or through a dispel/removespell option).

 

Thats just top of my head, there may be more efficient ways of doing it.  (Still on my first coffee).

  • 2 months later...
Posted
On 4/19/2022 at 7:14 PM, Seijin8 said:

 

Assuming you want to do this through script alone (not always the best, but should work fine for this), you'd ideally create two states (active/inactive) with inactive being the default state.

 

After consuming the ingredient, the spell goes to the active state, where it either tracks time internally ("registerforsingleupdate(28800.0)") or tracks current game time and checks every x amount of time to see if that has passed.

 

You will want a system in there for detecting sleep/wait events as well so that the system behaves appropriately.

 

If the spell is triggered again during the "active" state, it does nothing and no ingredient is consumed.

 

Once the active state finishes (8 hrs), it flips back to the inactive state and the spell effects terminate (either though built-in cooldown on the spell itself, or through a dispel/removespell option).

 

Thats just top of my head, there may be more efficient ways of doing it.  (Still on my first coffee).

 

On 4/19/2022 at 7:03 PM, Tlam99 said:

Check the script of the perk avoid dead, restoration line

 

 

Sorry for the necro but I just wanted to say thanks for your help. I couldn't get the cooldown to work using states but using the script of the avoid dead perk worked perfectly.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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