As a demo of how this might be used, I put together a very quick little mod which, when a hotkey is pressed, looks at the object in the crosshairs, and uses the GetNumItemsWithKeyword and GetNumItemsOfType functions from this download to tell you how many potions and pieces of armour it contains.
Added screenshots to demo this in action. It's actually kind of a cute idea for a real mod, I think - as the screenshots show, it might tell you if a chest is worth the time picking the lock.
(Of course, this being based on Quad2Core's work, I would be remiss if I didn't mention the fantastic Lock Overhaul by the same author - which allows you to simply smash the lock off with a massive warhammer, thereby also avoiding any time spent lockpicking! )
my followers keep doing this (throwing poison) thing and i notice in their inventory they have these throwing potions as scrolls, are those scrolls in the vanilla game... i would prefer if they used it on their blade instead, is there a way to change that?
;debug.notification("Attempting to poison weapon in left hand") ;get form of weapon in right hand Form RightHandWeap=PlayerRef.GetEquippedWeapon(false);false=right hand ;get form of weapon in left hand Form LeftHandWeap=PlayerRef.GetEquippedWeapon(true) ;unequip right hand weapon PlayerRef.UnequipItemEx(RightHandWeap,1,false) ;unequip left hand weapon PlayerRef.UnequipItemEx(LeftHandWeap,2,false) ;equip left hand weapon in right hand PlayerRef.EquipItemEx(LeftHandWeap,1,false,false) utility.wait(0.5) ;poison weapon in right hand PlayerRef.EquipItemEx(FormThatMatches,1,false,true) utility.wait(0.5) ;unequip left hand weapon from right hand PlayerRef.UnequipItemEx(LeftHandWeap,1,false) ;equip left hand weapon in left hand PlayerRef.EquipItemEx(LeftHandWeap,2,false,false) ;equip original right hand weapon PlayerRef.EquipItemEx(RightHandWeap,1,false,false)
Thank you so much for this. I'm having trouble using SKSE functions. For example
function InitializeFormlists() ;************************************************************ ;*******Fills formlist with all spells a player has learned** ;************************************************************ int nSpellsLearned=PlayerRef.GetSpellCount() int LoopCounter=0 debug.trace("Spells player knows: " + nSpellsLearned) form curSpell
while (LoopCounter<nSpellsLearned) curSpell=PlayerRef.GetNthSpell(LoopCounter) if PlayerRef.HasSpell(curSpell) SpellFormList.AddForm(curSpell) ;debug.notification("Spell " + LoopCounter + " added: " + curSpell.GetName()) endif LoopCounter+=1 endwhile
;debug.notification ("Spells form list initialized!"
It doesn't return all the spells in a players inventory, and it returns some powers that the player doesn't have. For example the above code returns nightingale armor full set, shrouded armor full set, ahzials genius, and crossbow bonus, on a brand new clean save just out of Helgen in Riverwood. It correctly finds the warrior stone, oakflesh, and sparks, but it doesn't return flames, which the player does have.
I need an efficient function that will fill a formlist with only the spells that a player knows. I was thinking I could use ActorGetSpells, or ActorBaseGetSpells with an empty asSchool parameter to return ALL spells that a player knows. Is that correct? What would the syntax be if I want to get all spells of every school for both the actor, and the actor base?
What is the difference between the actorspells and the actorbasespells?
Hello there - sorry this took a couple of days, but investigating this led me to some interesting discoveries (and an improvement to this plugin, which I'll get to later)..
So first off, to address why you're seeing what you are. I ran your function on a brand new character, and got the same results. Looking in the Creation Kit, it turns out the things you're seeing are Ability spells which are added to your character via Perks. They have conditions on them so they only actually have an effect at certain times (like "Shrouded Armor Full Set", which only kicks in if you're wearing four Dark Brotherhood items), but they are permanently applied, which is why they pop up in the list.
As to why Flames and Healing are missing, that relates to the difference between Actor and ActorBase. The ActorBase is what's defined in the Creation Kit, while the Actor is an 'instance' of this, which appears in the world. When you learn spells, they are added to the Actor - but your starting spells are defined on the ActorBase.
To confirm that, I ran the PlayerRef.GetActorBase().GetSpellCount() function, and that did return Flames and Healing. It also returned one called "Combat Heal Rate" - which is another permanent Ability (not sure why that one is applied directly in the Spell list, rather than applied via a Perk like the "Full Set" ones, but so it goes..)
And so, we come to what you actually need: a way to populate a FormList with just the actual spells that someone (like the player) knows.
Turns out, I couldn't find a way to make the current SKSE functions ignore those Abilities (there might be one - but I've not found it). However, I was able to modify this plugin to distinguish between Spells, Abilities, etc. So when I ran the modified version on my brand-new character (including scanning the ActorBase), I got exactly two results: Flames, and Healing :D
So, the next step will be to incorporate this 'Spell Type' option into the functions this plugin adds. I'll need to have a bit of a think on how to do that with the minimum of disruption to anyone who might be using these functions already.. Hopefully have an answer in a day or so though! When that's done, you should have a simple function (like 'ActorGetSpells') that you can call, and get a nice, neat spell list :)
Many, many thanks for your question, as it gave me the kick to dive in a little deeper to how these things work, and (hopefully!) make my work better and more useful!
Update to v3.02 - the Return of the Poisoning functions!
I'm very happy to say that I've been able to figure out how to restore the super-awesome poison-related functions that Quad2Core had in the original plugin (but which weren't in the v1 source, which is why it's taken me a while to figure them out).
These work in a similar way to the SKSE Enchantment and ItemHealthPercent functions - as in, you need to have either an ObjectReference or an equipped object to pass in. With these, you can add poison to an item, un-poison the item, find how many charges it has left, set the number of charges.
Hopefully the function comments on the Description page tell you all you need to know, but any questions, just shout up.
Added some functions for modifying Ammo objects (arrows and Bolts), since SKSE 1.7.3 doesn't have them :(
I know they're not really inventory functions, but they're needed by my new 'Arrow Sheaves' mod, and I didn't want to create another plugin just for them! :p
The major change here is that, following irswat's comment about how getting spells would return Ability effects (which are set on the Player from the start), I'm now able to filter out Ability effects like these from the returned lists.
As a result, you should now be able to call "ActorGetSpells" on someone, and see a full list of just the *real* spells that they have.
Of course, this is subject to how things are set up - if the game (or a mod) is applying something which acts like an Ability, but it's marked as a Spell in the Creation Kit, then it will still turn up in the returned list. I would expect that won't happen often, but be aware..
Great work,thank you very much.Is it possiable to provide some functions that can get all spells already learned in a school,like playerref.getalldestructionspells()
Ooh, that could be interesting! I think it should be possible - although whether it's possible for me is another matter! I can definitely have a look though.
I'd probably do it as a GetSpellsOfSchool function, and you'd pass in the Actor (so PlayerRef would be valid to pass in), and the magic school (as a string) - and the usual option to search ActorBase, since that's where the spells usually are. Then you'd get back an Array of Spell objects.
So the Papyrus would be: Spell[] function GetSpellsOfSchool(Actor akActor, string asSchool, bool abSearchBase)
How's that look?
By the way, you can technically do this using pre-existing SKSE functions: iterate the Spells for an Actor, get each MagicEffect for each Spell, and do GetAssociatedSkill() for each MagicEffect. I can send you an example in a PM if you like?
I know it's been a while, but I've done an update which includes what you were after - a way to get a list of spells an Actor knows, filtered by the magic school. So for your original example (all Destruction spells on the player), you would now be able to do:
I've added functions to retrieve spell lists from Actors, filtered by conditions (eg all spells of the Restoration school, or all spells of level 50 (Adept) or higher).
These can also be used to test if an Actor has a particular spell, by calling the function, and testing if the result has at least one spell (I've included a bool version of each function which does just that).
This does mean that the previous, keyword-and school-specific spell checks (Actor(Base)HasSpellSchool, Actor(Base)HasSpellKeyword) are now unnecessary - you can use the generic functions, and just pass in blank arguments for the things you don't want to check for (check the Description page for the full options).
I've kept those old functions in the script for now, though - but all they do is call the main functions with the relevant blank arguments.
29 comments
Added screenshots to demo this in action. It's actually kind of a cute idea for a real mod, I think - as the screenshots show, it might tell you if a chest is worth the time picking the lock.
(Of course, this being based on Quad2Core's work, I would be remiss if I didn't mention the fantastic Lock Overhaul by the same author - which allows you to simply smash the lock off with a massive warhammer, thereby also avoiding any time spent lockpicking! )
However...it does not work with Anniversary Edition, which is a bummer.
I'm using this to circumvent Apply Combat Hit Spell limitations!
Are there any other utilities like this? things that just add SKSE functions rather than mod the game directly
;get form of weapon in right hand
Form RightHandWeap=PlayerRef.GetEquippedWeapon(false);false=right hand
;get form of weapon in left hand
Form LeftHandWeap=PlayerRef.GetEquippedWeapon(true)
;unequip right hand weapon
PlayerRef.UnequipItemEx(RightHandWeap,1,false)
;unequip left hand weapon
PlayerRef.UnequipItemEx(LeftHandWeap,2,false)
;equip left hand weapon in right hand
PlayerRef.EquipItemEx(LeftHandWeap,1,false,false)
utility.wait(0.5)
;poison weapon in right hand
PlayerRef.EquipItemEx(FormThatMatches,1,false,true)
utility.wait(0.5)
;unequip left hand weapon from right hand
PlayerRef.UnequipItemEx(LeftHandWeap,1,false)
;equip left hand weapon in left hand
PlayerRef.EquipItemEx(LeftHandWeap,2,false,false)
;equip original right hand weapon
PlayerRef.EquipItemEx(RightHandWeap,1,false,false)
It doesn't return all the spells in a players inventory, and it returns some powers that the player doesn't have. For example the above code returns nightingale armor full set, shrouded armor full set, ahzials genius, and crossbow bonus, on a brand new clean save just out of Helgen in Riverwood. It correctly finds the warrior stone, oakflesh, and sparks, but it doesn't return flames, which the player does have.
I need an efficient function that will fill a formlist with only the spells that a player knows. I was thinking I could use ActorGetSpells, or ActorBaseGetSpells with an empty asSchool parameter to return ALL spells that a player knows. Is that correct? What would the syntax be if I want to get all spells of every school for both the actor, and the actor base?
What is the difference between the actorspells and the actorbasespells?
Thanks again!
So first off, to address why you're seeing what you are. I ran your function on a brand new character, and got the same results. Looking in the Creation Kit, it turns out the things you're seeing are Ability spells which are added to your character via Perks. They have conditions on them so they only actually have an effect at certain times (like "Shrouded Armor Full Set", which only kicks in if you're wearing four Dark Brotherhood items), but they are permanently applied, which is why they pop up in the list.
As to why Flames and Healing are missing, that relates to the difference between Actor and ActorBase. The ActorBase is what's defined in the Creation Kit, while the Actor is an 'instance' of this, which appears in the world. When you learn spells, they are added to the Actor - but your starting spells are defined on the ActorBase.
To confirm that, I ran the PlayerRef.GetActorBase().GetSpellCount() function, and that did return Flames and Healing. It also returned one called "Combat Heal Rate" - which is another permanent Ability (not sure why that one is applied directly in the Spell list, rather than applied via a Perk like the "Full Set" ones, but so it goes..)
And so, we come to what you actually need: a way to populate a FormList with just the actual spells that someone (like the player) knows.
Turns out, I couldn't find a way to make the current SKSE functions ignore those Abilities (there might be one - but I've not found it). However, I was able to modify this plugin to distinguish between Spells, Abilities, etc. So when I ran the modified version on my brand-new character (including scanning the ActorBase), I got exactly two results: Flames, and Healing :D
So, the next step will be to incorporate this 'Spell Type' option into the functions this plugin adds. I'll need to have a bit of a think on how to do that with the minimum of disruption to anyone who might be using these functions already.. Hopefully have an answer in a day or so though! When that's done, you should have a simple function (like 'ActorGetSpells') that you can call, and get a nice, neat spell list :)
Many, many thanks for your question, as it gave me the kick to dive in a little deeper to how these things work, and (hopefully!) make my work better and more useful!
I'm very happy to say that I've been able to figure out how to restore the super-awesome poison-related functions that Quad2Core had in the original plugin (but which weren't in the v1 source, which is why it's taken me a while to figure them out).
These work in a similar way to the SKSE Enchantment and ItemHealthPercent functions - as in, you need to have either an ObjectReference or an equipped object to pass in. With these, you can add poison to an item, un-poison the item, find how many charges it has left, set the number of charges.
Hopefully the function comments on the Description page tell you all you need to know, but any questions, just shout up.
Cheers all!
Added some functions for modifying Ammo objects (arrows and Bolts), since SKSE 1.7.3 doesn't have them :(
I know they're not really inventory functions, but they're needed by my new 'Arrow Sheaves' mod, and I didn't want to create another plugin just for them! :p
The major change here is that, following irswat's comment about how getting spells would return Ability effects (which are set on the Player from the start), I'm now able to filter out Ability effects like these from the returned lists.
As a result, you should now be able to call "ActorGetSpells" on someone, and see a full list of just the *real* spells that they have.
Of course, this is subject to how things are set up - if the game (or a mod) is applying something which acts like an Ability, but it's marked as a Spell in the Creation Kit, then it will still turn up in the returned list. I would expect that won't happen often, but be aware..
Many thanks again to irswat for the help!
gonna replace my sloppy novel with
Spell[] SpellFormArray=new spell[127]
SpellFormArray=ActorGetSpells(playerRef as actor)
SpellFormList.AddForms(SpellFormArray)
I'd probably do it as a GetSpellsOfSchool function, and you'd pass in the Actor (so PlayerRef would be valid to pass in), and the magic school (as a string) - and the usual option to search ActorBase, since that's where the spells usually are. Then you'd get back an Array of Spell objects.
So the Papyrus would be:
Spell[] function GetSpellsOfSchool(Actor akActor, string asSchool, bool abSearchBase)
How's that look?
By the way, you can technically do this using pre-existing SKSE functions: iterate the Spells for an Actor, get each MagicEffect for each Spell, and do GetAssociatedSkill() for each MagicEffect. I can send you an example in a PM if you like?
I know it's been a while, but I've done an update which includes what you were after - a way to get a list of spells an Actor knows, filtered by the magic school. So for your original example (all Destruction spells on the player), you would now be able to do:
Spell[] playerSpells = _Q2C_Functions.ActorGetSpells(playerRef, None, "Destruction")
I know it's quite late coming, but hope it might be some use! :)
I've added functions to retrieve spell lists from Actors, filtered by conditions (eg all spells of the Restoration school, or all spells of level 50 (Adept) or higher).
These can also be used to test if an Actor has a particular spell, by calling the function, and testing if the result has at least one spell (I've included a bool version of each function which does just that).
This does mean that the previous, keyword-and school-specific spell checks (Actor(Base)HasSpellSchool, Actor(Base)HasSpellKeyword) are now unnecessary - you can use the generic functions, and just pass in blank arguments for the things you don't want to check for (check the Description page for the full options).
I've kept those old functions in the script for now, though - but all they do is call the main functions with the relevant blank arguments.