Jump to content

onhit event...


littleerve

Recommended Posts

How the hell do i register for an onhit event for a target and not myself?

 

I've got an ench/magic effect on a worn item of mine running a script, but i just can't figure out how to reference a target instead of myself for onhit. I wish there were more examples or something i could look at.

Link to comment
Share on other sites

It depends on the context of HOW you are registering for the hit. I use it in one of my mods as a post activity condition. Once I have the condition, I can then register for the hit.

 

If xxxxx == xx

RegisterForHitEvent(PlayerREF)

endif

 

Now, you need to set the event up.

 

Event OnHit(ObjectReference akTarget, ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked, string apMaterial)

 

If akTarget == PlayerREF && ...

 

in there you need to determine if you use a source or a projectile, etc. For me, it is an explosion, so my condition is:

 

If akTarget == PlayerREF && (akSource as explosion)

 

Now I know it is only the ONE kind of explosion I am registering for so I dont need to filter it any further. But if yours is a weapon, use akSource as Weapon.

 

The wiki outlines the whole thing rather well... as to the question, you *should* be able to simply put in the object reference in the register RegisterForHitEvent(ActorName). It is akTarget that needs to match the registerfor hit in the OnHit event.

 

https://www.creationkit.com/fallout4/index.php?title=OnHit_-_ScriptObject

Edited by joerqc
Link to comment
Share on other sites

Yeah but that's all for if the player gets hit, how do i setup the magic effect / script to get the onhit event to proc when I hit someone else? Like I want playerref as the aggressor etc but with a magic effect set to fire/forget on contact? I just can't get the right combination.

 

I have a feeling I'm going to have to do something like the furious effect does, two different magic effects with two different scripts or something.

Edited by littleerve
Link to comment
Share on other sites

Ok I got it sorted. Here's the 411.

 

I made a legendary mod to change explosive weapons, however im using weapons that have grenade launchers. Which is cool, but, the enchantment for the explosive bullet is an override projectile on the omod, so, the grenade projectile was wrong.

 

So, I removed the override projectile and figured out how to spawn an explosion at the target when it is hit.

I'm not the best coder, so it's hard to figure out when you only know/understand 1/2 of what you need to.

 

I manage to find an example of what I wanted and it basically goes like this:

 

Omod -> ench -> Constant/Self Magic effect -> Perk -> Apply Spell on Hit -> spell -> Fire/Forget & Constant Magic Effect -> Script

 

and the script is super simple now:

extendactivemagiceffect yadayada

 

Actor Property PlayerRef Auto
Explosion Property ExpShell Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
akTarget.Placeatme(ExpShell)
EndEvent

 

and PlayerRef is obvious and ExpShell is just whatever explosion you want.

 

Now I can add any type of explosion to any type of weapon mwhahahahaha (tho I might want a cooldown timer for anything too big)

 

Maybe I could make lasers spawn fire hazards, i already have a mod that drops a rad hazard (shotgun plasma with an arc projectile that drops a rad hazard when it lands, it's awesome fun)

Edited by littleerve
Link to comment
Share on other sites

  • 1 year later...

D

 

Ok I got it sorted. Here's the 411.

 

I made a legendary mod to change explosive weapons, however im using weapons that have grenade launchers. Which is cool, but, the enchantment for the explosive bullet is an override projectile on the omod, so, the grenade projectile was wrong.

 

So, I removed the override projectile and figured out how to spawn an explosion at the target when it is hit.

I'm not the best coder, so it's hard to figure out when you only know/understand 1/2 of what you need to.

 

I manage to find an example of what I wanted and it basically goes like this:

 

Omod -> ench -> Constant/Self Magic effect -> Perk -> Apply Spell on Hit -> spell -> Fire/Forget & Constant Magic Effect -> Script

 

and the script is super simple now:

extendactivemagiceffect yadayada

 

Actor Property PlayerRef Auto
Explosion Property ExpShell Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
akTarget.Placeatme(ExpShell)
EndEvent

 

and PlayerRef is obvious and ExpShell is just whatever explosion you want.

 

Now I can add any type of explosion to any type of weapon mwhahahahaha (tho I might want a cooldown timer for anything too big)

 

Maybe I could make lasers spawn fire hazards, i already have a mod that drops a rad hazard (shotgun plasma with an arc projectile that drops a rad hazard when it lands, it's awesome fun)

This script worked?

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

I've been looking for something like this. Thank you for the info littleerve.

Omod -> ench -> Constant/Self Magic effect -> Perk -> Apply Spell on Hit -> spell -> Fire/Forget & Constant Magic Effect -> Script

 

For that last bit, to avoid any confusion:

... -> Spell -> Fire and Forget/Contact Magic Effect -> Script

 

For the script I just did the following:

Explosion Property ExpShell Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
    akTarget.Placeatme(ExpShell)
EndEvent
Link to comment
Share on other sites

  • 2 weeks later...

I've been doing some experiments. I looked at examples from the PA effects script. I got the script to this form:

Explosion Property ExpShell Auto
IdleMarker Property ExplosionSpawnMarker Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
    ObjectReference marker = akTarget.PlaceAtMe(ExplosionSpawnMarker)
        if ( marker != None )
            float fXPos = marker.GetPositionX()
            float fYPos = marker.GetPositionY()
            float fZPos = marker.GetPositionZ() + 4.0
            marker.SetPosition(fXPos, fYPos, fZPos)
            marker.PlaceAtMe(ExpShell)
            marker.Delete()
        endIf
EndEvent

This is only useful if for some reason you want to elevate the explosion a little bit above ground. 4 is just an example, you can increase it as you like. While increasing it will make the explosion look better, if it's applied let's say on a Mr Handy - it will be placed closer to the body, not below its thruster. Strangely, at the same time it will look quite off/elevated when the target is a bloatfly.

 

=============================================================

 

Edit: Here is a bit of an improved version of the above, where you can define the value of the variable:

Explosion Property myExplosion Auto
IdleMarker Property EmptyIdleMarker Auto Const
float Property markerZOffset = 4.0 Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
    ObjectReference marker = akTarget.PlaceAtMe(EmptyIdleMarker)
        if ( marker != None )
            float fXPos = marker.GetPositionX()
            float fYPos = marker.GetPositionY()
            float fZPos = marker.GetPositionZ() + markerZOffset
            marker.SetPosition(fXPos, fYPos, fZPos)
            marker.PlaceAtMe(myExplosion)
            marker.Delete()
        endIf
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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