Jump to content

[Script Help] How to check ref on update.


saintgrimm92

Recommended Posts

I'm currently adding a script to a trigger box that's around some liquid poison for a boss fight with a poison dragon.

When the dragon enters the poison, it should be healed. When the player enters the poison, they should take damage.

Event OnTriggerEnter(ObjectReference akActionRef)
if akactionref == dragon
  Heal.Cast(PoisonStream, Dragon)
EndIf
If akactionref == game.getplayer()
  poison.cast(poisonstream, Game.getplayer())
EndIf
RegisterForSingleUpdate(5)
EndEvent

(Also, on trigger leave, unregisterforupdate)

 

So then for the "on update" event, how do I check to see who this is effecting?

I tried:

Event OnUpdate()
if akactionref == dragon
  Heal.Cast(PoisonStream, Dragon)
EndIf
If akactionref == game.getplayer()
  poison.cast(poisonstream, Game.getplayer())
EndIf
RegisterForSingleUpdate(5)
EndEvent

But since onUpdate doesn't have the akactionref syntax, it's unable to compile. I'm not the best scripter by far, so I'm not really sure on any alternatives to check and see whose inside the poison.



EDIT: I've seen multiple scripts on actors, but never on triggers... Can they use more than 1 script? I could simply make 1 script for if akactionref==dragon and a completely different script for if akactionref==player. Might test that out while I wait for a reply here.

Edited by saintgrimm92
Link to comment
Share on other sites

What I would do instead, is use abilities with update events. So your trigger would add the ability when enter, and remove when leave like so:

 

Event OnTriggerEnter(ObjectReference akActionRef)
    if akActionRef == dragon
        Dragon.AddSpell(Heal) ;add heal ability to dragon
    EndIf
    If akactionref == game.getplayer()
        Game.GetPlayer().AddSpell(Poison)
    EndIf
EndEvent


Event OnTriggerLeave(ObjectReference akActionRef)
    if akActionRef == dragon
        Dragon.RemoveSpell(Heal) ;add heal ability to dragon
    EndIf
    If akactionref == game.getplayer()
        Game.GetPlayer().RemoveSpell(Poison)
    EndIf
EndEvent

Then on the player ability you would do this:

 

Scriptname TM_PoisonAbility extends ActiveMagicEffect 
;Ability For player 

Spell Property Poison Auto
ObjectReference Property PoisoStream Auto
Actor Target

Event OnEffectStart(Actor akTarget, Actor akCaster) 
    Target = akTarget ;save target for use in other events
    Poison.Cast(PoisoStream, akTarget)
    RegisterForSingleUpdate(5)
EndEvent

Event OnUpdate() 
    Poison.Cast(PoisoStream, Target)
    RegisterForSingleUpdate(5)
EndEvent

And for the dragon ability use the heal spell instead.

Link to comment
Share on other sites

Any object can have multiple scripts. You could have one that looks specifically for the player and does stuff and one that looks for the dragon and does other stuff. Or you can store the entering actor(s) in local variables and use those in the update.

 

For the latter, using your code as a base:

 

Not tested for compilation or function

Actor Property Dragon Auto ;this is assumed else how does the script know whom the Dragon refers to
Actor PlayerRef ;easy way to reference player throughout script without multiple GetPlayer calls which take time
ObjectReference myTrigger1 ;if filled will reference the dragon else null
ObjectReference myTrigger2 ;if filled will reference the player else null

Event OnTriggerEnter(ObjectReference akActionRef)
  If akactionref == dragon
    myTrigger1 = akActionRef
    Heal.Cast(PoisonStream, Dragon)
  ElseIf akactionref == game.getplayer()
    myTrigger2 = akActionRef
    PlayerRef = akActionRef as Actor
    poison.cast(poisonstream, PlayerRef)
  EndIf
  RegisterForSingleUpdate(5)
EndEvent

Event OnUpdate()
  if myTrigger1
    Heal.Cast(PoisonStream, Dragon)
  EndIf
  If myTrigger2
    poison.cast(poisonstream, PlayerRef)
  EndIf
  RegisterForSingleUpdate(5)
EndEvent 

The trigger enter block can use the ElseIf between the two as that event will run once for each of them when they enter. But the update event uses separate IF blocks because they both need to run.

 

 

Also it should be noted that even if using two scripts, the latest registration wins. Meaning if the player enters at one point and the dragon enters 3 seconds into the player's timer, the player will have to wait another 5 seconds before the update will run. That would be 8 seconds total. Long story short, dylbill's solution is probably the best route as it avoids this particular issue by separating the update onto two separate objects (specifically, abilities).

Link to comment
Share on other sites

  • Recently Browsing   0 members

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