INFO: OnSpellCast()

Post » Wed Jun 20, 2012 11:50 pm

I think I have found an efficient way to detecting if the player uses a Potion, Poison or Ingredient with "OnSpellCast()" without a massive form list and should be compatible with any mods that add said items. I have done a fair bit of testing, hopefully it will help.


----------------------------- Variables ------------------------Int intIngredientsEaten = 0; Number of Ingredients player has eaten to test against OnSpellCast().Int intPotionsTaken = 0; Number of Potions player has taken to test against OnSpellCast().Int intPoisonsUsed = 0; Number of Poisons player has used to test against OnSpellCast().Bool boASpell = FALSE; True if last effect was likely a spell.---------- Event before waiting for OnSpellCast() ------------intIngredientsEaten = Game.QueryStat("Ingredients Eaten")intPotionsTaken = Game.QueryStat("Potions Used")intPoisonsUsed = Game.QueryStat("Poisons Used")------------------------ OnSpellCast() Event--------------------------IF Game.QueryStat("Ingredients Eaten") == intIngredientsEaten && \   Game.QueryStat("Potions Used") == intPotionsTaken && \   Game.QueryStat("Poisons Used") == intPoisonsUsed   boASpell = TRUEENDIF; You now have a Bool function telling you if the player used a potion, poison or ingredient instead of a spell.
User avatar
sam westover
 
Posts: 3420
Joined: Sun Jun 10, 2007 2:00 pm

Post » Thu Jun 21, 2012 4:04 am

That's quite an innovative solution, but you can just check if the spell is either a Potion, Poison or Ingredient using the parameter supplied with the event. So your OnSpellCast event would look like this:

Event OnSpellCast(Form akSpell)  if (akSpell as Potion)	Debug.Trace("We just drank a potion!")  endif  if (akSpell as Spell)	Debug.Trace("We just cast a spell!")  endIf  if (akSpell as Ingredient)	Debug.Trace("We just ate an ingredient!")  endIfendEvent


A poison is also a potion, but you can find the difference between a potion and a poison using IsHostile(). The only problem is, for some reason Bethesda decided that Poisons don't trigger the OnSpellCast event.

User avatar
Elena Alina
 
Posts: 3415
Joined: Sun Apr 01, 2007 7:24 am


Return to V - Skyrim