Jump to content

Papyrus: ActiveMagicEffect Function Calls?


Feliks

Recommended Posts

Posted

So I'm sitting here on a nearly completed mod, and the last thing I needed was a quest when the game starts up to apply an effect to the player. That part works fine.

 

The part that screwed up was when I had it check to see if the effect was already there, and if so dispel it (in case future updates change the script enough that the effect needs to be reapplied.) and the compiler started throwing errors that "Dispel is not a function or does not exist" 

 

So I looked into that, and have come to the conclusion that the issue is not that Dispel is not a function (it is) or that I'm not calling it on a Magic Effect (I am) but that Dispel applies to ActiveMagicEffects, which are not referenced the same way as regular magic effects.

 

 

So my question is, if I have an effect attached to a player and/or an NPC how would I call functions in the script of the effect from another code?

 

 

edit:

 

 

Example One:

Access the script functions on a created ObjectReference:
ObjectReference Pony1 = PlayerRef.PlaceAtMe(myCustomPony)   ;create two ponies. Let us assume that myCustomPony is a base Actor that has 'PonyScript.psc' attached to it.
ObjectReference Pony2 = PlayerRef.PlaceAtMe(myCustomPony)
PonyScript Pony1Script = Pony1 as PonyScript                ;declare two variables, each pointing to the INSTANCE of PonyScript attached to one particular pony
PonyScript Pony2Script = Pony2 as PonyScript                
Pony1Script.groomPony()                                     ;groom pony one, using the groomPony() function in (its instance of) PonyScript
Pony2Script.killPony()                                      ;kill pony two, using the killPony() function in (its instance of) PonyScript

Note: sometimes you will have to cast the object with ScriptB attached to it before declaring the variable will work. Let us say that Pony1 was an Actor instead of an ObjectReference, for instance. Since PonyScript extends ObjectReference, we first need to cast Pony1 as an ObjectReference before we can cast it as a PonyScript, otherwise the compiler will throw out errors:

Actor Pony1 = somePony
PonyScript Pony1Script = (Pony1 as ObjectReference) as PonyScript


Example Two:
Find an Actor's linked reference, and conditionally access the script functions on that reference:

ObjectReference possibleTable1 = Actor1.GetLinkedRef()
if (possibleTable1 as Furniture) == magicTable                         ;is the actor linked to a magicTable?
  magicTableScript TableScript1 = possibleTable1 as magicTableScript
  TableScript1.explode()                                               ;if so, use the magicTable's script function to make the magicTable explode!
endif

 

 

Found this on creationkit.com, this feels like it should be relevant but I can't think of how to get it to work for an active effect

Posted

Alright, so a few hours of research and testing did very little on my end before I made this post. Changed one word in my google search (from to in) and this gem popped up. Testing that out right now.

 

Edit: Yes. This is the perfect way to effect activemagiceffects from a quest, which it turns out is exactly what I needed, I just didn't quite understand that.

Posted

There are a couple ways that I would dispel a magic effect when I wanted (and there might be other ways but these are the ways I know).

1) You could have your magic effect's script OnEffectStart() use the command RegisterForModEvent() (and have Dispel() get called when it receives such an event) and then you could use SendModEvent() in some script whenever you need it.

2) You could give your magic some effect some unique keyword then create another (dummy) magic effect with that same keyword but with "Dispel Effects with these Keywords" checked, and then apply that effect on the player whenever you want to dispel the first magic effect.

Posted

Wow, those are both really neat workarounds. I'm not sure I ever would have thought of the second one.

 

Although for the framework portion of the mod the jbezorg thread I found holds the key to making it all work. Watch out for this release. I hope it's as useful as I think it will.

 

 

Also I never thanked you for your answer to my array question a week or so ago (changed internet providers, without internet for 6 days) but that did solve my problem.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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