Jump to content

[LE] Does OnHit work in a Reference Alias script?


qwertypol012

Recommended Posts

As the title says. I want to know whether OnHit event work inside a Ref Alias script.

 

I have a Ref Alias script to monitor an NPC's conditions, and one of the events i need is OnHit.

 

I also have additional questions btw:

Does OnHit event work in an Armor script? I already tried to make it, by extending the script to ObjectReference (attached to the armor), but it didn't seem to work. That's why i changed it to Ref Alias script and also an Active Magic Effect script which seemingky capable to run OnHit event.

 

Any explanation is appreciated. :)

Link to comment
Share on other sites

Reference alias points to an actor. A script on the ref alias will receive the following events:

Any ReferenceAlias events

Any Actor events

Any ObjectReference events

Any Form events

 

Reference alias points to a piece of armor. A script on the ref alias will receive the following events:

Any ReferenceAlias events

Any ObjectReference events

Any Form events

Note that while stored in a container / inventory some events / functions may not be triggered.

Link to comment
Share on other sites

  On 1/16/2021 at 2:45 AM, IsharaMeradin said:

Reference alias points to an actor. A script on the ref alias will receive the following events:

 

Any ReferenceAlias events

Any Actor events

Any ObjectReference events

Any Form events

Â

Reference alias points to a piece of armor. A script on the ref alias will receive the following events:

Any ReferenceAlias events

Any ObjectReference events

Any Form events

Note that while stored in a container / inventory some events / functions may not be triggered.

Thanks for the explanation. So it seems like that's the case with my armor script (as ObjectReference). Probably because it's started with OnContainerChanged event, which possibly makes the OnHit didn't work.

 

As for the Ref Alias, i once tried it in a Player Alias script, and the OnHit didn't seem to be triggered. I put some debug.Notification inside the event, but none of them showed in the game whenever i got hit. And of course the alias has been filled with the player reference (i can assure it).

Link to comment
Share on other sites

IsharaMeradin already said most, i'll just add 2 things.

- Once an object is inside a container or inventory it can no longer run a "Self" function, but it can run the function if it is targeting something else.

Example:

This will never fire



ObjecReference Property MyREF01 Auto

Event OnContainerChanged()
If ( akNewContainer == PlayerREF )
MyREF01.Activate(self)
EndIf
Endevent



But this will



ObjecReference Property MyREF01 Auto
ObjecReference Property MyREF02 Auto

Event OnContainerChanged()
If ( akNewContainer == PlayerREF )
MyREF01.Activate(MyREF02)
EndIf
Endevent



When you add an "OnHit" event to the armor that event will also fire when you throw to the ground and hit the armor.

The best way to have an "OnHit" event attach directly to the armor is to:

- Create an Ability Spell with archetype 'Script'.

- Add your script to your magic effect with archetype 'Script' that it will run the "OnHit" event.

- Then add/remove the ability on "OnEquipped()" > "OnUnequipped()"


I hope it helps and have a happy modding.

Edited by maxarturo
Link to comment
Share on other sites

 

  Reveal hidden contents

 

So, that's why it didn't work in my case. I still don't understand properly about making the armor "targeting something else". Not really sure about its implementation.

 

But thanks for the insight. I think i understand OnHit more now. In writing scripts, i mainly followed instructions and infos from the CK site's papyrus functions, and unfortunately they don't have much info (just like what you've explained above)

Link to comment
Share on other sites

  On 1/17/2021 at 11:27 PM, maxarturo said:

Why don't you explain with simple words and in order what are you trying to achieve. There are different ways to do certain things and in some cases only one way.

Alright, I'll try to explain what I'm trying to achieve. It'll be a bit long though.

 

I'm in the process of adding a feature to my mod. To put it short, my mod is an armor mod which has some features when being worn; and one of the features is:

"When being worn AND the player is in combat, check if the player is facing a strong enemy (by simply comparing his/her level with player's level, which one is higher) OR if the player is in a critical condition (ie. Health below a certain threshold, for example). If one of these conditions is fulfilled, then run X function"

 

X function is: Transforming the armor into a more enhanced version of the armor.

 

That's it. Do you have any suggestions on how to do it properly without using too many resource intensive papyrus functions?

I want my scripts to only use papyrus functions as lightweight as possible.

Edited by qwertypol012
Link to comment
Share on other sites

"Do you have any suggestions on how to do it properly without using too many resource intensive papyrus functions?"

Unfortunately no, what you want to do needs to use a bunch of things in order to be achieved, but i'll post the most light version of it, in my opinion.

NOTE: There are other ways to do this and maybe some else can suggest another way to do it.


* I will use the "if the player is in a critical condition".


1) Create a "BoostPerk", a perk that will modify the incoming damage, you can see how the vanilla "Ghost Half Damage Perk" is made, you might need to also add to your perk a "Mod Incoming Spell Damage".

The vanilla "Ghost Half Damage Perk" modifies only one kind of incoming damage.


2) Create an "Ability Spell".


3) In its 'Magic Effect" add this script:

* It fires when the Player's health is under 20%.


  Reveal hidden contents




4) Add to your script's property the "Perk" you created.


5) Add to your Armor this script:

  Reveal hidden contents



6) Assign the "Boost Ability Spell" to your Armpr's script.


You are done !.

Edited by maxarturo
Link to comment
Share on other sites

 

  Reveal hidden contents

 

Thanks. I tried some methods too, but this one is a bit different. I'll try it out :)

 

And, how about the "player facing a strong enemy" (ie. has higher level)?

Do you know the most lightweight method for it?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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