Script Debugging (Adding perks to player depending on armor

Post » Wed Jun 20, 2012 7:03 am

Welp if you've seen my other thread on Spell Conditionals you know what I'm up to here. Basically I'm trying to get it so the game detects if the player equips a heavy armor piece (i.e. a heavy armor cuirass, or boots), then gives the player a speed drain depending on the skill level of the player.

The way it works is thus:

1. Script detects what player has on, then gives perks depending on this. I.E. it'll add the Heavy Armor Cuirass perk if it detects that the player is wearing a heavy armor cuirass.

2. Perks determine what spell abilities to apply. The heavy armor Cuirass perk for example, adds all the spell abilities to the player that adjust speed, balanced for a cuirass in mind.

3. Spell abilities detect what the player skill level for Heavy Armor is, and in add a negative speedmult modifier to the player depending on this skill level. So for a cuirass, there might be 10 different spell abilities that are all activated at the same time, but each one has a different skill threshold and speed number. Only the ability that matches the player's current skill level will get activated. As a backup, the conditions of the spell effect double checks if the player is wearing a curiass for example, before applying the ability.

I have steps #2 and #3 working perfectly. The game correctly applies the speed drain for the right piece of armor being worn (boots, cuirass, etc) and the right skill level the player has.

Issue is, I'm trying to figure out the delivery. AKA, without the script, the player will get this speed drain reguardless of the armor type he/she is wearing - all curiasses will set off the cuirass speed drain, when I wish to only apply it to heavy armor cuirasses.

So I wrote up a script, here's what it looks like so far. The script is attached to the player, through the QuestAliases tab.


Scriptname CPO_PlayerSkills extends ReferenceAliasKeyword Property ArmorHeavy  AutoKeyword Property ArmorCuirass  AutoKeyword Property ArmorBoots  AutoKeyword Property ArmorGauntlets  AutoKeyword Property ArmorHelmet  AutoPerk Property CPO_HA_SpeedSkillCuirass  AutoPerk Property CPO_HA_SpeedSkillBoots  AutoPerk Property CPO_HA_SpeedSkillGauntlets  AutoPerk Property CPO_HA_SpeedSkillHelmit Auto;Check if an object is unequippedEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference);Next, check if the equipped object is armor   if akBaseObject As Armor   ;If it is armor, check to see if this piece of armor has the keywords ArmorHeavy AND ArmorCuirass.   ;If not, then the script continues to check if it's boots, gauntlets, etc.		If ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorCuirass))			Game.GetPlayer().RemovePerk(CPO_HA_SpeedSkillCuirass)		else ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorBoots))			Game.GetPlayer().RemovePerk(CPO_HA_SpeedSkillBoots)		else ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorGauntlets))			Game.GetPlayer().RemovePerk(CPO_HA_SpeedSkillGauntlets)		else ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorHelmet))			Game.GetPlayer().RemovePerk(CPO_HA_SpeedSkillHelmit)		endif   endifendEvent;Check if an object is equippedEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference);Next, check if the equipped object is armor   if akBaseObject As Armor   ;If it is armor, check to see if this piece of armor has the keywords ArmorHeavy AND ArmorCuirass.   ;If not, then the script continues to check if it's boots, gauntlets, etc. The perk itself does   ;the apropreate skill checks with its ability conditional statements.		If ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorCuirass))			Game.GetPlayer().AddPerk(CPO_HA_SpeedSkillCuirass)		else ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorBoots))			Game.GetPlayer().AddPerk(CPO_HA_SpeedSkillBoots)		else ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorGauntlets))			Game.GetPlayer().AddPerk(CPO_HA_SpeedSkillGauntlets)		else ((akBaseObject As Armor).HasKeyword(ArmorHeavy) && (akBaseObject As Armor).HasKeyword(ArmorHelmet))			Game.GetPlayer().AddPerk(CPO_HA_SpeedSkillHelmit)	 endif   endifendEvent

Unfortunatly, it fails to compile. Here's the errors:


Starting 1 compile threads for 1 files...Compiling "CPO_PlayerSkills"...f:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(23,7): required (...)+ loop did not match anything at input '('f:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(25,2): mismatched input 'else' expecting ENDIFf:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(25,7): required (...)+ loop did not match anything at input '('f:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(27,2): mismatched input 'else' expecting ENDIFf:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(29,2): mismatched input 'endif' expecting ENDEVENTf:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(42,7): required (...)+ loop did not match anything at input '('f:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(44,2): mismatched input 'else' expecting ENDIFf:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(44,7): required (...)+ loop did not match anything at input '('f:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(46,2): mismatched input 'else' expecting ENDIFf:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\CPO_PlayerSkills.psc(48,2): mismatched input 'endif' expecting ENDEVENTNo output generated for CPO_PlayerSkills, compilation failed.Batch compile of 1 files finished. 0 succeeded, 1 failed.Failed on CPO_PlayerSkills


