Jump to content

[LE] Trying to run PlaceAtMe in a magic effect, having trouble compiling


ChosenName

Recommended Posts

I'm trying to spawn a health potion using a magic effect, so I've create the effect and attached the following script to it

Scriptname SummonHealthPotion extends ActiveMagicEffect  
{Script to summon a health potion at the player's location}

Potion Property healthPotion Auto  
{The potion summoned by the spell}

Event OnEffectStart(Actor AkTarget, Actor akCaster)
	akCaster.PlaceAtMe(healthPotion)
EndEvent

I then updated the property of the script to attach healthPotion to the proper game object. This compiles fine but doesn't do anything when I cast the spell. Upon reading it seems PlaceAtMe takes a Form parameter and not an object reference, so I tried the following change

Scriptname SummonHealthPotion extends ActiveMagicEffect  
{Script to summon a health potion at the player's location}

Potion Property healthPotion Auto  
{The potion summoned by the spell}

Event OnEffectStart(Actor AkTarget, Actor akCaster)
	akCaster.PlaceAtMe(healthPotion.GetBaseObject())
EndEvent

But then it tells me

GetBaseObject is not a function or does not exist

 

Do you know what I'm doing wrong? Thank you :)

Link to comment
Share on other sites

It looks like your top script should be working. Doubly make sure the property is set and you save your mod after. That will also place the potion right at your feet. If you want to place the potion in front of you, you can do this:

 

Potion Property healthPotion Auto  
{The potion summoned by the spell}

Event OnEffectStart(Actor AkTarget, Actor akCaster)
    ObjectReference PotionRef = akCaster.PlaceAtMe(healthPotion)
    
    float A = akCaster.GetAngleZ()
    Float YDist = Math.Sin(A)
    Float XDist = math.Cos(A)
    YDist *= 100
    XDist *= 100
    PotionRef.MoveTo(akCaster, YDist, XDist, 10.0, False) ;moves potion 100 units in front of caster
EndEvent

decrease or increase the *= 100 to move it closer or farther away.

Link to comment
Share on other sites

Hmmm, I dunno then. That looks all good to me. Try putting a notification in to make sure the script is firing:

 

Event OnEffectStart(Actor AkTarget, Actor akCaster)
    akCaster.PlaceAtMe(healthPotion)
    Debug.Notification("Potion Placed")
EndEvent
Link to comment
Share on other sites

 

Good call! There's no notification so now I know the script is not firing. Now I have to figure out why. Thanks for the help I really appreciate it!

 

Magic effects will only trigger OnEffectStart() events if they are applied to an actor, I believe.

 

 

Yes I think that's correct. Glad you got it working!

Link to comment
Share on other sites

Oh I see, that would explain why switching it to Self worked! Is there a less restrictive starting event I can use - something like OnEffectTriggered? Or perhaps something more related to location-targeted spells, like OnEffectStart(Location a, ...)? I'm not seeing such an event in the ActiveMagicEffect reference.

Edited by ChosenName
Link to comment
Share on other sites

That little trick of the notification telling you if something is working in your script or not is a great way to debug coding problems.

A sound can be used this way also (some languages that's all you get). This is one of them little coding debug tricks no one ever mentions.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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