Jump to content

[LE] Simple question related to "delete.self" in a script.


Recommended Posts

Do activators (mostly invisible activators) that their scripts have a "delete.self" keep having traces in the "save file" or after "deleting" (delete.self) all traces of the script and their Refs are also deleted from the save file ?.


And if NO, then what's the use of it inside a script ?.


I'm researching this and i can't find anything releated to this online.

Edited by maxarturo
Link to comment
Share on other sites

You asked: "Do activators .. keep having traces in the save file or after 'delete()' are all traces of the script also deleted".
It depends on level of persistence for this activator! Activators are objectReference with own subType.

IF self.IsEnabled()
    self.Disable()       ; 1
ENDIF
    self.Delete()        ; 2

probably you know already: https://www.creationkit.com/index.php?title=Delete_-_ObjectReference

 

Only references created in game can actually be deleted.
Remember that Delete() only flags an object for deletion. What does it mean?

The method "delete()" is pushing the refID into a garbage pool, but it can be deleted (script as well) only, if no other script or script property is pointing to this refID. Its clear now?

 

vanilla sample scripts:

PlayerHorseScript

 

;/ Scriptname PlayerHorseScript extends ReferenceAlias  

Event OnDeath(Actor akKiller)
    MySelf = GetActorReference()
EndEvent

Event OnUnload()
    If MySelf.IsDead() == 1
        ; disable the dead horse if it is unloaded
        MySelf.Disable()
        MySelf.Delete()
        ; added a new horse that can be bought at the stables
        Myself = StablesPosition.PlaceActorAtMe(LvlHorseSaddled)
        Alias_HorseRef.ForceRefTo(MySelf)
        Alias_HorseRef.GetRef().SetFactionOwner(StablesFaction)
    EndIf
EndEvent


Actor Property MySelf  Auto  

ObjectReference Property StablesPosition  Auto  

ActorBase Property LvlHorseSaddled  Auto  

ReferenceAlias Property Alias_HorseRef  Auto  

Faction Property StablesFaction  Auto  ### original script inside ### /;

; ###################################################################
; ###################################################################

Scriptname PlayerHorseScript extends ReferenceAlias  
{v1.4 ReDragon 2014}

  ActorBase PROPERTY LvlHorseSaddled auto  
  Faction   PROPERTY StablesFaction  auto  

  ReferenceAlias  PROPERTY Alias_HorseRef  auto
  ObjectReference PROPERTY StablesPosition auto  
  Actor           PROPERTY MySelf          auto  


; -- EVENTs -- 2

EVENT OnDeath(Actor akKiller)
    MySelf = self.GetActorReference()
    Debug.Notification("Horse is dead!!")
ENDEVENT


EVENT OnUnload()
IF (MySelf) && MySelf.IsDead()
ELSE
    RETURN    ; - STOP -    horse is still alive
ENDIF
;---------------------
; clean up the dead horse
    MySelf.Disable()
    MySelf.Delete()
    MySelf = None

; add a new horse that can be bought at the stables
    Myself = StablesPosition.PlaceActorAtMe(LvlHorseSaddled)
    Alias_HorseRef.ForceRefTo(MySelf as ObjectReference)
    MySelf.SetFactionOwner(StablesFaction)
ENDEVENT

 

 

 

defaultDeleteSelfOnReset

 

;/ Scriptname defaultDeleteSelfOnReset extends ObjectReference Hidden
{DOES NOT DO WHAT ITS NAME IMPLIES.  ITS HAD CHANGES MADE TO IT SPECIFICALLY FOR FIXING A NIRNROOT GLOW ISSUE.}

EVENT OnCellAttach()
    self.Disable()
    self.Delete()
endEVENT ### original script inside ### /;

;/ #######################################################################

[02/26/2014 - 08:16:27PM] error: Unable to call Disable - no native object bound to the script object, or object is of incorrect type
stack:
    [<NULL form> (FF000D08)].defaultDeleteSelfOnReset.Disable() - "<native>" Line ?
    [<NULL form> (FF000D08)].defaultDeleteSelfOnReset.OnCellAttach()
- "defaultDeleteSelfOnReset.psc" Line 5

[02/26/2014 - 08:16:27PM] error: Unable to call Delete - no native object bound to the script object, or object is of incorrect type
stack:
    [<NULL form> (FF000D08)].defaultDeleteSelfOnReset.Delete() - "<native>" Line ?
    [<NULL form> (FF000D08)].defaultDeleteSelfOnReset.OnCellAttach()
- "defaultDeleteSelfOnReset.psc" Line 6
########################################################################## /;

