I have been trying to write a piece of papyrus code that summarizes the currently equipped items of the player. I have a lot of programming experience but I have very little experience with the creation kit so I might be misusing things or solving problems in an overly complex manner. The code uses SKSE by the way.
What the code 'does' is register the left shift key event. When I press the left shift key the player's items are queried one by one with
p.getNthForm(n). The items, which are actually Forms, are then checked for being either armor or ammo and if they are it is checked if the player has them equipped (I hoped on a performance improvement by checking the types first). After that the left and right hand are checked for having a weapon/shield/torch/spell equipped or not and finally I check the shout.
Example output in the debug log is the following:
[04/07/2013 - 12:11:14AM] Items |Apparel: Dawnbreaker|Left hand: Spell - Flames|Right hand: Weapon - Dawnbreaker|Shout: [Shout < (0002F7BA)>]|
The problems are that
- The debug.trace function seems to be very unresponsive and a big number of shift presses is skipped. This may be because the script takes long to execute (order of seconds) and stays in the "busy" state.
- The answer is incorrect. I was also wearing apparel and had arrows equipped. They did not show up in this particular debug message when they should have.
scriptname DeazurainQuickLoadoutQuest extends Quest{Quick Loudout Event registering and updating}import DeazurainQuickLoadoutfloat version = 0.0; creationkit com/GetType_-_Form;kAmmo = 42;kArmor = 26;kShout = 119;kSpell = 22;kWeapon = 41event OnInit()dbg("First Run!")update()endevent; A loadout consists of; Left hand: weapon|spell|unarmed; Right hand: weapon|spell|unarmed; Apparel: [armor|ammo|shield]; Shout: shoutevent OnKeyDown(int keycode)GotoState("Busy")Actor p = Game.GetPlayer()string s = "Items |"int t ; type holder; Get apparelint n = p.getNumItems()while n n -= 1 Form f = p.getNthForm(n) t = f.getType() if t == 24 || t == 41 ; the form type is armor or ammo if p.isEquipped(f) s += "Apparel: " + f.getName() + "|" endif endifendwhile; Get left and right hand; creationkit com/GetEquippedItemType_-_Actort = p.getEquippedItemType(0) ; left handif t == 0 s += "Left hand: Unarmed|"elseif t == 9 Form f = p.getEquippedSpell(0) ; left hand s += "Left hand: Spell - " + f.getName() + "|"elseif t == 10 Form f = p.getEquippedShield() s += "Left hand: Shield - " + f.getName() + "|"elseif t == 11 Form f = p.getEquippedWeapon(true) ; left hand s += "Left hand: Torch - " + f.getName() + "|"else Form f = p.getEquippedWeapon(true) ; left hand s += "Left hand: Weapon - " + f.getName() + "|"endift = p.getEquippedItemType(1) ; right handif t == 0 s += "Right hand: Unarmed|"elseif t == 9 Form f = p.getEquippedSpell(1) ; right hand s += "Right hand: Spell - " + f.getName() + "|"elseif t == 11 Form f = p.getEquippedWeapon(false) ; right hand s += "Right hand: Torch - " + f.getName() + "|"else Form f = p.getEquippedWeapon(false) ; right hand s += "Right hand: Weapon - " + f.getName() + "|"endif; Get shoutForm theshout = p.getEquippedShout()s += "Shout: " + theshout + "|"; Log itDebug.trace(s)GotoState("")endeventfunction update()dbg("Checking for updates...")float versionOld = versionif version < 0.04 version = 0.04 ; perform special conversions in data structure, re-register events etc. RegisterForKey(42) ; shiftendifif versionOld == version dbg("No updates found")else dbg("Updated from " + versionOld + " to " + version)endifendfunctionstate Busyevent OnKeyDown(int keycode) ; Do nothingendEventendstate
I created a quest and attached the script to it. Don't mind the version part, the update function is called from another script in the OnPlayerLoadGame event.
Is there anyone who might be able to help me solve (one of) these problems?
Thanks in advance,
Deazurain