I made this script to help me detect when the player hit an object with a specific item. I will be using it for my custom resource gathering for a project of mine. Its not perfect nor pretty, but it works, so I thought I would share it.
Scriptname MyMiningSCRIPT extends ObjectReference
;==========
;Properties
;==========
WEAPON Property MyPickaxeProp Auto
;Needs to be set in the Properties window.
;==========
;Functions
;==========
Function MessageBox(string asMessageBoxText) native global
;Used for the debug message boxes.
Bool Function IsEquipped(Form akItem) native
;A yes or no variable to detect if a specific item is equipped.
Int Function RandomInt(int aiMin = 0, int aiMax = 100) native global
;The random number minimum and maximum.
;==========
;Events
;==========
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)
;Not sure if all this is necessary, so i kept it just in case.
Int Random = Utility.RandomInt() ;Assigning the random number to the variable "Random".
If (Game.GetPlayer().IsEquipped(MyPickaxeProp)) ;Checking the equipped status of the given item.
If Random >= 50
Debug.MessageBox("The value is 50 or higher.")
Elseif Random < 50
Debug.MessageBox("The value is 49 or lower.")
EndIf
EndIf
EndEvent