The ObjectReference or Actor within an event.

Post » Thu Jun 21, 2012 7:14 pm

Event OnHit - how do I refer to the ObjectReference being hit within this event? It's not a parameter passed through, but there must be a way.
User avatar
Assumptah George
 
Posts: 3373
Joined: Wed Sep 13, 2006 9:43 am

Post » Thu Jun 21, 2012 5:18 pm

OnHit is an event triggered by the ObjectReference when it gets hit. E.g., if the player hits an NPC, it isn't the player's OnHit event that is called, but the other actor's. The player would be passed as the aggressor parameter of the event. So to refer to the ObjectReference being hit, you likely don't need anything because you'll already be in a script attached to it, or in some cases you may need to use "Self".
User avatar
StunnaLiike FiiFii
 
Posts: 3373
Joined: Tue Oct 31, 2006 2:30 am

Post » Thu Jun 21, 2012 9:49 pm

Self doesn't work because it's in an activemagiceffect, and I need an OR or Actor.

Scriptname astral_innerserenity extends activemagiceffectimport ObjectReferenceActor Property PlayerRef autoSpell Property akSpell autoSpell Property bkSpell autoSpell Property ckSpell autoIdle Property stopanim autoEvent OnHit(ObjectReference orAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)actor akAggressor = orAggressor as ActorBool boHitByMagic = FALSE  ; True if likely hit by Magic attack.Bool boHitByMelee = FALSE  ; True if likely hit by Melee attack.Bool boHitByRanged = FALSE ; True if likely his by Ranged attack.PlayerRef = Game.GetPlayer()IF akAggressor != PlayerRef && PlayerRef.IsInCombat() && akAggressor.IsHostileToActor(PlayerRef); The above is really to rule out run of the mill physical traps.IF ((akAggressor .GetEquippedItemType(0) == 8) || (akAggressor .GetEquippedItemType(1) == 8) \  || (akAggressor .GetEquippedItemType(0) == 9) || (akAggressor .GetEquippedItemType(1) == 9))  && akProjectile != None  boHitByMagic = TRUE			 debug.notification("akAggressor magicked me!")ELSEIF (akAggressor .GetEquippedItemType(0) != 7) && akProjectile == None  boHitByMelee = TRUE			 debug.SendAnimationEvent(PlayerRef, "AttackStart")			 utility.wait(1.5)			 PlayerRef.playidle(stopanim)			 debug.notification(PlayerRef+" is attacking!")ELSEIF (akAggressor .GetEquippedItemType(0) == 7)  boHitByRanged = TRUE			 ckSpell.cast(PlayerRef, akAggressor)			 debug.notification("akAggressor shot me!")ENDIFENDIFEndEvent

When I replace Game.GetPlayer() with Self, it does not compile properly. I can use Game.GetPlayer() as a workaround, sure, but I'm trying to maximize compatibility in case anyone wants to give this spell to an NPC instead.
User avatar
Samantha Wood
 
Posts: 3286
Joined: Sun Oct 15, 2006 5:03 am

Post » Thu Jun 21, 2012 10:01 pm

GetTargetActor()
User avatar
Alina loves Alexandra
 
Posts: 3456
Joined: Mon Jan 01, 2007 7:55 pm

Post » Thu Jun 21, 2012 7:40 pm

Worked beautifully, thank you.

If anyone else is sharing my question, you can just use 'GetTargetActor' in an activemagiceffect script without a variable, like so:


PlayerRef = GetTargetActor()
User avatar
Breautiful
 
Posts: 3539
Joined: Tue Jan 16, 2007 6:51 am

Post » Thu Jun 21, 2012 11:33 am

Just to help clarify, non-global functions like this one are always called on an object, but if you don't specify the object explicitly in the function call it will use the Self object.

I always prefer omitting the calling object when calling a function on the Self object. It's only necessary to use Self when passing it somewhere else, like as the parameter of a function.

Cipscis
User avatar
Kirsty Collins
 
Posts: 3441
Joined: Tue Sep 19, 2006 11:54 pm


Return to V - Skyrim