Scriptname defaultDeleteSelfOnReset extends ObjectReference Hidden
{v1.4 ReDragon 2014}    ; does not do what its name implies

; Its had changes made to it specifically for fixing a nirnroot glow issue.


; -- FUNCTION --

FUNCTION myF_Info()
;------------------
    string s = "OnCellLoad() -  self = " +self
           s+= ", baseObject = "

    form fm = self.GetBaseObject()
    int   i = fm.GetFormID()

    self.Delete()

    IF     (i == 0x000E2FF9)            ; NirnrootEmptyACTIVATOR [ACTI:000E2FF9]
        s+= "NirnrootEmptyACTIVATOR"
    ELSEIF (i == 0x000E1FB4)            ; NirnrootGlowACTIVATOR [ACTI:000E1FB4]
        s+= "NirnrootGlowACTIVATOR"
    ELSE
        s+= fm
    ENDIF
    Debug.Trace(s)
ENDFUNCTION


; -- EVENT --

EVENT OnCellLoad()
    self.DisableNoWait()
    myF_Info()
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Thanks ReDragon for your explanation !

 

It's kind of clear.

So if i "delete.self" only the "trigger box - Activator" the static object that the script - Activator is controlling won't get delete, i'll will have to put also a "delete.self" after "disable.self" to the static object too.
Also, if is not too much trouble or i'm asking too much, could you take a look at this Script, i cant seem to make it work - compile or if it is compiling it won't work.
The script below is just one of many attempts.... It's giving me a headache...


Scriptname aXMDshrinePowerUpSCRIPT01 extends ObjectReference  
{Activate custom Shrine & with 10 Filled Black Souls Gems gain 10 points of Health or Magicka or Stamina}
 
 
bool property isHealth auto
bool property isMagicka auto
bool property isStamina auto
{Assign the correct Actor value to Activator}
 
SoulGem Property FilledBlackSouls Auto
{Requierd item - Black Soul}
 
