NexusComa Posted March 27, 2020 Share Posted March 27, 2020 That's exactly what a developer would say ... :ermm: Link to comment Share on other sites More sharing options...
foamyesque Posted March 27, 2020 Share Posted March 27, 2020 (edited) FWIW, my own script is working fine so far (edit: and this is not to say that I'm not eagerly going through your scripts trying to learn how to improve my own scripts myself), it is however attached to an Ability I've given the Player.You say you wouldn't do that - could you explain why you wouldn't? I think it's possible Nexus thought you were applying the script directly to the player, which is very bad practice because of the potential for mod conflicts. Aliases or spells are much, much better options (and aliases are usually the best way to add spells in any case). However, you say you're creating this as an ability, which so long as you're not editing the player record directly to do so, is fine. However, the player's a shared, high-priority resource, and will get hit (a lot) in circumstances where you know you won't have to ever care about this. OnHits can also fire multiple times if there's an enchanted weapon or a spell involved. That means you're potentially handling a lot of events you don't need to, which bogs down the script engine for everything else. For something like this I'd consider, e.g, making sure the ability isn't added until the player enters a triggerbox,and is removed when the player leaves it. That triggerbox can then be enabled or disabled by the quest this is associated with so that it doesn't do anything unless the quest is currently active. EDIT: Also, if you want a something that avoids using the stack or putting scripts on multiple objects... int iSize = itemList.GetSize() bool bRemoved = false while !bRemoved && iSize > 0 int iIndex = Utility.RandomInt(0, iSize) - 1 Form testForm = itemList.GetAt(iIndex) int iCount = akAggressor.GetItemCount(testForm) if iCount > 0 akAggressor.RemoveItem(testForm,1) bRemoved = true if iCount == 1 itemList.RemoveAddedForm(testForm) endif else itemList.RemoveAddedForm(testForm) iSize = itemList.GetSize() endif endwhile This obviously doesn't include the setup bits or filtering to make sure of the attacker or attack type, it's just the core random-selection piece. What it does is randomly select one thing from a FormList. If that exists in the attacker's inventory, it removes it. If it was the last copy of that thing in the attacker's inventory, it also removes it from the formlist, so it can't be selected again. If it *doesn't* exist in the attacker's inventory, it removes it from the FormList, and then selects randomly again. This continues until either it's successfully removed something or the FormList is exhausted. You could make this go faster with SKSE and arrays, if needed. The advantage here over the simple hardcoded tri-case setup is that this is extensible to as many items as you want, so you're not locked into exactly three by your own code. Note that unlike my prior one this one fails if more items are somehow added to the NPCs inventory. Edited March 27, 2020 by foamyesque Link to comment Share on other sites More sharing options...
dylbill Posted March 27, 2020 Share Posted March 27, 2020 Thanks NexusComa for the input. I also like seeing different perspectives on coding style, and the reasons why things are done. Your post was very insightful. I also agree with foamyesque that the script / effect should only be active when it needs to be. If the script is only supposed to work on a specific actor, you could put a condition on the ability's magic effect GetDistance ActorRef < 5000. That way the effect is only active if you're around the actor. Link to comment Share on other sites More sharing options...
foamyesque Posted March 27, 2020 Share Posted March 27, 2020 Thanks NexusComa for the input. I also like seeing different perspectives on coding style, and the reasons why things are done. Your post was very insightful. I also agree with foamyesque that the script / effect should only be active when it needs to be. If the script is only supposed to work on a specific actor, you could put a condition on the ability's magic effect GetDistance ActorRef < 5000. That way the effect is only active if you're around the actor.The problem there is that it magic effects will poll that test, quite frequently, and the vast, vast majority of the time, it'll be negative. It doesn't use the script engine, but it's still not something to do if you can avoid it.And in this case, I think you can. This is, presumably, a boss enemy of some sort. Enclose the entire cell they're in with a triggerbox that's set to register the player entering or leaving (this way it will handle people using the console to get around, though not using it to teleport or spawn the NPC elsewhere), and when that happens, add or remove the ability. That way it's only monitoring if the two of them are capable of interacting in the place where they are intended to interact. Link to comment Share on other sites More sharing options...
TangerineDog Posted March 28, 2020 Author Share Posted March 28, 2020 I solved that by having a potion the player needs to drink to advance the story anyway add this spell. This occurs in the very dungeon the opponent is in as well.And a triggerbox i nan area the player needs to pass through after the fight (but can't pass through before) removes the spell before the player enters the vanilla world again.Sure, that's more story-based than any form of elegant coding. It' a mod I'm doing for a friend so I want it to be as little engine-murdering as possible nonetheless :turned: However, after scripting this, I decided to try my hand on something that has bugged me for a while: there's no mod that makes NPCs use poisons without changing more about the game.With a script that checks for inventory items, this should now be possible without me having to add an ability to every enemy template, I reckon. Of course, now that the script will, in fact, be called on multiple times in battle, I want to make sure it can be, as @NexusComa put it, drilled and still work.So far, I haven't had any issues running this script in a room with 10 poison-equipped bandits thrashing me.But I'm using only what I know Papyrus to be able to do and I don't know if, for example, you can add a hierarchy of importance to items on a form list. Potion Property DamageHealth01 Auto 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 Potion Property DamageMagicka01 Auto Potion Property DamageMagicka02 Auto Potion Property DamageMagicka03 Auto Potion Property DamageMagicka04 Auto Potion Property DamageMagicka05 Auto Potion Property DamageMagickaLinger01 Auto Potion Property DamageMagickaLinger02 Auto Potion Property DamageMagickaLinger03 Auto Potion Property DamageMagickaLinger04 Auto Potion Property DamageMagickaLinger05 Auto Potion Property DamageMagickaRecovery01 Auto Potion Property DamageMagickaRecovery02 Auto Potion Property DamageMagickaRecovery03 Auto Potion Property DamageMagickaRecovery04 Auto Potion Property DamageMagickaRecovery05 Auto Potion Property DamageStamina01 Auto 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 Potion Property DamageStaminaRate01 Auto Potion Property DamageStaminaRate02 Auto Potion Property DamageStaminaRate03 Auto Potion Property DamageStaminaRate04 Auto Potion Property Paralyze01 Auto Potion Property Paralyze02 Auto Potion Property Paralyze03 Auto Potion Property Paralyze04 Auto Potion Property Paralyze05 Auto Spell Property DamageHealth01Spell Auto Spell Property DamageHealth02Spell Auto Spell Property DamageHealth03Spell Auto Spell Property DamageHealth04Spell Auto Spell Property DamageHealth05Spell Auto Spell Property DamageHealthLinger01Spell Auto Spell Property DamageHealthLinger02Spell Auto Spell Property DamageHealthLinger03Spell Auto Spell Property DamageHealthLinger04Spell Auto Spell Property DamageHealthLinger05Spell Auto Spell Property DamageMagicka01Spell Auto Spell Property DamageMagicka02Spell Auto Spell Property DamageMagicka03Spell Auto Spell Property DamageMagicka04Spell Auto Spell Property DamageMagicka05Spell Auto Spell Property DamageMagickaLinger01Spell Auto Spell Property DamageMagickaLinger02Spell Auto Spell Property DamageMagickaLinger03Spell Auto Spell Property DamageMagickaLinger04Spell Auto Spell Property DamageMagickaLinger05Spell Auto Spell Property DamageMagickaRecovery01Spell Auto Spell Property DamageMagickaRecovery02Spell Auto Spell Property DamageMagickaRecovery03Spell Auto Spell Property DamageMagickaRecovery04Spell Auto Spell Property DamageMagickaRecovery05Spell Auto Spell Property DamageStamina01Spell Auto Spell Property DamageStamina02Spell Auto Spell Property DamageStamina03Spell Auto Spell Property DamageStamina04Spell Auto Spell Property DamageStamina05Spell Auto Spell Property DamageStaminaLinger01Spell Auto Spell Property DamageStaminaLinger02Spell Auto Spell Property DamageStaminaLinger03Spell Auto Spell Property DamageStaminaLinger04Spell Auto Spell Property DamageStaminaLinger05Spell Auto Spell Property DamageStaminaRate01Spell Auto Spell Property DamageStaminaRate02Spell Auto Spell Property DamageStaminaRate03Spell Auto Spell Property DamageStaminaRate04Spell Auto Spell Property Paralyze01Spell Auto Spell Property Paralyze02Spell Auto Spell Property Paralyze03Spell Auto Spell Property Paralyze04Spell Auto Spell Property Paralyze05Spell Auto int scriptrunning = 0 Event OnInit() GoToState("Standby") EndEvent Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) if scriptrunning == 0 if(akAggressor as Actor) if(aksource as weapon) int coinflip = Utility.RandomInt(1, 2) if coinflip == 2 ApplyPoisonOnHitFunction(akAggressor) endif endif endif endif EndEvent Function ApplyPoisonOnHitFunction(ObjectReference akAggressor) scriptrunning = 1 int random = Utility.RandomInt(1, 9) int randommaster = random int hasskipped = 0 If hasskipped == 0 If random == 1 If (akAggressor.GetItemCount(DamageHealth05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth05, 1) ElseIf (akAggressor.GetItemCount(DamageHealth04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth04, 1) ElseIf (akAggressor.GetItemCount(DamageHealth03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth03, 1) ElseIf (akAggressor.GetItemCount(DamageHealth02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth02, 1) ElseIf (akAggressor.GetItemCount(DamageHealth01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth01, 1) Else random = random + 1 EndIf EndIf If random == 2 If (akAggressor.GetItemCount(DamageHealthLinger05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger05, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger04, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger03, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger02, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger01, 1) Else random = random + 1 EndIf EndIf If random == 3 If (akAggressor.GetItemCount(DamageMagicka05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka05, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka04, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka03, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka02, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka01, 1) Else random = random + 1 EndIf EndIf If random == 4 If (akAggressor.GetItemCount(DamageMagickaLinger05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger05, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger04, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger03, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger02, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger01, 1) Else random = random + 1 EndIf EndIf If random == 5 If (akAggressor.GetItemCount(DamageMagickaRecovery05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery05, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery04, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery03, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery02, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery01, 1) Else random = random + 1 EndIf EndIf If random == 6 If (akAggressor.GetItemCount(DamageStamina05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina05, 1) ElseIf (akAggressor.GetItemCount(DamageStamina04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina04, 1) ElseIf (akAggressor.GetItemCount(DamageStamina03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina03, 1) ElseIf (akAggressor.GetItemCount(DamageStamina02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina02, 1) ElseIf (akAggressor.GetItemCount(DamageStamina01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina01, 1) Else random = random + 1 EndIf EndIf If random == 7 If (akAggressor.GetItemCount(DamageStaminaLinger05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger05, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger04, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger03, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger02, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger01, 1) Else random = random + 1 EndIf EndIf If random == 8 If (akAggressor.GetItemCount(DamageStaminaRate04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate04, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaRate03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate03, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaRate02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate02, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaRate01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate01, 1) Else random = random + 1 EndIf EndIf If random == 9 If (akAggressor.GetItemCount(Paralyze05) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze05Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze05, 1) ElseIf (akAggressor.GetItemCount(Paralyze04) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze04Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze04, 1) ElseIf (akAggressor.GetItemCount(Paralyze03) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze03Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze03, 1) ElseIf (akAggressor.GetItemCount(Paralyze02) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze02Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze02, 1) ElseIf (akAggressor.GetItemCount(Paralyze01) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze01Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze01, 1) Else random = 1 hasskipped = 1 EndIf EndIf ElseIf If random == 1 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageHealth05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth05, 1) ElseIf (akAggressor.GetItemCount(DamageHealth04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth04, 1) ElseIf (akAggressor.GetItemCount(DamageHealth03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth03, 1) ElseIf (akAggressor.GetItemCount(DamageHealth02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth02, 1) ElseIf (akAggressor.GetItemCount(DamageHealth01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealth01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealth01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 2 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageHealthLinger05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger05, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger04, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger03, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger02, 1) ElseIf (akAggressor.GetItemCount(DamageHealthLinger01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageHealthLinger01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageHealthLinger01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 3 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageMagicka05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka05, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka04, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka03, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka02, 1) ElseIf (akAggressor.GetItemCount(DamageMagicka01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagicka01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagicka01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 4 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageMagickaLinger05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger05, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger04, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger03, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger02, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaLinger01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaLinger01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaLinger01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 5 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageMagickaRecovery05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery05, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery04, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery03, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery02, 1) ElseIf (akAggressor.GetItemCount(DamageMagickaRecovery01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageMagickaRecovery01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageMagickaRecovery01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 6 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageStamina05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina05, 1) ElseIf (akAggressor.GetItemCount(DamageStamina04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina04, 1) ElseIf (akAggressor.GetItemCount(DamageStamina03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina03, 1) ElseIf (akAggressor.GetItemCount(DamageStamina02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina02, 1) ElseIf (akAggressor.GetItemCount(DamageStamina01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStamina01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStamina01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 7 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageStaminaLinger05) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger05Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger05, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger04, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger03, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger02, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaLinger01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaLinger01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaLinger01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 8 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(DamageStaminaRate04) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate04Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate04, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaRate03) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate03Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate03, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaRate02) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate02Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate02, 1) ElseIf (akAggressor.GetItemCount(DamageStaminaRate01) > 0) Game.GetPlayer().DoCombatSpellApply(DamageStaminaRate01Spell, Game.GetPlayer()) akAggressor.RemoveItem(DamageStaminaRate01, 1) Else random = random + 1 EndIf EndIf EndIf If random == 9 If random == randommaster random = 0 Else If (akAggressor.GetItemCount(Paralyze05) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze05Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze05, 1) ElseIf (akAggressor.GetItemCount(Paralyze04) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze04Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze04, 1) ElseIf (akAggressor.GetItemCount(Paralyze03) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze03Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze03, 1) ElseIf (akAggressor.GetItemCount(Paralyze02) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze02Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze02, 1) ElseIf (akAggressor.GetItemCount(Paralyze01) > 0) Game.GetPlayer().DoCombatSpellApply(Paralyze01Spell, Game.GetPlayer()) akAggressor.RemoveItem(Paralyze01, 1) Else random = 0 EndIf EndIf EndIf EndIf If random == 0 EndIf scriptrunning = 0 GoToState("Standby") EndFunction State Standby EndState> Link to comment Share on other sites More sharing options...
dylbill Posted March 28, 2020 Share Posted March 28, 2020 Two things I notice off the bat. You don't need to do If random == 0 at the end of the script, as there's no function in that condition. Also, instead of using game.GetPlayer(), define the player as a property by doing Actor Property PlayerRef Auto, and filling it in the creation kit, it's faster than using .GetPlayer a bunch of times. Link to comment Share on other sites More sharing options...
TangerineDog Posted March 28, 2020 Author Share Posted March 28, 2020 :ermm: I must be doing something wrong...If I change it toPlayerRef.DoCombatSpellApply(DamageHealth05Spell, Game.GetPlayer())nothing happens anymore.If I change it toGame.GetPlayer().DoCombatSpellApply(DamageHealth05Spell, PlayerRef)the bandit hitting me is poisoned and dies. Link to comment Share on other sites More sharing options...
dylbill Posted March 28, 2020 Share Posted March 28, 2020 Did you fill the PlayerRef property in the creation kit? Also I think it should be: akAggressor.DoCombatSpellApply(DamageHealth05Spell, PlayerRef) Link to comment Share on other sites More sharing options...
TangerineDog Posted March 28, 2020 Author Share Posted March 28, 2020 (edited) Did you fill the PlayerRef property in the creation kit? Also I think it should be: akAggressor.DoCombatSpellApply(DamageHealth05Spell, PlayerRef)That I did - but why can't the PlayerRef apply the Spell to itself?Also, with akAggressor.DoCombatSpellApply, it doesn't compile anymore, saying DoCombatSpellApply is not a funciton or doesn't exist - amybe because akAggressor is an object Reference while DoCombatSpellApply is part of an Actor Script? Edited March 28, 2020 by TangerineDog Link to comment Share on other sites More sharing options...
NexusComa Posted March 28, 2020 Share Posted March 28, 2020 (edited) Well that was like pulling the pin on a grenade ... I applaud your tenacity. You would need to add the reference up top also to make PayerRef actually be the player reference.With: Actor Property PlayerREF Auto <- then to fill the reference press auto fill when you're in the kit on that entree.Dylbill is right on the mark as that call uses twice like that in the same line is adding 3 times the cycles for that line. This would be a great time to incorporate ReDragon2013 arrays with that long of a variable section.Not that what you're doing is wrong, just to clean it up a bit. Like this ... Potion Property DamageHealth[] autoPotion Property DamageHealthLinger[] autoThe calls would look like DamageHealth[1], DamageHealth[2] and so on. Looks like 4 for each one. Then you load them up in the kit.Sometimes this can get a bit confusing but arrays are built for speed. Arrays in Skyrim can go as high a 128 so you actually could if you wished put all that in one array.Or split it up ... would work the same ether way.It would be: PlayerRef.DoCombatSpellApply(DamageHealthSpell[5], PlayerRef) ; I think .. sometimes playerREF can be touchy and you do need to actually add Game.GetPlayer(). Edited March 28, 2020 by NexusComa Link to comment Share on other sites More sharing options...
Recommended Posts