Jump to content

OnHit question for obse


Grindspice

Recommended Posts

[Problem Solved. Skip to #3 for the next relevant question. Thanks Philippe]

 

I'm trying to use the onhit function in a script so that it will TriggerPlayerSkillUse magicskill 1 whenever the player whacks something with their weapon. I'm new to modding and scripting and I don't understand how I'm supposed to use the onhit thing. CSelderscrolls has this written about it:

 

To handle events in which the player, and only the player, hits anyone else, use:

SetEventHandler "onhit", yourscript, "object"::playerRef

 

From what I can tell I need to stick that^ whole thing in the beginning of my script and then call up the "onhit" when I need it later on in the script. I need help with how to use the whole "object"::playerRef part, how to call up the onhit thing, and what the onhit script should look like.

 

Heres a chopped up version of what I got going on in the script so far.

---------------

scn aaSpellOnStrike

 

Float ...

Short ...

Ref spell...

;SetEventHandler "onhit" aaSpellOnStrikeXpGain [Don't know the object part right here]

 

Begin Gamemode

if ....

;whole bunch of stuff which works to make spells activate on a weapon strike under the right conditions.

Elseif ([keypressed condition])

;i'd like to invoke my onhit function here

;stuff to close out the script effect...

endif

end

------------------

scn aaSpellOnStrikeXpGain

 

ref spell

 

Begin ScriptEffectStart

 

;I think something related to the "onhit" goes here

 

If (GetSpellSchool Spell == 2)

TriggerPlayerSkillUse Destruction 1

Elseif (GetSpellSchool Spell == 4)

TriggerPlayerSkillUse Mysticism 1

endif

 

end

----------------

 

If somebody could give me an example of what to do with the "onhit" stuff or fill in my blanks I'd really appreciate it. I have a feeling I'm going to need this knowledge later on in my modding adventures.

 

btw I'm modifying paladicprince's spell sword mod. He got all the hard stuff done but I want to clean it up and use it as part of the overhaul I'm starting.

Edited by Grindspice
Link to comment
Share on other sites

The OnHit is an OBSE event handler. It works by:

  1. You creating an OBSE "user-created function" script to handle the OnHit event (this is a unique script just for this function)
  2. You registering that script as an event handler in another script (once every time a save is loaded should be more than enough)
  3. The game invoking the event handler script and supplying the information to the script as parameters when the event takes place
  4. You unregistering your script for the event when no longer relevant

An event handler is used to "catch" events in the game without using a separate script for each object possibly involved in an event. So, for example, if you wanted to "catch" all hits in the game, regarless of weapon, attacker or victim, you could use an event handler and OBSE would invoke the script when appropriate. Or when you would want to catch all hits by player. Or all hits on a specific NPC. Or when player hits Martin Septim. Or when someone finishes an AI package, or dodges an attack. All without touching the parties involved in the event, to maintain compatibility.

 

This is an example OnHit event handler script (script classified as Object Script):

ScriptName ExampleOnHitHandler

ref rTarget
ref rAttacker

Begin Function { rTarget rAttacker }

    MessageEX "%q%n%q was hit by %q%n%q!", rTarget rAttacker

End

And you would register it in, for example, a quest script, once when a save is loaded:

ScriptName ExampleQuestScript

Begin GameMode

    If ( GetGameLoaded )
        SetEventHandler "OnHit" ExampleOnHitHandler "object"::PlayerRef
    EndIf

End

Something like that. Has not been tested, though, but the idea should be visible. Hopefully that helps you get forward a bit. :smile:

 

Edit: Fixed some typos.

Edit 2: Added quotation marks for the "object", thanks to Drake for clarifying that (see his post below for more).

Edited by PhilippePetain
Link to comment
Share on other sites

Thanks for the help Philippe. I wasn't able to get the onhit script to work, and I'm still not sure about whether or not I did the "object"::playerRef thing correctly. I think I messed up by having the called script type set to object first, then I set it to quest and didn't have a corresponding quest, then I realized that there was already a magic script built in to paladicprince's script. I added what I wanted into that and got the results I needed without using the onhit function.

 

Your reply helped me understand the onhit thing better and I was able to stick it into the script without the cs popping up complaints everytime I tried to save it. The problem was I'm still a noob at this and I don't fully understand setting up scripts. I guess I shouldn't have skipped the quest scripting tutorial ><.

 

I'll probably have more questions about the onhit thing later though, so don't be surprised if this thread pops up again. I'm going to mod the sideways power attack to be a "whirlwind" attack instead of a "disarm" one and I'll probably need to use an onhit function.

 

If anybody's heard of a good way to get that power attack done slap a link on here for me to study.

Edited by Grindspice
Link to comment
Share on other sites

For what it's worth, or for future use of the function, the syntax documentation explicitly says the "key::value" pairs for the filters must follow very specific syntax in setting them up.

The "key" part is either the string "object" or "ref", while the quotes are "not" optional, and the "value" part is a specific reference or object, according to what the "key" part defines.

So, of course, the notation

SetEventHandler "OnHit" ExampleOnHitHandler object::PlayerRef

can't compile, as it contains a simple syntax error, the string is not a string.

SetEventHandler "OnHit" ExampleOnHitHandler "object"::PlayerRef

would be the correct notation.

 

It instructs the handler to only react on hits dealt "on" the PlayerRef object. Whereas using - "ref"::PlayerRef - instead would mean to only react to hits dealt "by" the PlayerRef. I think they set it up that way so you can pass in an arbitrary number of additional parameters, always specifying whether it's meant as another target or inflictor by prefixing them with either "object" or "ref" accordingly. But that's just blind guessing on my part now.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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