Jump to content

[LE] OnHit function trouble


jim555511

Recommended Posts

Hi there, thanks for the help.

So i'm trying to create a script that will read the actors health each time they are hit and based off their health percent will cast mage light on them. I've almost got everything working but the only problem is the onhit function. Heres my script

Scriptname SecondaryLeonardoScript extends Activemagiceffect
Spell Property Magelight auto
Actor myself
event oneffectstart(actor aktarget,actor akcaster)
myself = aktarget
endevent
Event onhit(ObjectReference aktarget, Form aksource,Projectile akprojectile,Bool abPowerAttack,Bool abSneakAttack,Bool abHitBloacked)
Float Health = myself.GetActorValue("Health")
Float BaseHealth = myself.GetBaseActorValue("Health")
Float HealthPercent = (Health/BaseHealth) * 100
if HealthPercent < 0.5
Magelight.Cast(myself,myself)
endif
endevent
It gives me a compiling issue and tells me that the onhit function doesn't match the parent script and i am out of ideas, please help :)
Link to comment
Share on other sites

First problem I see is you are missing a parameter. You're missing a bool for abBashAttack before blocked. Easiest thing is to copy the declaration line from the source file or copy from the wiki page https://www.creationkit.com/index.php?title=OnHit_-_ObjectReference. That way you don't miss things like that. Though the variable names will differ slightly from what you have written. Here's the lines from ObjectReference.psc for simple copying.

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

Rather than getting 2 actor values and doing the math yourself you could just use

Float HealthPercent = myself.GetActorValuePercentage("health")

That will return a float between 0 and 1 for the percentage. The event would then look like this

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
    Float HealthPercent = myself.GetActorValuePercentage("health")
     
    if HealthPercent < 0.5
        Magelight.Cast(myself,myself)
    endif
EndEvent

Something to keep in mind though, is that if the health ever went back up above 50% and then got hit again it would retrigger without any check if the spell is already active or any cooldown between casts. Maybe this is desired.

Link to comment
Share on other sites

First problem I see is you are missing a parameter. You're missing a bool for abBashAttack before blocked. Easiest thing is to copy the declaration line from the source file or copy from the wiki page https://www.creationkit.com/index.php?title=OnHit_-_ObjectReference. That way you don't miss things like that. Though the variable names will differ slightly from what you have written. Here's the lines from ObjectReference.psc for simple copying.

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

Rather than getting 2 actor values and doing the math yourself you could just use

Float HealthPercent = myself.GetActorValuePercentage("health")

That will return a float between 0 and 1 for the percentage. The event would then look like this

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
    Float HealthPercent = myself.GetActorValuePercentage("health")
     
    if HealthPercent < 0.5
        Magelight.Cast(myself,myself)
    endif
EndEvent

Something to keep in mind though, is that if the health ever went back up above 50% and then got hit again it would retrigger without any check if the spell is already active or any cooldown between casts. Maybe this is desired.

Thank you so much, your help is greatly appreciated, makes me feel stupid that i was only missing one thing haha

Edited by jim555511
Link to comment
Share on other sites

  • Recently Browsing   0 members

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