Jump to content

[LE] Script problem - left hand


GSGlobe

Recommended Posts

 

Scriptname AF_StaffTestAbility_Enchant_Script extends activemagiceffect

spell property AF_Staff_Right_Spell_Ability auto
spell property af_release_staffspellench auto
spell property af_release_staffsneakspellench auto
keyword property AF_Staff auto
Actor caster
; True if we have a cast staff in that hand
bool LeftHand
bool RightHand
Event OnEffectStart(Actor akTarget, Actor akCaster)
caster = akTarget
RegisterForAnimationEvent(akTarget, "MRh_SpellFire_Event")
RegisterForAnimationEvent(akTarget, "MLh_SpellFire_Event")
CheckStaffs()
EndEvent
Event OnAnimationEvent(ObjectReference akSource, string asEventName)
Weapon staff
if (asEventName == "MRh_SpellFire_Event")
; Right
staff = caster.GetEquippedWeapon()
;Debug.Notification("Casts with a " + caster.GetEquippedWeapon())
if (staff != none && staff.HasKeyword(AF_Staff) )
if caster.issneaking()
af_release_staffsneakspellench.cast(caster)
else
af_release_staffspellench.cast(caster)
EndIf
endif
Elseif (asEventName == "MLh_SpellFire_Event")
; Left
staff = caster.GetEquippedWeapon(true)
;Debug.Notification("Casts with a " + caster.GetEquippedWeapon(true))
if (staff != none && staff.HasKeyword(AF_Staff) )
if caster.issneaking()
af_release_staffsneakspellench.cast(caster)
else
af_release_staffspellench.cast(caster)
EndIf
endif
endif
EndEvent
Function CheckStaffs()
Weapon Lstaff = caster.GetEquippedWeapon(true)
LeftHand = Lstaff != none && Lstaff.HasKeyword(AF_Staff)
Weapon Rstaff = caster.GetEquippedWeapon(false)
RightHand = Rstaff != none && Rstaff.HasKeyword(AF_Staff)
;debug.Notification("L: " + LeftHand + " R: " + RightHand)
if (!LeftHand && !RightHand)
caster.removeSpell(AF_Staff_Right_Spell_Ability)
;debug.Notification("Dispel")
EndIf
EndFunction
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
Form staff = akBaseObject
Weapon Lweap = caster.GetEquippedWeapon(true)
Weapon Rweap = caster.GetEquippedWeapon(false)
if (LeftHand && (Lweap == none || !Lweap.HasKeyword(AF_Staff))) ; We unequipped a staff
;debug.Notification("Unequipped Left Staff")
elseif (RightHand && (Rweap == none || !Rweap.HasKeyword(AF_Staff)))
;debug.Notification("Unequipped Right Staff")
EndIf
CheckStaffs()
endEvent
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
if (akBaseObject.HasKeyword(AF_Staff))
CheckStaffs()
endif
endEvent
Event OnEffectFinish(Actor akTarget, Actor akCaster)
UnregisterForAnimationEvent(akTarget, "MRh_SpellFire_Event")
UnregisterForAnimationEvent(akTarget, "MLh_SpellFire_Event")
EndEvent

The above script works great on the right hand, but the left hand is only working if you have right hand equipped at the same time, otherwise the left hand is not registering the event.
I can't for the life of me figure it out, I even tried separating them but that just stops it working completely. Any ideas?
I'm thankful for any ideas, improvements or help in general.
Best regards,
Link to comment
Share on other sites

; Obtains the item quipped in the specified hand (0 - Left hand, 1 - Right hand)
    ; Return values are:
    ; -1 - Error
    ; 0 - Nothing
    ; 1 - One-handed sword
    ; 2 - One-handed dagger
    ; 3 - One-handed axe
    ; 4 - One-handed mace
    ; 5 - Two-handed sword
    ; 6 - Two-handed axe
    ; 7 - Bow
    ; 8 - Staff
    ; 9 - Magic spell
    ; 10 - Shield
    ; 11 - Torch
    ;int Function GetEquippedItemType(int aiHand) native

Not test for Function, it merely to give you some idea's

Scriptname AF_StaffTestAbility_Enchant_Script extends ReferenceAlias  
{I have destroy it has magic effecf & turn it into a Player Alias
it just happen, LOL, when I realise the ME was Pointless
since all it did was register & unregister}

spell property af_release_staffspellench auto
spell property af_release_staffsneakspellench auto
 
Int[] Hands

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
 
    If asEventName =="MRh_SpellFire_Event" || asEventName =="MLh_SpellFire_Event"
        If Hands[0] == 8 || Hands[1] == 8
            If(akSource.GetAnimationVariableBool("IsSneaking"))
                af_release_staffsneakspellench.cast(akSource, akSource) ;Who is it targeting? Let target the player.
            Else
                af_release_staffspellench.cast(akSource, akSource)  ;Who is it targeting? Let target the player. Just for Fun
            EndIf
        EndIf
    EndIf
