ReDragon2013 Posted March 28, 2020 Share Posted March 28, 2020 The simple logic of papyrus "state" related to your script ApplyPoisonOnHitScript Scriptname ApplyPoisonOnHitScript extends ActiveMagicEffect ; https://forums.nexusmods.com/index.php?/topic/8531238-make-script-return-to-top/page-3 ; properties are cut off here ; -- EVENTs -- EVENT OnEffectStart(Actor akTarget, Actor akCaster) Debug.Trace(" OnEffectStart() - target = " +akTarget+ ", player is [Actor < (00000014)>]") gotoState("Standby") ; ### STATE ### ENDEVENT ;EVENT OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) ; ; empty event in state("") ; ; but this is a native papyrus script event, you do not have to declare it here ;ENDEVENT ;============================== state Standby ;============ EVENT OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) IF ( abHitBlocked ) ; current hit was blocked by target which has this magiceffect applied! ELSEIF (akAggressor as Actor) gotoState("") ; ### STATE ### ; your code IF (aksource as Weapon) IF Utility.RandomInt(0, 1) as Bool ; (Utility.RandomInt(0, 1) == 1) ApplyPoisonOnHitFunction(akAggressor) ENDIF ENDIF gotoState("Standby") ; ### STATE ### back to this state to trigger a new hit event ENDIF ENDEVENT ;if (scriptrunning == 0) ; if(akAggressor as Actor) ; if(aksource as weapon) ; int coinflip = Utility.RandomInt(1, 2) ; if coinflip == 2 ; ApplyPoisonOnHitFunction(akAggressor) ; endif ; endif ; else ; Debug.Notification("Blocked") ; endif ;endif Maybe you are still interested in arrays, a suggestion for your function and properties Potion[] PROPERTY poList auto ;/ *** Potion Property DamageHealth01 Auto ; [0] Potion Property DamageHealth02 Auto Potion Property DamageHealth03 Auto Potion Property DamageHealth04 Auto Potion Property DamageHealth05 Auto Potion Property DamageHealthLinger01 Auto Potion Property DamageHealthLinger02 Auto Potion Property DamageHealthLinger03 Auto Potion Property DamageHealthLinger04 Auto Potion Property DamageHealthLinger05 Auto ; [9] Potion Property DamageMagicka01 Auto ; [10] Potion Property DamageMagicka02 Auto Potion Property DamageMagicka03 Auto Potion Property DamageMagicka04 Auto Potion Property DamageMagicka05 Auto ; [14] Potion Property DamageMagickaLinger01 Auto Potion Property DamageMagickaLinger02 Auto Potion Property DamageMagickaLinger03 Auto Potion Property DamageMagickaLinger04 Auto Potion Property DamageMagickaLinger05 Auto ; [19] Potion Property DamageStamina01 Auto ; [20] Potion Property DamageStamina02 Auto Potion Property DamageStamina03 Auto Potion Property DamageStamina04 Auto Potion Property DamageStamina05 Auto Potion Property DamageStaminaLinger01 Auto Potion Property DamageStaminaLinger02 Auto Potion Property DamageStaminaLinger03 Auto Potion Property DamageStaminaLinger04 Auto Potion Property DamageStaminaLinger05 Auto ; [29] Potion Property Paralyze01 Auto ; [30] Potion Property Paralyze02 Auto Potion Property Paralyze03 Auto Potion Property Paralyze04 Auto Potion Property Paralyze05 Auto ; [34] Potion Property DamageMagickaRecovery01 Auto ; [35] Potion Property DamageMagickaRecovery02 Auto Potion Property DamageMagickaRecovery03 Auto Potion Property DamageMagickaRecovery04 Auto Potion Property DamageMagickaRecovery05 Auto ; [39] Potion Property DamageStaminaRate01 Auto ; [40] Potion Property DamageStaminaRate02 Auto ; [41] Potion Property DamageStaminaRate03 Auto ; [42] Potion Property DamageStaminaRate04 Auto ; [43] *** /; Spell[] PROPERTY spList auto ;/ *** Spell Property DamageHealth01Spell Auto ; [0] Spell Property DamageHealth02Spell Auto Spell Property DamageHealth03Spell Auto Spell Property DamageHealth04Spell Auto Spell Property DamageHealth05Spell Auto ; [4] Spell Property DamageHealthLinger01Spell Auto ; [5] Spell Property DamageHealthLinger02Spell Auto Spell Property DamageHealthLinger03Spell Auto Spell Property DamageHealthLinger04Spell Auto Spell Property DamageHealthLinger05Spell Auto ; [9] Spell Property DamageMagicka01Spell Auto ; [10] Spell Property DamageMagicka02Spell Auto Spell Property DamageMagicka03Spell Auto Spell Property DamageMagicka04Spell Auto Spell Property DamageMagicka05Spell Auto ; [14] Spell Property DamageMagickaLinger01Spell Auto Spell Property DamageMagickaLinger02Spell Auto Spell Property DamageMagickaLinger03Spell Auto Spell Property DamageMagickaLinger04Spell Auto Spell Property DamageMagickaLinger05Spell Auto ; [19] Spell Property DamageStamina01Spell Auto ; [20] Spell Property DamageStamina02Spell Auto Spell Property DamageStamina03Spell Auto Spell Property DamageStamina04Spell Auto Spell Property DamageStamina05Spell Auto ; [24] Spell Property DamageStaminaLinger01Spell Auto Spell Property DamageStaminaLinger02Spell Auto Spell Property DamageStaminaLinger03Spell Auto Spell Property DamageStaminaLinger04Spell Auto Spell Property DamageStaminaLinger05Spell Auto ; [29] Spell Property Paralyze01Spell Auto ; [30] Spell Property Paralyze02Spell Auto Spell Property Paralyze03Spell Auto Spell Property Paralyze04Spell Auto Spell Property Paralyze05Spell Auto ; [34] Spell Property DamageMagickaRecovery01Spell Auto ; [35] Spell Property DamageMagickaRecovery02Spell Auto Spell Property DamageMagickaRecovery03Spell Auto Spell Property DamageMagickaRecovery04Spell Auto Spell Property DamageMagickaRecovery05Spell Auto ; [40] Spell Property DamageStaminaRate01Spell Auto ; [41] Spell Property DamageStaminaRate02Spell Auto ; [42] Spell Property DamageStaminaRate03Spell Auto ; [43] Spell Property DamageStaminaRate04Spell Auto ; [44] *** /; FormList PROPERTY myEmptyList auto ; **+ A formlist has to be created with CK and assigned to this script property! *** ;--------------------------------------------------------- Bool FUNCTION myF_TEST(ObjectReference oRef, Int i, Int m) ; helper to shrink code size ;--------------------------------------------------------- ; https://www.creationkit.com/index.php?title=DoCombatSpellApply_-_Actor ; https://www.creationkit.com/index.php?title=Revert_-_FormList myEmptyList.Revert() ; "Removes all script added forms from the list." int j = m WHILE (m <= i) myEmptyList.AddForm( poList[i] as Form ) ; GetAt(0) = 05, GetAt(1) = 04, .. , GetAt(4) = 01 i = i + 1 ENDWHILE IF (oRef.GetItemCount(myEmptyList) > 0) ; pre-test to shrink single item counts of native function "GetItemCount()" ;--- WHILE (i > m) i = i - 1 ; [i - 1] .. [m] form fm = poList[i] as Form IF (oRef.GetItemCount(fm) > 0)) (oRef as Actor).DoCombatSpellApply(spList[i], Game.GetPlayer() as ObjectReference) ; do combat spell from actor to objectRef oRef.RemoveItem(fm, 1) Return TRUE ENDIF ENDWHILE ;--- ENDIF Return False ENDFUNCTION ;------------------------------------------------------------- Function ApplyPoisonOnHitFunction(ObjectReference akAggressor) ;------------------------------------------------------------- ; "poList" array of potions ; "spList" array of spells int r = Utility.RandomInt(1, 9) ; r = random, first loop we are looking for int i form fm IF (r == 1) ; DamageHealth05 IF myF_Test(5, 0) RETURN ; - STOP - found a potion ENDIF ;;; i = 5 ;;; WHILE (i > 0) ;;; i = i - 1 ; [4] .. [0] ;;; fm = poList[i] as Form ;;; IF (akAggressor.GetItemCount(fm) > 0)) ; at least one potion found ;;; (akAggressor asActor).DoCombatSpellApply(spList[i], playerRef) ; do combat spell ;;; akAggressor.RemoveItem(fm, 1) ; remove a unit of potion ;;; RETURN ; - STOP - ;;; ENDIF ;;; ENDWHILE ;;; RETURN ; - STOP - remove comment, if you want test a single loop only ENDIF ;-------------- IF (r == 2) ; DamageHealthLinger05 ;;; IF myF_Test(10, 5) ;;; RETURN ; - STOP - ;;; ENDIF i = 10 WHILE (i > 5) i = i - 1 ; [9] .. [5] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) akAggressor.RemoveItem(fm, 1) RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 3) ; DamageMagicka05 ;;; IF myF_Test(15, 10) ;;; RETURN ; - STOP - ;;; ENDIF i = 15 WHILE (i > 10) i = i - 1 ; [14] .. [10] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) ; at least one potion found (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) ; do combat spell akAggressor.RemoveItem(fm, 1) ; remove a unit of potion RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 4) ; DamageMagickaLinger05 ;;; IF myF_Test(20, 15) ;;; RETURN ; - STOP - ;;; ENDIF i = 20 WHILE (i > 15) i = i - 1 ; [19] .. [15] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) akAggressor.RemoveItem(fm, 1) RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 5) ; DamageStamina05 ;;; IF myF_Test(25, 20) ;;; RETURN ; - STOP - ;;; ENDIF i = 25 WHILE (i > 20) i = i - 1 ; [24] .. [20] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) ; at least one potion found (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) ; do combat spell akAggressor.RemoveItem(fm, 1) ; remove a unit of potion RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 6) ; DamageStaminaLinger05 ;;; IF myF_Test(30, 25) ;;; RETURN ; - STOP - ;;; ENDIF i = 30 WHILE (i > 25) i = i - 1 ; [29] .. [25] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) akAggressor.RemoveItem(fm, 1) RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 7) ; Paralyze05 ;;; IF myF_Test(35, 30) ;;; RETURN ; - STOP - ;;; ENDIF i = 35 WHILE (i > 30) i = i - 1 ; [34] .. [30] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) ; at least one potion found (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) ; do combat spell akAggressor.RemoveItem(fm, 1) ; remove a unit of potion RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 8) ; DamageMagickaRecovery05 ;;; IF myF_Test(40, 35) ;;; RETURN ; - STOP - ;;; ENDIF i = 40 WHILE (i > 35) i = i - 1 ; [39] .. [35] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) akAggressor.RemoveItem(fm, 1) RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- IF (r == 9) ; DamageStaminaRate04 (4 only) ;;; IF myF_Test(44, 40) ;;; RETURN ; - STOP - ;;; ENDIF i = 44 WHILE (i > 40) i = i - 1 ; [43] .. [40] fm = poList[i] as Form IF (akAggressor.GetItemCount(fm) > 0)) ; at least one potion found (akAggressor as Actor).DoCombatSpellApply(spList[i], playerRef) ; do combat spell akAggressor.RemoveItem(fm, 1) ; remove a unit of potion RETURN ; - STOP - ENDIF ENDWHILE ENDIF ;-------------- ENDFUNCTION Link to comment Share on other sites More sharing options...
NexusComa Posted March 28, 2020 Share Posted March 28, 2020 (edited) Calling the goto to loop however creates an ever stacking fragment. I have a theory on why the other method works so well. Kind of a private project at this point however. Edited March 29, 2020 by NexusComa Link to comment Share on other sites More sharing options...
Recommended Posts