Jump to content

Can I get the Base Id of a spell target with Papyrus?


Pancakes22

Recommended Posts

I'm trying to make a spell that adds a different item to your inventory depending on which NPC you use it on, say if you used it on Carlotta in Whiterun it would give you a differnt item than if you used it on Ysolda in Whiterun. Is this possible? If not, can I get the name of the actor? Eg using it on Carlotta would return a string with a value of "Carlotta Valentia"

Link to comment
Share on other sites

Apply a script to the magic effect of your spell. Use the event OnEffectStart, akTarget should provide the actor. You then compare akTarget to your pre-filled actor properties of whom you want to provide different items. But this requires you to list out all the NPCs you want to work with. Tedious work and not usable with mod added NPCs.

 

It's all I got. Brainstorming turned into a brain fart, sorry :P

Link to comment
Share on other sites

  • 3 years later...

Apply a script to the magic effect of your spell. Use the event OnEffectStart, akTarget should provide the actor. You then compare akTarget to your pre-filled actor properties of whom you want to provide different items. But this requires you to list out all the NPCs you want to work with. Tedious work and not usable with mod added NPCs.

 

It's all I got. Brainstorming turned into a brain fart, sorry :tongue:

Yes, this is the same FUGLY conclusion I've come to... and you're right, it is cumbersome, tendious, and limited to the extreme!

 

I'm still searching for a better solution or some kind of trickly work around, and I think there may be one in the usage of a Quest Script, and attached ReferenceAlias set to the ActorRef from akTarget, which is found in the Magic Effect Script, and set in a script which fires on the OnEffectStart event, as you've stated...

 

But I cannot find enough clear documentation / examples about how to use Quest ReferenceAlias mechanism to even begin the test coding of it?

 

There are lots of places where it is talked about, but no one provides a clear, step by step tutorial on how to implement it.

 

Here are a few related web pages:

 

https://www.creationkit.com/index.php?title=ObjectReference_Script

 

https://forums.nexusmods.com/index.php?/topic/5282495-papyrus-oneffectstart-and-quest-alias-question/

 

https://forums.nexusmods.com/index.php?/topic/2071309-referring-to-actor-activemagiceffect-script/

 

https://github.com/xanderdunn/skaar/wiki/Understanding-Forms,-Object-References,-Reference-Aliases,-and-Persistence

 

Clearly, these people are all pursuing the same thing, but no one seems to have a clear idea how it is actually done!

 

I SEE it being done in some other complex mods, such as "Interesting NPCS", but those mods are far, far too large, and complex, to reverse engineer.

 

I (we) need a simple, clear cut, explained, tutorial example of how to use quests, ReferenceAlias to MagicEffect akTarget values, to pass an actor reference from one script to another.

 

In essence, we need a way to pass an instance (not base) actor ID from one script to another, through what amounts to a Global Variable, like we might pass an Integer of how many materials of a particular type a room or container holds.

 

-

Edited by VanKrill
Link to comment
Share on other sites

Maybe next script samples are helpful to understamd something better. What can you do to transfer script data from one script to another.

 

SampleQuestScript store data inside

 

Scriptname SampleQuestScript extends Quest
{written by ReDragon 2017}
; https://forums.nexusmods.com/index.php?/topic/1100048-can-i-get-the-base-id-of-a-spell-target-with-papyrus/

  ActorBase[] PROPERTY abList auto Hidden
  ActorBase TargetBase

  Bool bBusy


; -- FUNCTIONs -- 2

;-------------------------------------
ActorBase FUNCTION myF_GetLastTarget()
;-------------------------------------
    RETURN TargetBase
ENDFUNCTION

;----------------------------------------
FUNCTION myF_Transfer(ActorBase abTarget)
;----------------------------------------
    WHILE (bBusy)
        Utility.Wait(0.1)
    ENDWHILE
    bBusy = TRUE            ; *T*
;    ---------------------
    TargetBase = abTarget            ; now the variable "TargetBase" has the same value as "akTarget.GetActorBase()" inside MGEF script

    IF (abList.Length <= 0)
        abList = new ActorBase[5]    ; create an array of ? entries, taken 5 as sample
    ENDIF

    int n = abList.Find(abTarget)

IF (n >= 0)
    bBusy = False            ; ***
    RETURN    ; - STOP - actorBase of "abTarget" already stored
ENDIF
;---------------------
int i = 0
    WHILE (i < n)
        IF abList[i]                 ; n=5, abList[0] .. abList[4] are valid
        ELSE
            abList[i] = abTarget
            bBusy = False    ; ***
            RETURN    ; - STOP -    break the loop, end function!
        ENDIF
        i = i + 1
    ENDWHILE
;    ---------------------
    bBusy = False            ; ***
ENDFUNCTION

 

 

 

SampleMGEFScript get data from

 

Scriptname SampleMGEFScript extends ActiveMagicEffect
{written by ReDragon 2017}
; https://forums.nexusmods.com/index.php?/topic/1100048-can-i-get-the-base-id-of-a-spell-target-with-papyrus/
; Skyrim Mod Talk
; VanKrill: searching for a better solution ..  to pass an actor reference from one script to another

  Quest PROPERTY myQuest auto    ; fill inside CK with the desired quest,
      ; quest should have a script attached, which is the place to store akTarget as actorBase for example


; -- EVENTs -- 2

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
    Debug.Trace("Sample: OnEffectStart() - target = " +akTarget+", caster = " +akCaster)        ; only for info
    myF_Action(akTarget)
ENDEVENT

EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    Debug.Trace("Sample: OnEffectFinish() - target = " +akTarget+", caster = " +akCaster)        ; only for info
ENDEVENT


; -- FUNCTION --

FUNCTION myF_Action(Actor akTarget)
;----------------------------------
; http://www.creationkit.com/index.php?title=GetActorBase_-_Actor

    actorBase AB = akTarget.GetActorBase()
;;; form fm = akTarget.GetActorBase() as Form                ; this is the formID

; http://www.creationkit.com/index.php?title=GetLeveledActorBase_-_Actor
    actorBase ABLvl = akTarget.GetLeveledActorBase()
;;; form fmLvl = akTarget.GetLeveledActorBase() as Form      ; this is the formID of leveled Actor

; *********************************************************************************
; Note: "Creating an actor in script from a temporary ActorBase (leveled ActorBase)
;        will cause a CTD when the temporary ActorBase is garbage collected.
;        To make a copy of an actor, use GetActorBase() instead."
; *********************************************************************************
    SampleQuestScript ps = myQuest as SampleQuestScript
    IF ( ps )
        ps.myF_Transfer(AB)
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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