maniczombie Posted June 29, 2012 Share Posted June 29, 2012 Here is my script: Scriptname HelmetToggleScriptNPC extends ObjectReference Spell Property ToggleSpell Auto Actor Property CurrentActor Auto Armor Property IronHelmet Auto Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject == IronHelmet if (CurrentActor.hasSpell(ToggleSpell)) Debug.Notification("Has Spell") else Debug.Notification("Does not have Spell") endif endif EndEvent Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) if akBaseObject == IronHelmet Endif EndEvent When I link the Actor Property to the player it works fine, but if I link it too Lydia instead (HouseCarlWhiterun) then I always get "Does not have spell" returned. I have 2 spells, 1 that adds the effect to the player on first cast, then removes on second. My other spell does the same to a target.The Script attatched to the aimed spell works fine at detecting if the actor has the spell or not using if(GetTargetActor().hasSpell(ToggleHelmetToggledSpell)) I plan for this script to be attached to every NPC in the game. If anyone knows whats going wrong please help. Thanks Link to comment Share on other sites More sharing options...
LittleBaron Posted June 30, 2012 Share Posted June 30, 2012 I am confused looking at your script about out how you planned on 'giving' it to every actor in the game. You would need to assign the CurrentActor property by hand for every single NPC and attach this script to... something... besides the NPC but would need as many somethings as there are NPC's. How are you planning on delivering it? Also, you are asking the script if the CurrentActor has the spell ToggleSpell when what you really mean to do is ask if they have whatever effect the ToggleSpell applies, I think. This will make it say yes for the player, for whom you have probably given the ability to cast the spell, and say no for Lydia who just had the spell cast on her. If that is the case you want to call HasMagicEffect instead. Hope that helps a bit :thumbsup: Link to comment Share on other sites More sharing options...
maniczombie Posted June 30, 2012 Author Share Posted June 30, 2012 HasMagicEffect doesn't work either The way the spell works is I have a cast spell with a script attached which adds the toggle spell to the target so she would have both the spell and the effect, but neither are getting detected. I know the adding to every npc thing is long winded but it's the easiest solution I can see to what I'm trying to achieve. I've replaced all helmets in the game with hidden versions so I have to add a script to all npcs to make them show helmets again if they don't have the toggle spell. Link to comment Share on other sites More sharing options...
maniczombie Posted June 30, 2012 Author Share Posted June 30, 2012 I think it's the CurrentActor Property that doesn't work as if CurrentActor.IsEquipped(IronHelmet) isn't working either. Please someone tell me what I'm doing wrong?? Link to comment Share on other sites More sharing options...
Woverdude Posted July 5, 2012 Share Posted July 5, 2012 Try changing: if (CurrentActor.hasSpell(ToggleSpell)) to if (CurrentActor.hasSpell(ToggleSpell) == 1) As it is, you have not specified whether it should return when the request is true or when it is false. I'm not entirely sure how Papyrus handle such requests, and it might assume that you are telling it to return when true. However, it might not. It's good to be specific just in case. As far as applying the script to each NPC, let me suggest another method. I have not tested this method, because I do not have your spells, but the changed script compiles and I'm fairly confident that it should work. Instead, you should try creating an ability (constant effect Spell) that runs the script on everyone in the vicinity. That way, the script will still be done, but you will save the processor some work, will save yourself a lot of time, and will make your mod work with other mods that add new NPCs. To do this, create a MagicEffect with the 'Script' Effect Archetype, the 'ConstantEffect' Casting Type, and the 'Self' Delivery. Also give it an Area value. I would suggest 100 to make sure that it runs on everyone in the vicinity. Next, add the script to the MagicEffect. Make sure and change the script so that it extends ActiveMagicEffect. Also, I would suggest changing the Event to OnEffectStart. To make sure that the CurrentActor is the Target, write a line that says that CurrentActor = akTarget. That way, checking whether CurrentActor has the spell will check whether the target has the spell. You will also need to change the line: if akBaseObject == IronHelmet to if (CurrentActor.IsEquipped(IronHelmet) == 1) so that it checks the target for the IronHelmet. You're going to have to make one more change. Giving someone an ability with a script does not rerun the script. Even though it is ConstantEffect, the script will only run once. So, you're going to have to make sure that when the effect is finished, you take away the Ability and then give it back so that it runs again and keeps on running. Also, you can add 'false' after the spell name to make sure that it does not constantly notify you that it is being removed and then added again. The end result that I came up with was this: Scriptname HelmetToggleScriptNPC extends activemagiceffect Spell Property ToggleSpell Auto Spell Property ThisAbility Auto Armor Property IronHelmet Auto Actor Property CurrentActor Auto Event OnEffectStart(Actor akTarget, Actor akCaster) CurrentActor = akTarget if (CurrentActor.IsEquipped(IronHelmet) == 1) if (CurrentActor.HasSpell(ToggleSpell) == 1) Debug.Notification("Has Spell") elseif (CurrentActor.HasSpell(ToggleSpell) == 0) Debug.Notification("Does not have Spell") endif endif EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) if (CurrentActor.HasSpell(ThisAbility) == 1) CurrentActor.RemoveSpell(ThisAbility, false) CurrentActor.Addspell(ThisAbility, false) endif EndEvent If this works, then it will save you a ton of time, will make people happy because your mod plays well with others, and might save the PC some processing power. Link to comment Share on other sites More sharing options...
Recommended Posts