EndEvent
 
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)

    Keyword Staff = Keyword.GetKeyword("WeapTypeStaff")
    If akBaseObject As Weapon && akBaseObject.HasKeyword(Staff)
        Actor akSelf = Self.GetReference() as Actor
        CheckStaffs(akSelf)
        If(Hands[0] != 8)
            Self.UnregisterForAnimationEvent(akSelf, "MLh_SpellFire_Event")
        ElseIf(Hands[1] != 8)
            Self.UnregisterForAnimationEvent(akSelf, "MRh_SpellFire_Event")
        EndIf
    EndIf
endEvent
 
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)

    Keyword Staff = Keyword.GetKeyword("WeapTypeStaff")
    If akBaseObject As Weapon && akBaseObject.HasKeyword(Staff)
        Actor akSelf = Self.GetReference() as Actor
        CheckStaffs(akSelf)
        If Hands[0] == 8
            Self.RegisterForAnimationEvent(akSelf, "MLh_SpellFire_Event")
        ElseIf(Hands[1] == 8)
            Self.RegisterForAnimationEvent(akSelf, "MRh_SpellFire_Event")
        EndIf
    EndIf    
endEvent

Function CheckStaffs( Actor akActor)
{It will check both hands, but gets triggered by either}

    Hands = new Int[2]
    Int nIndex = 2
    While nIndex As Bool
        nIndex -= 1
        Hands[nIndex] = akActor.GetEquippedItemType(nIndex)
        If Hands[nIndex] == 8
            Return
        EndIf
    EndWhile
EndFunction
Link to comment
Share on other sites

Thanks alot for taking your time helping out, so the above should be functional with left hand?

 

I will give IT a spin once Im home fr.o.m. Work in 11hours or so. Your script is alot different than what Im used to but hopefully Ill get IT to work :)

Link to comment
Share on other sites

change checkStaffs to this it better if you equip two Staffs at same time in the inventory menu

Function CheckStaffs( Actor akActor)
{It will check both hands, but gets triggered by either}

    Hands = new Int[2]
    Int nIndex = 2
    While nIndex As Bool
        nIndex -= 1
        Int Temp = akActor.GetEquippedItemType(nIndex)
        If Temp == 8
            Hands[nIndex] = Temp
        EndIf
    EndWhile
EndFunction

But was more, Food for thought, if you look at PSC exact at the top you will see

; Obtains the item quipped in the specified hand (0 - Left hand, 1 - Right hand)

Then it return a int value for each hand, with what weapon, each hand is equipped with, with more returns that using Keywords.

 

I am not sure what your trying to achieve with the ME, is it Targeting Self, Other, is it an Ability? So I just wrote a Code showing how you can quicky find what both hands are holding, but concentrated on the Staffs, & registering for Animation Event to give you some ideas.

 

If my loop (while) confuses you? since were not checking Lots Of things take a look this

Function CheckStaffsA( Actor akActor)
{It will check both hands, but gets triggered by either}

    Hands = new Int[2]
    Int nIndex = 2
    While nIndex As Bool
        nIndex -= 1
        Int Temp = akActor.GetEquippedItemType(nIndex)
        If Temp == 8
            Hands[nIndex] = Temp
        EndIf
    EndWhile
EndFunction


Function CheckStaffsB( Actor akActor)
{It will check both hands, but gets triggered by either}

	Int Left =  akActor.GetEquippedItemType(0)
	If Left == 8
		Hands[0] = Left
	EndIf
	Int Right = akActor.GetEquippedItemType(1)
	If Right == 8
		Hands[1] = Right
	EndIf
EndFunction

But a Loop support an index of 128, so it may have been over kill for 2. I admit that

 

Cheers

Edited by PeterMartyr
Link to comment
Share on other sites

The magic effect is an Ability, once you equip one of My staff youll get a perk thats linked to the magic effect. Its what My limited knowledge came up with.

 

So in a sense the script should check, IF staff has keyword(mykeyword) and check whether staff with said keyword is in left or right hand then register for animation event.

 

The spells (af_release) is a self spell.

 

I got the right hand to work fine, and the left hand only worked IF right hand was also equipped.

 

 

The checkstaff function got me confused, also the self.registeranimationevent(self,BLaBla) Ive never used self before.

 

Ive never taken programming classes and only been trying to learn for 2 months hehe.

 

Thanks alot for your help so far :) very interesting

Link to comment
Share on other sites

Oh... you need this for Spell Ability CK Conditions so Game Engine cast & dispel it for ya.

 

https://www.creationkit.com/index.php?title=GetEquippedItemType

 

## 8 like my code

 

Go back to your original plan with ME, Only in Spell Conditions use the above to activate & dispell it, If you are using a Staff. which turn the Scripted Effect simply into

Scriptname AF_StaffTestAbility_Enchant_Script extends activemagiceffect    

