the0champion Posted October 26, 2016 Share Posted October 26, 2016 So, very new to scripting, made a basic script which *should* level up your lockpicking skill (which I've repurposed to an unarmored skill tree). Some background, I created a perk labeled "MSGUnarmoredLeveling" as a perk that does nothing, but is added to your perks any time you're not wearing armor. I've tested that this perk works correctly, and it is listed in my active effects while I am unarmored. Anyway, here is the script: Scriptname MSGUnarmoredLevelup extends Perk ;;;;;;;;;;;;;;;;;;;;;;;;;;Input:None so far;;Progresses the Unarmored skill by leveling lockpicking whenever;you cast a spell while unarmored;;;;;;;;;;;;;;;;;;;;;;;;;;Actor Property Player AutoPerk Property MSGUnarmoredLeveling Auto Event OnInit();Display WIP Message BoxDebug.MessageBox("The Unarmored skill line is currently a work in progress.")EndEvent;This is a test script to level up your unarmored while casting spells and not wearing armor Event OnSpellCast()If Player.HasPerk(MSGUnarmoredLeveling)Game.AdvanceSkill("Lockpicking", 10.0)Debug.MessageBox("Skill Advancement is being triggered!")ElseDebug.MessageBox("OnSpellCast Event is being triggered, but seeing if the player has the perk is not being triggerd")EndIfEndEvent I've assigned player property to PlayerRef and the perk to MSGUnarmoredLeveling in the creation kit, but when I cast a spell with MSGUnarmoredLeveling listed under my active effects, nothing happens. The OnInit messagebox appears when I start up the game, so I know the script is active somewhere, it just doesn't seem to be doing anything.Thanks a bunch for any help, and sorry if this is painfully obvious to everyone else! Link to comment Share on other sites More sharing options...
lofgren Posted October 26, 2016 Share Posted October 26, 2016 Should extend activemagiceffect, not perk. OnSpellCast requires a parameter. http://www.creationkit.com/index.php?title=OnSpellCast_-_ObjectReference As written the script will advance lockpicking whenever the player casts any spell, eats food or potions, equips enchanted armor, etc. Link to comment Share on other sites More sharing options...
lofgren Posted October 27, 2016 Share Posted October 27, 2016 My previous comment may have been in error. I thought you were saying that you attached the script to the player through a magic effect. How are you attaching the script to the player? If it is a reference alias then the script should extend ReferenceAlias, if it is a magic effect then it should extend ActiveMagicEffect. If you don't know what I am talking about then you should walk us through the steps you have taken so far. Link to comment Share on other sites More sharing options...
the0champion Posted October 27, 2016 Author Share Posted October 27, 2016 So I didn't attach it to the player, I've attached it to a perk I've created called "MSGLevelingAid" I've rewritten the code as follows: Scriptname MSGUnarmoredLevelup extends Perk ;;;;;;;;;;;;;;;;;;;;;;;;;;Input:None so far;;Progresses the Unarmored skill by leveling lockpicking whenever;you cast a spell while unarmored;;;;;;;;;;;;;;;;;;;;;;;;;;Actor Property Player AutoPerk Property MSGUnarmoredLeveling AutoPerk Property MSGMixedArmorLeveling AutoPerk Property MSGLightArmorLevelingPure AutoPerk Property MSGHeavyArmorLevelingPure AutoPerk Property MSGLevelingAid AutoMessage Property MSGUnarmoredLevelingMessage AutoMessage Property MSGLightArmorLevelingMessage AutoMessage Property MSGHeavyArmorLevelingMessage AutoMessage Property MSGMixedArmorLevelingMessage Auto Event OnInit();Display WIP Message Box;Debug.MessageBox("The Unarmored skill line is currently a work in progress.");Gives the player the perk that will apply leveling aid perks based on worn statusGame.GetPlayer().AddPerk(MSGLevelingAid);Call the static functionMSGStaticLevelUp()EndEvent;This is a test script to level up your unarmored while casting spells and not wearing armor Event OnSpellCast()If Player.HasPerk(MSGUnarmoredLeveling)Game.AdvanceSkill("Lockpicking", 10.0)Debug.MessageBox("Skill Advancement is being triggered!")ElseDebug.MessageBox("OnSpellCast Event is being triggered, but seeing if the player has the perk is not being triggerd")EndIfEndEvent Function MSGStaticLevelUp();check to see if player is unarmoredif Player.HasPerk(MSGUnarmoredLeveling)Game.AdvanceSkill("Lockpicking",10.0);MSGUnarmoredLevelingMessage.Show()ElseIf Player.HasPerk(MSGMixedArmorLeveling)Game.AdvanceSkill("HeavyArmor",1.0)Game.AdvanceSkill("LightArmor",1.0);MSGMixedArmorLevelingMessage.Show()ElseIf Player.HasPerk(MSGHeavyArmorLevelingPure)Game.AdvanceSkill("HeavyArmor",2.0);MSGHeavyArmorLevelingMessage.Show()ElseIf Player.HasPerk(MSGLightArmorLevelingPure)Game.AdvanceSkill("LightArmor",2.0);MSGLightArmorLevelingMessage.Show()Else;Debug.MessageBox("None of your leveling aid perks have been applied")EndIfUtility.Wait(10.0)MSGStaticLevelUp()EndFunction This has successfully applied the "MSGLevelingAid" perk to the player, and then that perk applies an Ability which gives you any of the other 4 sub perks (MSGUnarmoredLeveling, etc.) based on your current armored status. I've successfully tested the recursion function I added to the script and it'll slowly level over time your Unarmored, Light Armor, or Heavy Armor based on what you're wearing, so I know the perks are working correctly. Perhaps the Event OnSpellCast() is not the best trigger for this script? I'll try adding an extra level to the recursion which will check to see if the player has the appropriate perk and is casting a spell, but I was trying to avoid having the script rerunning every second to see if you're casting. Link to comment Share on other sites More sharing options...
lofgren Posted October 27, 2016 Share Posted October 27, 2016 This is not a great way to go about this at all. You should move your scripts off of the perk into an ability, and have the magic effects of the ability turn on and off based on condition functions in the spell. That way you can use RegisterForSingleUpdate() loops instead of Utility.Wait() loops, which will be much more efficient and easier to abort if necessary. You can have a different magic effect for each condition. Magic effects also receive the OnSpellCast event (which, again, requires a parameter). Perks do not receive that event. As written your script will consume massive resources and eventually either cause crazy script lag or crash the game. Link to comment Share on other sites More sharing options...
the0champion Posted October 27, 2016 Author Share Posted October 27, 2016 OK thanks. I'll try that out. Right now it does work (I even managed to get a convoluted perk to help with the whole leveling while casting), but like you said, I'm worried about the memory drain, so I'll try rewriting it that way. Link to comment Share on other sites More sharing options...
the0champion Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) Sweet, that worked like a champ, and made for a much neater script. Thanks again for the help!Here's how much shorter the script is, for anyone who's working with similar issues: Scriptname MSGSpellCastUnarmoredLeveling extends activemagiceffect Actor Property Player AutoMagicEffect Property MSGSpellCastUnarmored AutoMessage Property MSGSpellCastUnarmoredMessage Auto Event OnEffectStart(Actor akTarget, Actor akCaster)ObjectReference Caster = akCasterMSGSpellCastUnarmoredLevelingLoop()EndEvent Function MSGSpellCastUnarmoredLevelingLoop()If Player.HasMagicEffect(MSGSpellCastUnarmored)Game.AdvanceSkill("Lockpicking",20.0)MSGSpellCastUnarmoredMessage.Show()RegisterForSingleUpdate(1)ElseUnRegisterForUpdate()EndIfEndFunction Event OnUpdate()MSGSpellCastUnarmoredLevelingLoop()EndEventScript is attached to a magic effect which is applied to an ability which triggers that magic effect any time you are not wearing armor and casting. Edited October 27, 2016 by the0champion Link to comment Share on other sites More sharing options...
lofgren Posted October 27, 2016 Share Posted October 27, 2016 Another option would be to move the script to a quest, but that would still require you to attach the OnSpellCast event to the player somehow. Link to comment Share on other sites More sharing options...
Recommended Posts