Page 1 of 1

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 10:17 am
by C.L.U.T.C.H
I'm talking about this http://cs.elderscrolls.com/constwiki/index.php/OnHit

As you can see, OnHit has one parameter: ActorID, which is "Who hits the scripted object". The page claims OnHit will work without ActorID, and the script will trigger whenever it is hit by anything.

What I want is a way to get that ActorID there. I want it so whenever the scripted object is hit, the script returns a reference to the Actor that hits it

Simply put, I want to know who hits the object, by using OnHit. Is it possible? If so, how?

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 9:58 am
by Roy Harris
I think you can use the GetCombatTarget

Check here:

http://cs.elderscrolls.com/constwiki/index.php/GetCombatTarget

for more info

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 5:41 am
by no_excuse
I think you can use the GetCombatTarget

Check here:

http://cs.elderscrolls.com/constwiki/index.php/GetCombatTarget

for more info

GetCombattarget returns the current target, my script requires the reference to be returned at the time a hit occurs, not all the time.

The reason is that I want to put my character behind the attacking character at the time the enemy hits. it's not possible to use GetCombatTarget for that

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 9:29 am
by Damned_Queen
http://cs.elderscrolls.com/constwiki/index.php/GetActionRef, maybe?

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 8:19 am
by James Shaw
If you use OBSE, you can use the OnHit event handler to get the references of both the attacker and the target.

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 2:08 pm
by Princess Johnson
If you use OBSE, you can use the OnHit event handler to get the references of both the attacker and the target.

Ah, Scruggs did mention that, but I don't know how to use it. Perhaps you can point me in the right direction? Event Handler is a new function from 0019, yes?

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 1:57 pm
by Chloe Lou
Event Handler documentation: http://obse.silverlock.org/obse_command_doc.html#Events

Well you need to make an object script that you want to run whenever somebody gets hit. Something like:
scn MyFunctionref attackerref targetbegin Function { target, attacker };do stuffend

Next you need to set the event handler. In my mod I used a quest with a script attached like:
scn MySetEventHandlerQuestScriptbegin gamemodeif getgameloaded   seteventhandler "onhit" MyFunctionendifend


Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 7:43 pm
by Bitter End
Hmm... that's neat. This means target and attacker could be anything and abstract, seems like a perfect function for my intended script. Many thanks!

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 6:24 pm
by Jack Walker
That's... really cool. Now I need to find an excuse to play with this. :D

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 9:59 pm
by Yvonne Gruening
You can attach script effects to stuff too. Then you can do a ScriptEffectStart, ScriptEffectUpdate and ScriptEffectfFinish in a script to do things while the script effect is active. Just a little teaser on all the fun things you can do :)

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 5:30 pm
by kiss my weasel
I'm actually looking at how to do something like this in a little project of mine right now. Is it possible, using the event handler, to make it trigger whenever a certain actor hits anybody, so the attacker is set and the target is only returned when the event happens? I basically would like to have the player apply a variable effect whenever they hit an actor, regardless of their current weapon.

Obtain OnHit's reference?

PostPosted: Mon Oct 18, 2010 4:48 pm
by Katie Pollard
Well I haven't tried it personally, but the example in the documentation says that you can use it to only run when the player is the attacker:
SetEventHandler "OnHit" FnOnHitByPlayer object::PlayerRef