Jump to content

Scripting help - OnMagicEffectApply() target?


BurnyD

Recommended Posts

Working on an update to SLIA, and wanted to extend some events to actors other than the player.  Generally this has been pretty straightforward, but with the objects that require a magic effect to work (ingestibles for example), I'm hitting a wall.

 

I see two versions of the OnMagicEffectApply() event.

 

For ObjectReference - http://www.creationkit.com/index.php?title=OnMagicEffectApply_-_ObjectReference

For ScriptObject - http://www.creationkit.com/fallout4/index.php?title=OnMagicEffectApply_-_ScriptObject

 

Previously I was using the ObectReference version and it was working, but it doesn't tell you who the target is, only who the caster is.  The ScriptObject one has the target, but I don't think it's what I need (it didn't work cleanly in the script anyways, it threw an error about the parameters not matching).

 

I'd guess there has to be a simple way to see who the magic effect is applying to, but I'm at a loss.  Any help would be appreciated.

 

Here is an example of the script as it stands.  I would like to add an If statement to the SLIA function that checks if the target is the player, then uses sPlayerMale/Female if so and sTargetMale/Female if not.  I'd also need to change the last parameter of the function to the target rather than explicitly the player.

 

 

Scriptname SLIA_Potion extends activemagiceffect  

 
SLIA_Core property SLIA auto
 
; This script is for potions
 
int iExposure = 25
string sPlayerMale = "A feeling of warmth travels straight to your groin."
string sPlayerFemale = "A feeling of warmth travels straight to your groin."
 
string sTargetMale = "A feeling of warmth travels straight to his groin."
string sTargetFemale = "A feeling of warmth travels straight to her groin."
 
Auto State Active
 
Event OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect)
 
SLIA.ArousalTrigger(iExposure, sPlayerMale, sPlayerFemale, Game.GetPlayer())
 
GoToState("Inactive")
 
EndEvent
 
EndState
 
State Inactive
 
EndState

 

Link to comment

What about using a different Events of ActiveMagicEffect?

 

Here you have this:

 

Event OnEffectStart(Actor akCaster, Actor akTarget)

 

And inside you can do whatever you want to the actors.

 

 

Code example:

Scriptname SLIA_Potion extends activemagiceffect  
 
SLIA_Core property SLIA auto
 
int iExposure = 25
string sPlayerMale = "A feeling of warmth travels straight to your groin."
string sPlayerFemale = "A feeling of warmth travels straight to your groin."
 
string sTargetMale = "A feeling of warmth travels straight to his groin."
string sTargetFemale = "A feeling of warmth travels straight to her groin."
 
Event OnEffectStart(Actor akCaster, Actor akTarget)
  if akTarget==Game.getPlayer()
    SLIA.ArousalTrigger(iExposure, sPlayerMale, sPlayerFemale, akTarget)
  else
    SLIA.ArousalTrigger(iExposure, sTargetMale, sTargetFemale, akTarget)
  endIf
EndEvent
 
Link to comment

I'll give it a try, thanks!

 

Edit: That seems to have worked.  Simplifies the script as well (needed the states before because the OnMagicEffectApply() was triggering multiple times).

 

I actually have no way that I know of to test it working on another target because I don't know how to make an NPC drink something or take a potion, but... well, in theory it should work so I'll just assume it works.

Link to comment

I was never able to make a NPC to drink a potion, also a follower.

I did a trick that was to create an actual Spell that will force a Drinking Idle to the NPC and then use the code in the MagicEffect to do what you want.

And then you cast by script the spell when you need it.

 

Link to comment

I only wanted to add support for such a thing because people asked for it, I haven't gotten to do it either.  I also added support for equipping certain clothing working on the NPC as well, though consoling equipitem to them didn't trigger the event.  But maybe some mod out there does, idk.

 

I did make a spell as well for the mod, with the weird condition that when the spell is cast (healing hands modified, so concentrated spell on target actor), the akTarget was the player and the akCaster was the NPC, although it was me casting it on him.  I wonder if that is being flipped in the case of potions as well, but I have no way to tell unless someone figures out a way to make an NPC take a potion / drink some ale or whatever and complains.

Link to comment

If you want a NPC to "drink a potion":

 

Create a Package, tyoe "DoNoting", stop movement, wait 2 secs.

Crate a Package Fragment, in the OnStart put as property a Spell that has the magic effect you defined.

As code: mySpell.cast(akActor, akActor)

Go in the Idles tab, pick the idle DrinkPotion (maybe it as a slightly different name, I don't remember, but it is the only one with Drink inside.), and set to play the specific idle.

 

Now you have just to give this package to a NPC (any way is good), and when it will be executed you will have your result.

 

Link to comment

Archived

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

  • Recently Browsing   0 members

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