How do you detect when the actor is attacking in a script.

Post » Tue Jun 19, 2012 1:59 am

So this will not work:


Scriptname aadpActorScript extends ActiveMagicEffect


actor ME

Event OnEffectStart(Actor akTarget, Actor akCaster)

ME = akTarget

endevent


Event OnEffectupate

if me.isattacking == 1
Debug.messagebox(me + "is attacking")
endif

endevent


I would rather use a "I am attacking" (OnAttack) EVENT but I could not find one in the Wiki.
User avatar
josh evans
 
Posts: 3471
Joined: Mon Jun 04, 2007 1:37 am

Post » Tue Jun 19, 2012 5:41 am

Shouldn't you do RegisterForUpdate() and then override OnUpdate()?
User avatar
Robyn Howlett
 
Posts: 3332
Joined: Wed Aug 23, 2006 9:01 pm

Post » Tue Jun 19, 2012 3:06 am

You could use a spell (probably best to use an ability) with a scripted effect conditionalised to be applied only when attacking via http://www.creationkit.com/IsAttacking. That should allow you to essentially detect when an actor is attacking without continuously checking.

Cipscis
User avatar
TOYA toys
 
Posts: 3455
Joined: Sat Jan 13, 2007 4:22 am

Post » Mon Jun 18, 2012 9:03 pm

WHAT! No way to detect it inside a script? WOW that will mean I will need to make and attached a HECK of a lot of abilities to the actors to do all the combat features I did in Oblivion.

wow.... that is disappointing. Well. maybe SKSE will save the day, I wish I knew how far along they were on that.


You could use a spell (probably best to use an ability) with a scripted effect conditionalised to be applied only when attacking via http://www.creationkit.com/IsAttacking. That should allow you to essentially detect when an actor is attacking without continuously checking.

Cipscis
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm

Post » Tue Jun 19, 2012 12:18 am

Yes I left out the RegisterForUpdate() thing you are correct!

But what is then override OnUpdate()?


My working script (for example):




Scriptname aadpFastRestScript extends activemagiceffect

float Amount
actor ME

Event OnEffectStart(Actor akTarget, Actor akCaster)
Me = akTarget
RegisterForUpdate(0.1)
EndEvent


Event OnUpdate()
Amount = Me.GetBaseActorValue("Stamina") as float
Amount = Amount * 0.02

Me.RestoreAV("Stamina", Ammount)

endevent


In Oblivion I would do this:

if Me == 0
set Me to this
return
endif


How can I do the same thing in this Skyrim magic script where ME is the actor the magic effect is on (I,E the target of the magic effect)?
This was VERY important to do because the ME ref would often get reset to zero for unknown reasons.



Shouldn't you do RegisterForUpdate() and then override OnUpdate()?
User avatar
Chad Holloway
 
Posts: 3388
Joined: Wed Nov 21, 2007 5:21 am

Post » Tue Jun 19, 2012 12:57 pm

In Skyrim, if a script is storing a reference in a variable, that reference will be persistent, so you shouldn't need to worry about anything like that happening.

http://www.creationkit.com/GetBaseActorValue_-_Actor already returns a float value, so you don't need to cast the result to float.

Also, although your http://www.creationkit.com/OnUpdate_-_Form event is very short, when you only have a very short time between updates it's worth considering using a chain of http://www.creationkit.com/RegisterForSingleUpdate_-_Form. This would ensure that you won't get a lot of OnUpdate events registered simultaneously, although with such a small amount of code I don't think that should be a problem here. Just something to be aware of.

How does this work for you?
ScriptName aadpFastRestScript extends ActiveMagicEffectActor MeEvent OnEffectStart(Actor akTarget, Actor akCaster)	Me = akTarget	RegisterForUpdate(0.1)EndEventEvent OnUpdate()	Me.RestoreActorValue("Stamina", Me.GetBaseActorValue("Stamina") * 0.02)EndEvent

Cipscis
User avatar
Add Meeh
 
Posts: 3326
Joined: Sat Jan 06, 2007 8:09 am


Return to V - Skyrim