Jump to content

Seeking help with On hit script


jcbq

Recommended Posts

so i'm seeking help with trying to write a script for Armor so that it can evolve via a global variable so that upon a weapon strike the armor would count upward. the issue im having is that i cant even get it to fire. A few people have been trying to help me reverse engineer the weapon system which works via a mag effect and once that mag effect fires add one to the global until it hits the threshold.

 

but that works when it strikes something what im trying to do is reverse it so that when it gets struck, it works. the same way were at a road block and are seeking any form of help

 

TLDR; trying to make a real learn by doing evolving system, got weapons and jewelry working Armor'snot working and need help

Link to comment
Share on other sites

Weapon ItemMysteryCurrent ; Current mystery item

Weapon ItemMysteryNext ; Next mystery item to discover


GlobalVariable Property gItemXPCurrent Auto ; Current Level of XP with current Myster Item

Int Property XPChanceGain Auto ; % chance to gain XP

Int Property XPRequiredGain Auto ; XP required to next Mystery Item

Spell Property SpellCastXPEnemy Auto ; spell to cast on enemy with successful gain of XP

Spell Property SpellCastXPSelf Auto ; spell to cast on self with successful gain of XP

Message Property MsgNextItem Auto ; Message to display when item levels up


Int XPCurrent ; get current level of experience with this item



EVENT OnEffectStart(Actor akTarget, Actor akCaster)

XPCurrent = gItemXPCurrent.GetValue() as Int

;debug.notification("Current XP = " + XPMainCurrent)


If(Utility.RandomInt(0, 100) <= XPChanceGain)

XPCurrent += 1

gItemXPCurrent.SetValue(XPCurrent)

;debug.notification("XP Gained! XP Level = " + XPCurrent )


; --> need to cast spell on enemy

If(SpellCastXPEnemy!= None)

SpellCastXPEnemy.Cast(akCaster, akTarget)

EndIf


; --> need to cast spell on self

If(SpellCastXPSelf!= None)

SpellCastXPSelf.Cast(akCaster, akCaster)

EndIf


; ==== Check for Level-Up====

; --> if xp > needtolevel, then remove item; give new item; equip new item

If(XPCurrent >= XPRequiredGain)

Game.GetPlayer().RemoveItem(ItemMysteryCurrent, 1, true)

Game.GetPlayer().AddItem(ItemMysteryNext, 1, true)

Game.GetPlayer().EquipItem(ItemMysteryNext, false, true)

;debug.notification("Woot! You have discovered a weapon power.")

If(MsgNextItem != None)

MsgNextItem.Show()

EndIf

Else

EndIf


Else

;debug.notification("XP not gained. XP Level = " + XPCurrent )

EndIf


ENDEVENT


Event OnEffectFinish(Actor akTarget, Actor akCaster)

;debug.notification("effect finished")

ENDEVENT



trying to flip this so that it can work if yougethit instead of youhittinga valid target

Link to comment
Share on other sites

So, this script is in an effect part of the enchantment of a weapon and you want a similar thing on an armor piece that would increment a global when you get hit, right?

 

There shouldn't be any issues getting onhit to work, activemagiceffect scripts receive events from the actor they are attached to, which in the case of armor is the wearer, and onhit is one of those events. Something like this:

Scriptname lalal extends activemagiceffect

GlobalVariable Property gItemXPCurrent Auto
Int Property XPChanceGain Auto
Int Property XPRequiredGain Auto

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
 debug.notification("OnHit fired")
 If(Utility.RandomInt(0, 100) <= XPChanceGain)
   gItemXPCurrent.SetValue((gItemXPCurrent.GetValue() as Int) + 1)
   If (gItemXPCurrent.GetValue() as Int) >= XPRequiredGain
     ;swap armor
   Endif
  Endif
EndEvent

You may want to include some conditions on the onhit events so it doesn't increment the global more that it should, check the examples on the wiki for mor information on the matter: https://www.creationkit.com/index.php?title=OnHit_-_ObjectReference

Edited by FrankFamily
Link to comment
Share on other sites

This seems viable. I'd still suggest using states while the script processes. As OnHit can fire 3 times for a single hit in some cases.

 

I think the original idea was to do it without using an enchant for it. But I am starting to see that may not work.

Edited by Pickysaurus
Link to comment
Share on other sites

Good point, just in case jcbq doesn't know, sending it to a "processing" state would be just this:

 

 

Scriptname lalal extends activemagiceffect

GlobalVariable Property gItemXPCurrent Auto
Int Property XPChanceGain Auto
Int Property XPRequiredGain Auto

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
gotostate("Busy")
debug.notification("OnHit fired")
If(Utility.RandomInt(0, 100) <= XPChanceGain)
   gItemXPCurrent.SetValue((gItemXPCurrent.GetValue() as Int) + 1)
   If (gItemXPCurrent.GetValue() as Int) >= XPRequiredGain
     ;swap armor
   Endif
  Endif
gotostate("")
EndEvent

State Busy
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
;
Endevent
EndState

 

 

 

Onhit could be in an alias to avoid using the enchantment. Which would be player only or the wearer could be forced into the alias via ForceRefTo from OnEquip/OnUnequip, I guess.

Edited by FrankFamily
Link to comment
Share on other sites

  • Recently Browsing   0 members

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