Any help with this one?

Also another question - will the game "equip" the player upon the load of a save game (and thus correctly get the script working)? If not... how would I get the script to detect what armors the player is already wearing using OnInit() ?
User avatar
SHAWNNA-KAY
 
Posts: 3444
Joined: Mon Dec 18, 2006 1:22 pm

Post » Wed Jun 20, 2012 10:00 am

All I see so far is that you keep using "else" when you're supposed to be using "elseif". Try changing that and see if you get more errors.
User avatar
Alexandra walker
 
Posts: 3441
Joined: Wed Sep 13, 2006 2:50 am

Post » Wed Jun 20, 2012 1:20 pm

Sounds good, I'll try that. I thought it was supposed to be else? At least that's what the CK reference says. Ah well :tongue:

EDIT: That worked! Now to see if it works in-game.
User avatar
Gaelle Courant
 
Posts: 3465
Joined: Fri Apr 06, 2007 11:06 pm

Post » Wed Jun 20, 2012 2:17 am

Awesome!! It works perfect :D

Only problem is, as feared, it only kicks into effect when the player actually unequips/equips. Is it possible to check (on initialization of the script, or on cell load) what type of armor the player is already wearing and then from that, apply the perks that get applied on equip? I coudln't find a function that seems to be able to detect what a player/actor is already wearing beforehand.
User avatar
Lucky Girl
 
Posts: 3486
Joined: Wed Jun 06, 2007 4:14 pm

Post » Wed Jun 20, 2012 1:29 pm

There is an http://www.creationkit.com/OnLocationChange_-_Actor event for scripts extending Actor, and any script can use OnInit. Then I suppose you can use http://www.creationkit.com/WornHasKeyword_-_Actor to check and see if the player is already wearing heavy armor or not.
User avatar
Yvonne
 
Posts: 3577
Joined: Sat Sep 23, 2006 3:05 am

Post » Wed Jun 20, 2012 3:56 am

Ah awesome thank you! I knew of WornHasKeyword for magic effect/perk conditons but I could have sworn I didn't see a papyrus function for it :D

Thanks :)
User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am

Post » Tue Jun 19, 2012 11:41 pm

Okay thats nto gonna work, because like the conditional statment it checks things on a global level - if I wear any heavy armor at all it'll set off the function

A better idea would be a way to auto-unequip then equip armor a player is wearing. I found a function called "UnequipAll" but there's no options for this, and worse yet, no "EquipAll" to reverse it. How did that Thalmor embassy quest/forsworn work? I'm away from PC so I can't check. I'm pretty sure those quests had you unequip all items, then at the end it equipped all your items back onto you. How was that achieve and how did they "detect" what armors you were wearing?
User avatar
Tania Bunic
 
Posts: 3392
Joined: Sun Jun 18, 2006 9:26 am

Post » Wed Jun 20, 2012 8:48 am

In the Thalmor embassy quest, you handed off all your stuff to Delphine, and it was placed in a chest at the inn in Riverwood. You were also able to hand stuff to Malborn which he would return to you during the quest. Neither or them actually equipped the items onto the player.

In the Forsworn quest in Cidhna mine, I'm pretty sure it's just like going to jail. All your stuff is removed and placed somewhere, then it gets returned to you later on. They aren't re-equipped either.

Maybe you should just use UnequipAll and let the player manually re-equip his/her items? The unequip would only happen once.
User avatar
Dustin Brown
 
Posts: 3307
Joined: Sun Sep 30, 2007 6:55 am

Post » Wed Jun 20, 2012 12:01 pm

There's an easier way of doing this, with conditions inside a perk. I'll give you an example (screenshot) when I'm on my PC.
User avatar
kevin ball
 
Posts: 3399
Joined: Fri Jun 08, 2007 10:02 pm

Post » Wed Jun 20, 2012 1:46 pm

Won't have time to take screenshots, but if you just create as many perk entries as you need, i.e. all the entries from CPO_HA_SpeedSkillCuirass etc. with appropriate conditions so they only run when the player has items with the required key words equipped. Sorry that my explanation is not very detailed, but you can do this without a script.
User avatar
Fluffer
 
Posts: 3489
Joined: Thu Jul 05, 2007 6:29 am

Post » Wed Jun 20, 2012 7:46 am

Nah that won't work because keywords are global things. So if I am wearing ANY piece of heavy armor on my body, coupled with a curiass (even if its a light armor one) it'll trigger it. The conditions don't differentiate between items, they just look and see what items the player has.

OnInit onl goesy onces once, when the mod/script is first loaded right? In which case yeah, making it so the player has to equip all their items agian won't be so bad if they just have to do it when the mod first loads. It'll just be bad if they have to do that every time the game is loaded.
User avatar
Kerri Lee
 
Posts: 3404
Joined: Sun Feb 25, 2007 9:37 pm


Return to V - Skyrim