Jump to content

Need Help with Onhit Script Event.


Recommended Posts

Hi all, apologies in advance for my inexperience as I'm still learning scripts.

I'm trying to make a script that detects when Current actor is hit, and the attack is blocked, a spell is added to the current actor,
for a sort of counter attack buff. The script defines perks which it uses to scale the effect depending on the One Handed Skill.
The Scipt should read the attacking and the defending actor without player references, as I am planning to use SPID to distribute
this effect for NPC use as well.

I'm pretty sure that the script wont compile because of my lack of understanding how to define participating actors,
and I'm also not sure if this script would fire When the Player Blocks a hit, or when the player hits a blocking enemy.

Here is my WIP script.

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

Scriptname WEMAS_ShieldCounterAdd_Script extends activemagiceffect

SPELL Property ShieldCounterBuff Auto

SPELL Property ShieldCounterBuff2 Auto

SPELL Property ShieldCounterBuff3 Auto

SPELL Property ShieldCounterBuff4 Auto

SPELL Property ShieldCounterBuff5 Auto

Perk Property OHNovice Auto

Perk Property OHApprentice Auto

Perk Property OHAdept Auto

Perk Property OHExpert Auto

Perk Property OHMaster Auto


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

abHitBlocked

if selfref.hasPerk(OHNovice)
ShieldCounterBuff.cast(self, self)

elseif selfref.hasperk(OHApprentice)
ShieldCounterBuff2.cast(self, self)

elseif selfref.hasperk(OHAdept)
ShieldCounterBuff3.cast(self, self)

elseif selfref.hasperk(OHExpert)
ShieldCounterBuff4.cast(self, self)

elseif selfref.hasperk(OHMaster)
ShieldCounterBuff5.cast(self, self)
endif

endevent

---------------------------------------------------------------------------------------------------------------------------------------------------------------
Again, apologies for very crude code, still wrapping my brain around it.
Any help or insights would be appreciated!

Link to comment
Share on other sites

Compiler will complain about abhitblocked just sitting there. It isn't being compared to a value nor is it being given a value. You probably want to check if it is true or not before proceeding. You'll need:

If abhitblocked

or

If abhitblocked == true

Both yield the same, the latter is better for understanding especially when coming back later to make changes.

 

Compiler will complain about selfref. It hasn't been defined anywhere.

Your use of Self is incorrect. You want these spells to be cast on the target actor by the target actor rather than cast by the magic effect on the magic effect.

 

For the actor who has the magic effect applied to them, use GetTargetActor

You could do:

Actor myActor = Self.GetTargetActor()

Then use myActor wherever you have SelfRef and Self.

 

 

At least that will give you a step in the right direction. You'll still need to do testing to confirm it compiles and works.

Link to comment
Share on other sites

Thank you Ishara! That was a lot of help. Scripts are now compiling and seem to be registering in game.
Ended up doing some of my conditional effects through the spell itself. Finished script ended up looking like this.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Scriptname WEMAS_ShieldCOunterAdd_Script extends activemagiceffect

SPELL Property ShieldCounterBuff Auto

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

Actor myActor = Self.GetTargetActor()

if abHitBlocked == True
Debug.Notification("Attack Detected!!!")
ShieldCounterBuff.cast(myActor, myActor)
Debug.Notification("Counter Attack Primed!!!")
endif

endevent
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Seems good now. Just have to work out everything else on the perk side of things.

Really appreciate the assistance!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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