Jump to content

[LE] Script help for prevent a script run more than one time per day


elafrosicky

Recommended Posts

Since items can't reference or call functions on themselves when they are in an inventory, you have to use a magic effect instead to make use of something like OnUpdateGameTime().

 

So stick this script on a magic effect, with it's properties at least set to Script > Constant Effect > Self.

 

 

Scriptname MyMagicScriptName extends activemagiceffect  

Event OnEffectStart(Actor akTarget, Actor akCaster)
	RegisterForSingleUpdateGameTime(24) ;Measured by in-game hours. Fires the update event after the first day.
endEvent

Event OnUpdateGameTime()	
	;Do stuff.
	RegisterForSingleUpdateGameTime(24)	;Loop it. Should automatically UnregisterForUpdateGameTime, and stop listening for updates when the spell dispels.
endEvent

 

 

Make sure to read the wiki about how OnUpdateGameTime() works, and such. Make sure you don't loop these updates endlessly, bogging down the Papyrus engine.

 

Also create a new Spell set to Ability then add your magic effect to it.

 

Then attach this script to your item, if you want it to run if its in the player inventory instead.

 

 

Scriptname MyItemScriptName extends ObjectReference 

Actor property PlayerRef auto	;Make sure to assign this to the player ref in (any) cell. If we only needed to get the player once, use Game.GetPlayer() instead.

Spell property aSpell auto	;Assign this to your ability spell.

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	if akNewContainer == PlayerRef	;Only add the spell if its in the players inventory.
		PlayerRef.AddSpell(aSpell, false)
	else    ;Removes the spell if the item ends up anywhere but the players inventory.
		PlayerRef.RemoveSpell(aSpell)
	endif
endEvent

 

 

 

Otherwise this will run if you have it equipped or unequipped.

 

 

Scriptname MyItemScriptName extends ObjectReference 
{Add spell on equipped. Written by Wilbur Cobb / smashballsx88}

Actor property PlayerRef auto	;Make sure to assign this to the player ref in (any) cell. We want this since we need to get the player more then once, otherwise use Game.GetPlayer()

Spell property aSpell auto	;Assign this to your ability spell.

;Form, Weapon, Armor ... ect, as long as it extends Form. property MyItemProperty auto

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
        CheckIfEqByPlayer()    ;OnEquipped() wont fire if equipped right out of a container. This will make sure to still add the spell.
endEvent

Event OnEquipped(Actor akActor)
        CheckIfEqByPlayer()
endEvent

Event OnUnequipped(Actor akActor)
    if akActor == PlayerRef
        PlayerRef.RemoveSpell(aSpell)
    endif
endEvent

Function CheckIfEqByPlayer()    ;This function will make sure the player has the item equipped.
    if PlayerRef.IsEquipped(MyItemProperty)    ;Set this to a property, which points to the form of your item. You cant use self when its in the inventory.
        PlayerRef.AddSpell(aSpell, false)
    endif
endFunction

 

 

This Script Objects map should help you see what all extends Form.

 

Make sure to use this wiki page to read notes on all the functions present in these scripts. Cheers.

Edited by smashballsx88
Link to comment
Share on other sites

  • Recently Browsing   0 members

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