Message PROPERTY NoBlackSoulsMessage01 auto
{Message to show - HEALTH -if you don't have BlackSouls}
 
Message PROPERTY NoBlackSoulsMessage02 auto
{Message to show - MAGICKA - if you don't have BlackSouls}
 
Message PROPERTY NoBlackSoulsMessage03 auto
{Message to show - STAMINA - if you don't have BlackSouls}
 
EffectShader Property PowerUpVisualFX  Auto  
{Visual FX to Play when Powered up on SELF}
 
Sound Property PowerUpSoundFX  Auto  
{Sound FX to play when Powered up}
 
bool Property isTriggered = false auto hidden
 
 
 
Event onActivate(ObjectReference akActionRef)
                 If (isTriggered != TRUE && akactionref.getitemcount(FilledBlackSouls) >= 10)
                 If (akActionRef.getAssociatedActorValue() == "Health") && isHealth
                     solveMe(akActionRef)
                     Game.GetPlayer().SetActorValue("Health",( Game.GetPlayer().GetBaseActorValue("Health") + 10))
           elseif (akActionRef.getAssociatedActorValue() == "Magicka") && isMagicka
                     solveMe(akActionRef)
                     Game.GetPlayer().SetActorValue("Magicka",( Game.GetPlayer().GetBaseActorValue("Magicka") + 10))
           elseif (akActionRef.getAssociatedActorValue() == "Stamina") && isStamina
                     solveMe(akActionRef)
                     Game.GetPlayer().SetActorValue("Stamina",( Game.GetPlayer().GetBaseActorValue("Stamina") + 10))
            else
                    (isTriggered != FALSE && akactionref.getAssociatedActorValue() == "Health") && isHealth
                    NoBlackSoulsMessage01.Show()
            else
                    (isTriggered != FALSE && akactionref.getAssociatedActorValue() == "Magicka") && isMagicka
                    NoBlackSoulsMessage02.Show()
            else
                    (isTriggered != FALSE && akactionref.getAssociatedActorValue() == "Stamina") && isStamina
                    NoBlackSoulsMessage03.Show()
            EndIf
         EndIf
EndEvent
 
 
 
FUNCTION SolveMe(objectReference whoSolved)
    isTriggered = true
                    akactionref.removeitem(FilledBlackSouls, 10)
                    Game.ForceThirdPerson()
                    PowerUpSoundFX.Play(game.GetPlayer())
                    PowerUpVisualFX.Play(game.GetPlayer(),3)
endFUNCTION

This is a short version of the same script working just fine, but i have to make three of them, one for each Value and shrine Health - Magicka - Stamina

Scriptname aXMDshrinePowerUpSCRIPT01 extends ObjectReference  
{Activate custom Shrine & with 10 Filled Black Souls Gems gain 10 points of Health}
 
 
SoulGem Property FilledBlackSouls Auto
{Requierd item - Black Soul}
 
Message PROPERTY NoBlackSoulsMessage01 auto
{Message to show - HEALTH -if you don't have BlackSouls}
 
 
EffectShader Property PowerUpVisualFX  Auto  
{Visual FX to Play when Powered up on SELF}
 
Sound Property PowerUpSoundFX  Auto  
{Sound FX to play when Powered up}
 
bool Property isTriggered = false auto hidden
 
 
 
Event onActivate(ObjectReference akActionRef)
             If (isTriggered != TRUE && akactionref.getitemcount(FilledBlackSouls) >= 10)
                 Game.GetPlayer().SetActorValue("Health",( Game.GetPlayer().GetBaseActorValue("Health") + 10))
                 akactionref.removeitem(FilledBlackSouls, 10)
                  Game.ForceThirdPerson()
                  PowerUpSoundFX.Play(game.GetPlayer())
                  PowerUpVisualFX.Play(game.GetPlayer(),3)
            else
                  NoBlackSoulsMessage01.Show()
            EndIf
EndEvent

 

 

 

Thank you very much in advance !!

Edited by maxarturo
Link to comment
Share on other sites

Well, for starters, you shouldn't need three versions of the script: The same script with a string property that gets filled with the AV you want to change will work in all three cases. Is this intended to be a once-ever use? The coding suggests it.

Link to comment
Share on other sites

Well, for starters, you shouldn't need three versions of the script: The same script with a string property that gets filled with the AV you want to change will work in all three cases. Is this intended to be a once-ever use? The coding suggests it.

No is not intended to be used only once, but the player can activate each shrine and gain Health or Stamina or Magicka whenever he wants, if he has 10 Black Souls.
And that's what i'm trying to do, merge the three scripts into one, the merge script has property with the AV to change for each shrine.
bool property isHealth auto

bool property isMagicka auto

bool property isStamina auto

The single script works fine everytime i activate it.
Link to comment
Share on other sites

The reason I asked about single use is that you have an if-statement checking a flag that's meant to track if the activation has happened, but you never set it. Wasn't sure what the intent was.

 

Some small tweaks:

 

 

Scriptname aXMDshrinePowerUpSCRIPT01 extends ObjectReference  
{Activate custom Shrine & change an ActorValue if the activator has a number of Filled Black Soul Gems }
 
String Property sWorkingAV Auto
{Sets what ActorValue to work on}

SoulGem Property FilledBlackSouls Auto
{Required item - Black Soul}

int Property iSacrificeCount = 10 Auto
{Number of items required. Default 10}

float Property fActorValueBoost = 10.0 Auto
{How much to change the ActorValue by. Default 10}

Message PROPERTY NoBlackSoulsMessage01 auto
{Message to show if you don't have BlackSouls}
 
EffectShader Property PowerUpVisualFX  Auto  
{Visual FX to Play when Powered up on SELF}
 
Sound Property PowerUpSoundFX  Auto  
{Sound FX to play when Powered up}
 
;bool Property isTriggered = false auto hidden
;not needed if multiple uses intended
 
Auto State Waiting
 
Event OnActivate(ObjectReference akActionRef)


    GotoState("Activated")
    ;protects against the player spamming the activate button for free upgrades

    Actor ActorRef = akActionRef as Actor
    if !ActorRef
        GotoState("Waiting")
        return
    endif
    ;makes sure the activator is an actor
    if ActorRef != Game.GetPlayer()
        GotoState("Waiting")
        return
    endif
    ;makes sure the activator is the player. This supercedes the prior check, but this way you can easily choose whether to make this work for NPCs or not.

    if ActorRef.GetItemCount(FilledBlackSouls) < iSacrificeCount
                  NoBlackSoulsMessage01.Show()
    else
    ;If (isTriggered != TRUE && akactionref.getitemcount(FilledBlackSouls) >= 10)

        ActorRef.SetActorValue(sWorkingAV, ActorRef.GetBaseActorValue(sWorkingAV) + fActorValueBoost)
        ActorRef.RemoveItem(FilledBlackSouls, iSacrificeCount)
        Game.ForceThirdPerson()
        PowerUpSoundFX.Play(ActorRef)
        PowerUpVisualFX.Play(ActorRef, 3)
    endif

    GotoState("Waiting")
    ;resets the state back to await the next activation
EndEvent

EndState

 

 

Haven't plugged this into the compiler, so, you know, typos etc may cause errors, but it should work so that all you need to do to make it work for any ActorValue and amount is to set the properties appropriately. WIth a bit of further work you could make it work for any item at all as the sacrifice (or multiple different items in any counts you choose), but that's not what you're after here.

 

The state change is done so that any other OnActivate events that arrive whilst the first one is processing, say because the player is hammering the interact button, will be thrown out. This is a precaution against a race condition where several OnActivate blocks will run the GetItemCount() call before any of them run the RemoveItem() call, allowing the player to potentially get multiple boosts per set of soulgems.

Link to comment
Share on other sites

Thanks a lot foamyesque !.


Your script version is very similar to my first attempt that actually worked.

But the main issue i have is that i want each shrine to display its own "NoBlackSouls" message, and this is where the script gets F****.

I have a working merge script which shows only one common message for the three shrines.


I'm done with this for today...


Thank you very much for spending your time thinking about this one !,

Link to comment
Share on other sites

HOLY S**** !!!

I just realize what a potato i did with the "message".

The first script i made was working fine... i was the stupid !!!!.....

Edited by maxarturo
Link to comment
Share on other sites

I write some stuff but its not very important xD

Your effect can be easly deleted by other mods :x

 

so better way is using Magic Effects or something like this maybe Perks instead of SetValue

 

 

Full Post: xD

 

 

 

 

 

Scriptname aXMDshrinePowerUpSCRIPT01 extends ObjectReference
{Activate custom Shrine & with 10 Filled Black Souls Gems gain 10 points of Health}

 

 

So your Scripts not gonna work with other mods :tongue:

for example Succubus Heart

 

Succubus heart ignore everything and overwrite player HP MP SP

so if you add player 10 HP points succubus heart will easly delete it :tongue:

 

cause if you... ugh xD not use it you loset your Max hp mp sp

and if you use it you gain more hp mp sp :D

 

with Succubus Heart your HP MP SP may hit 1 point :tongue:

even if player bought your "upgrade"

 

 

 

even better if you have Wounds mod ( ugly russian letters so i can't write this name ) and Succubus Heart you can have hp less than 0 :tongue:

 

once i had -723 hp xD "Battle Wounds" applay to my character every possible debuff cause my hp was less than 0 so i got Wounds every sec

 

 

 

im not sure but Perks and Potions can give player hp even if Succubus Heart is blocking it

i have one mod that change Dragon Souls to special powers and this mod don't have problems with Succubus Heart

also im not sure but maybe "Complete Alchemy" is using something else than "SetValue" cause drinking / eathing also give you HP that can't be taken back by Succubus Heart

 

 

im not sure how those 4 mods works but they will remove your buffs probably :tongue:

 

so better idea is give player some kind of Perk or Magic Effects or somethings :tongue:

 

 

i know SetValue will not work cause once i use SetValue in game and Succubus Heart have remove my health anyway :c

 

 

 

 

but you don't have to change it xD

you can change it if you want make your mod compatible with other mods :tongue:

 

#Sry4MyPotatoEnglish :smile:

 

 

 

im 100% sure spells will work fine cause i have spell "Infinite Ice Body"

this spell give you 250% of your max hp and make you 100% resist to Ice Magic

 

and it work as 10 time longer than you have casting this spell

for example if you casted this spell for 10 sec it will stay on you for 600 seconds xD

 

so lel you can duplicate your hp just by holding this spell while you walk for example for 5 min so this spell will stay 1 hour :tongue:

and then in Skill Menu your HP is green color and it can't be changed by Succubus Heart

 

 

its PROBABLY cause its Spell and Succubus heart change just base value of player healt

 

 

 

also you can make shrines that for example exchange 1 Black Soul for 10 Hp / Mp / Sp and after 24 h you can use this shrine again :D

 

 

ok im gonna move it to Spoiler xD

 

 

Im lvl 44 and i have 490 Hp 580 Mp and 300 Sp xD

 

Yey, Succubus Heart <3

 

also i die by 1 shot of almost any weapon xD

 

Yey, Weapon DMG UI and Hardcore Mode <3

 

 

 

 

Edited by TobiaszPL
Link to comment
Share on other sites

Hey Toby.

I don't really mind if an other mod will delete or overwrite it, this is just a small bonus attached to a possible "player's house" in a secret room (if he decides to use it as a player's house).


The mod's secret room offers the player the chance to gain 10 point of Health or Stamina or Magicka, or gain a Perk for the Perk tree or advance any Skill he wishes to (level up), always for a price.

I'm even thinking to add a sacrifice ritual for those players playing dark characters.


So i don't really mind for other mods overwriting it, it doesn't have a PRIMARY importance, especially since the house has Sooooo much more to offer to the player.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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