Obtain OnHit's reference?

Post » Mon Oct 18, 2010 10:17 am

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?
User avatar
C.L.U.T.C.H
 
Posts: 3385
Joined: Tue Aug 14, 2007 6:23 pm

Post » Mon Oct 18, 2010 9:58 am

I think you can use the GetCombatTarget

Check here:

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

for more info
User avatar
Roy Harris
 
Posts: 3463
Joined: Tue Sep 11, 2007 8:58 pm

Post » Mon Oct 18, 2010 5:41 am

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
User avatar
no_excuse
 
Posts: 3380
Joined: Sun Jul 16, 2006 3:56 am

Post » Mon Oct 18, 2010 9:29 am

http://cs.elderscrolls.com/constwiki/index.php/GetActionRef, maybe?
User avatar
Damned_Queen
 
Posts: 3425
Joined: Fri Apr 20, 2007 5:18 pm

Post » Mon Oct 18, 2010 8:19 am

If you use OBSE, you can use the OnHit event handler to get the references of both the attacker and the target.
User avatar
James Shaw
 
Posts: 3399
Joined: Sun Jul 08, 2007 11:23 pm

Post » Mon Oct 18, 2010 2:08 pm

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?
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm

Post » Mon Oct 18, 2010 1:57 pm

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

User avatar
Chloe Lou
 
Posts: 3476
Joined: Sat Nov 04, 2006 2:08 am

Post » Mon Oct 18, 2010 7:43 pm

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!
User avatar
Bitter End
 
Posts: 3418
Joined: Fri Sep 08, 2006 11:40 am

Post » Mon Oct 18, 2010 6:24 pm

That's... really cool. Now I need to find an excuse to play with this. :D
User avatar
Jack Walker
 
Posts: 3457
Joined: Wed Jun 06, 2007 6:25 pm

Post » Mon Oct 18, 2010 9:59 pm

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 :)
User avatar
Yvonne Gruening
 
Posts: 3503
Joined: Mon Apr 23, 2007 7:31 pm

Post » Mon Oct 18, 2010 5:30 pm

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.
User avatar
kiss my weasel
 
Posts: 3221
Joined: Tue Feb 20, 2007 9:08 am

Post » Mon Oct 18, 2010 4:48 pm

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
User avatar
Katie Pollard
 
Posts: 3460
Joined: Thu Nov 09, 2006 11:23 pm


Return to IV - Oblivion