spell property af_release_staffspellench auto
spell property af_release_staffsneakspellench auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

    If akCaster == Game.GetPlayer() 
        Self.RegisterForAnimationEvent(akCaster, "MLh_SpellFire_Event")
        Self.RegisterForAnimationEvent(akCaster, "MRh_SpellFire_Event")
    EndIf
EndEvent

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
{mmmm could use Game.GetPlayer() some where  :-) source == Game.GetPlayer() }

    If asEventName =="MRh_SpellFire_Event" || asEventName =="MLh_SpellFire_Event"
        If(akSource.GetAnimationVariableBool("IsSneaking"))
            af_release_staffsneakspellench.Cast(akSource, akSource)
        Else
            af_release_staffspellench.Cast(akSource, akSource)
        EndIf
    EndIf  
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)

    If akCaster == Game.GetPlayer() ;; buggy game better safe then sorry 2
        Self.UnregisterForAnimationEvent(akCaster, "MLh_SpellFire_Event")
        Self.UnregisterForAnimationEvent(akCaster, "MRh_SpellFire_Event")
    EndIf
EndEvent

We don't need to check for Staff any more because the game engine does it with Spell Condition.

 

I deep apologize for taking the learning out of it. Or did I?

 

I notice that

 caster = akTarget

So in Anim Event the Source is the Player, so I Targeted the Source with the spell.

 

Summing up

 

I hope you can see it. We are using CK Condition Version of the Papyrus Code I was using now. In the Spell. Which simplifies everything.

Link to comment
Share on other sites

Hm, yes. I got it to work with the spell condition, good idea! However, when having a staff in right hand and casting a normal spell on left hand it triggers the right hand spell script.

 

Looks like I'll have to work with the scripts you mentioned first, somehow to make it so the animation event only registers when a staff is equipped and onanimationevent only triggers on the hand the staff is equipped on.

 

I also found out that my own script worked and the fault was in the "spell" the onanimationevent should cast, I don't know why thought.

 

The AF_Release Spell is used without problems on the Right hand, but on the left hand it doesn't work at all. (I looked on the AF_Release Spell itself and it says "either hand".

 

The scripts for the AF_Release Spell is this

Scriptname AF_Release_StaffSpell_Script extends ActiveMagicEffect

Spell Property AF_Store_StaffSpellEnch Auto
FormList Property AF_StaffSpellEnch_FormList Auto
Event OnEffectStart(Actor akTarget, Actor akCaster)
If AF_StaffSpellEnch_FormList.GetSize() != 0
Int FormListRow = Utility.RandomInt(0, (AF_StaffSpellEnch_FormList.GetSize() - 1))
Spell SpellToCast = AF_StaffSpellEnch_FormList.GetAt(FormListRow) as Spell
SpellToCast.Cast(akTarget)
EndIf

EndEvent

 

 

The FX for the spell is triggered, but not the script itself and this is only happening for (Left Hand Staff)

Glitch,bug or not supported on Skyrim?

 

 

I edited my own code quickly, just for testing purposes before using your better written script.

I write below what worked and not.

 

Scriptname AF_StaffTestAbility_Enchant_Script extends activemagiceffect

;;USING SPELL CONDITION TO CHECK STAFF LEFT / RIGHT HAND 8
spell property AF_Staff_Right_Spell_Ability auto
spell property af_release_staffspellench auto
spell property af_release_staffsneakspellench auto
spell property icebolt auto
Actor caster
Event OnEffectStart(Actor akTarget, Actor akCaster)
caster = akTarget
RegisterForAnimationEvent(akTarget, "MRh_SpellFire_Event")
RegisterForAnimationEvent(akTarget, "MLh_SpellFire_Event")
EndEvent
Event OnAnimationEvent(ObjectReference akSource, string asEventName)
if (asEventName == "MRh_SpellFire_Event")
; Right
if caster.issneaking()
af_release_staffsneakspellench.cast(caster) ;; WORKS (RIGHT STAFF)
else
af_release_staffspellench.cast(caster) ;; WORKS (RIGHT STAFF)
EndIf
Elseif (asEventName == "MLh_SpellFire_Event")
; Left
if caster.issneaking()
af_release_staffsneakspellench.cast(caster) ;; DONT WORK,SAME SPELL AS ABOVE,WHY DOESNT IT WORK? (LEFT STAFF)
else
Icespike.cast(caster) ;; Vanilla Spell WORKS
EndIf
endif
EndEvent
Event OnEffectFinish(Actor akTarget, Actor akCaster)
UnregisterForAnimationEvent(akTarget, "MRh_SpellFire_Event")
UnregisterForAnimationEvent(akTarget, "MLh_SpellFire_Event")

EndEvent

 

 

If you check script, left staff vanilla spell worked just fine, my own spell doesnt.

Edited by GSGlobe
Link to comment
Share on other sites

  • Recently Browsing   0 members

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