Scripting an ability to the player on equip

Post » Wed Jun 19, 2013 7:01 am

I'm trying to create a mod that adds various sets of armor to the game that will increase in power as the player equips more pieces, but I'm running into trouble with the scripts to make it work.

The way it's supposed to work is that the player gains an ability (right now, zzzTestEffect) as soon as he equips one piece of armor, he gets the ability, and for each additional piece he equips, it becomes stronger or gains additional effects. To that end, I've given each armor set a keyword that is shared by each piece (in this case, zzzTestItem). zzzTestEffect itself has several effects which only appear if the player is wearing a certain number of items with the zzzTestItem keyword. I've posted the script below.

Spoiler
Scriptname TestSetScript extends ObjectReferencekeyword Property zzzTestItem Autospell Property zzzTestEffect AutoEvent OnEquipped (Actor AkActor)    if AkActor == Game.GetPlayer()        if Actor.HasSpell(Spell akzzTestEffect) == False            Game.GetPlayer().AddSpell(zzzTestEffect)        endif    endifEndEvent    Event OnUnequipped (Actor AkActor)        if AkActor == Game.GetPlayer()        if Actor.WornHasKeyword(Keyword zzzTestItem) == False            Game.GetPlayer().RemoveSpell(zzzTestEffect)        endif    endif    EndEvent

The intention of the script is for the first armor piece of the set the player equips to give him zzzTestEffect. It's supposed to check whether the player already has it before granting the ability, though, so that the player doesn't gain multiple copies of the ability. When a piece of armor is unequipped, the script is supposed to check if it's the last piece of armor from the set that the player has equipped, and if so, remove the ability entirely. However, in its current form, the script doesn't seem to do anything at all. When I equip the armor in game, the character doesn't gain any of the effects the armor is supposed to grant.

To be clear, I'd like to set up the effects of the armor sets this way because I don't want the benefits attached to any individual pieces of armor. I don't want a setup like Azhidal's Boots of Waterwalking that provide a +10 Enchanting bonus with four relics equipped; I want something where the player gets the +10 Enchanting (or other effect) if he has any four pieces of the set equipped.

User avatar
Paula Ramos
 
Posts: 3384
Joined: Sun Jul 16, 2006 5:43 am

Post » Wed Jun 19, 2013 7:19 pm

You need to simplify your variables to test and troubleshoot:

See what happens when you do this:

Scriptname TestSetScript extends ObjectReferencekeyword Property zzzTestItem Autospell Property zzzTestEffect AutoEvent OnEquipped (Actor AkActor)    if AkActor == Game.GetPlayer()        if Actor.HasSpell(Spell akzzTestEffect) == False            Game.GetPlayer().AddSpell(zzzTestEffect)        endif        if Actor.HasSpell(Spell akzzTestEffect) == True            debug.messagebox("Add spell working")        endif    endifEndEvent    Event OnUnequipped (Actor AkActor)        if AkActor == Game.GetPlayer()        if Actor.WornHasKeyword(Keyword zzzTestItem) == True            debug.messagebox("Keyword working")        endif    endif    EndEvent
User avatar
sam smith
 
Posts: 3386
Joined: Sun Aug 05, 2007 3:55 am

Post » Wed Jun 19, 2013 12:12 pm

Depending on what you're trying to do, it might be easier to apply a perk with a conditional like the ones found in the MatchingSet perk.

WornApparelHasKeywordCount

User avatar
Jarrett Willis
 
Posts: 3409
Joined: Thu Jul 19, 2007 6:01 pm


Return to V - Skyrim