Masterofnet Posted January 8, 2015 Share Posted January 8, 2015 (edited) Scriptname TwoEvents extends ObjectReference Armor Property DA Auto Actor Property PlayerRef Auto GlobalVariable Property HelmetVar Auto Event OnUnequipped(Actor akActor) if akActor == PlayerRef && PlayerRef.IsInCombat() && PlayerRef.GetItemCount(DA) == 1 && HelmetVar.GetValue() == 0 HelmetVar.SetValue(1) Debug.Notification("Dragonborn Armor can not be unequiped while in combat") PlayerRef.EquipItem(DA, abSilent = true) Elseif akActor == PlayerRef && PlayerRef.IsInCombat() && PlayerRef.GetItemCount(DA) == 1 && HelmetVar.GetValue() == 1 Debug.Notification("Dragonborn Armor can not be unequiped while in combat") PlayerRef.EquipItem(DA, abSilent = true) Elseif akActor == PlayerRef && PlayerRef.IsInCombat()==False && HelmetVar.GetValue() == 1 || HelmetVar.GetValue() == 2 HelmetVar.SetValue(0) Debug.Notification("Dragonborn Armor can be unequiped while not in combat") endIf endEvent Event OnEquipped(Actor akActor) if akActor == PlayerRef && PlayerRef.IsInCombat() && HelmetVar.GetValue() == 0 HelmetVar.SetValue(2) Debug.Notification("Dragonborn Armor can not be equiped while in combat") PlayerRef.UnequipItem(DA, abSilent = true) Elseif akActor == PlayerRef && PlayerRef.IsInCombat() && HelmetVar.GetValue() == 2 Debug.Notification("Dragonborn Armor can not be equiped while in combat") PlayerRef.UnequipItem(DA, abSilent = true) Elseif akActor == PlayerRef && PlayerRef.IsInCombat()==False && HelmetVar.GetValue() == 1 || HelmetVar.GetValue() == 2 HelmetVar.SetValue(0) Debug.Notification("Dragonborn Armor can be equiped while not in combat") endIf endEventThis script works very well except for one problem. Under the event on unequipped you see this script. Elseif akActor == PlayerRef && PlayerRef.IsInCombat()==False && HelmetVar.GetValue() == 1 || HelmetVar.GetValue() == 2HelmetVar.SetValue(0)Debug.Notification("Dragonborn Armor can be unequiped while not in combat") If fires while the player is in combat. While the same exact script under the event on equipped does not. Any ideas as to why??? Thanks Edited January 8, 2015 by Masterofnet Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 8, 2015 Share Posted January 8, 2015 Isn't that script of yours theoretically obsolete because there is a game setting that does the same thing? I ran into it while looking for something else, I know it is there, but I don't know what it's called. Link to comment Share on other sites More sharing options...
Masterofnet Posted January 8, 2015 Author Share Posted January 8, 2015 (edited) I am not aware of a game setting that can make armor unable to be equipped or unequipped during combat, but if there is that would be the best way to do it. Any ideas on this script? Edited January 8, 2015 by Masterofnet Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 8, 2015 Share Posted January 8, 2015 (edited) I have an idea.Replace "PlayerRef.IsInCombat()==False" with "PlayerRef.IsInCombat()==0" I've never used True or False statements, and I don't know if they work properly either, I'm more of a 0 or 1 guy.http://www.creationkit.com/IsInCombat OR replace it with "PlayerRef.IsInCombat()!=1" Edited January 8, 2015 by Kerberus14 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 8, 2015 Share Posted January 8, 2015 Try this simplified script without the global variable logic. See if it works for your needs. Reveal hidden contents Scriptname TwoEvents extends ObjectReference Armor Property DA Auto Actor Property PlayerRef Auto Event OnUnequipped(Actor akActor) If akActor == PlayerRef If PlayerRef.GetItemCount(DA) >= 1 If PlayerRef.IsInCombat() Debug.Notification("Dragonborn Armor can not be unequipped while in combat") PlayerRef.EquipItem(DA,false,true) Else Debug.Notification("Dragonborn Armor is being unequipped") EndIf EndIf EndIf EndEvent Event OnEquipped(Actor akActor) If akActor == PlayerRef If PlayerRef.GetItemCount(DA) >= 1 If PlayerRef.IsInCombat() Debug.Notification("Dragonborn Armor can not be equipped while in combat") PlayerRef.UnequipItem(DA,false,true) Else Debug.Notification("Dragonborn Armor is being equipped") EndIf EndIf EndIf EndEvent I do not know if you actually need the global variable for some reason other than trying to track the equip status of the item. As far as a pre-existing means of not being able to equip or unequip an item.... That is done inside the EquipItem and UnEquipItem functions. Basically, EquipItem(DA,true,true) tells papyrus to equip the DA item, making it unremovable and preventing the equip message from being displayed. UnEquipItem(DA,true,true) tells papyrus to unequip the DA item, making it impossible to equip and preventing the unequip message from being displayed.However, this won't work in your case because you are relying on the player to attempt to equip or unequip the item while the script is running on the item itself. Link to comment Share on other sites More sharing options...
lofgren Posted January 8, 2015 Share Posted January 8, 2015 I use a very similar script that works just fine. Link to comment Share on other sites More sharing options...
Masterofnet Posted January 8, 2015 Author Share Posted January 8, 2015 On 1/8/2015 at 6:39 PM, Kerberus14 said: I have an idea.Replace "PlayerRef.IsInCombat()==False" with "PlayerRef.IsInCombat()==0" I've never used True or False statements, and I don't know if they work properly either, I'm more of a 0 or 1 guy.http://www.creationkit.com/IsInCombat OR replace it with "PlayerRef.IsInCombat()!=1"I agree I prefer to use ==0. In this case that is what I had in the script when I discovered the problem. Adding false did not change it. ()!=1 would that indicate the play is in combat or not it combat? Thanks Link to comment Share on other sites More sharing options...
Masterofnet Posted January 8, 2015 Author Share Posted January 8, 2015 (edited) On 1/8/2015 at 6:41 PM, IsharaMeradin said: Try this simplified script without the global variable logic. See if it works for your needs. Reveal hidden contents Scriptname TwoEvents extends ObjectReference Armor Property DA Auto Actor Property PlayerRef Auto Event OnUnequipped(Actor akActor) If akActor == PlayerRef If PlayerRef.GetItemCount(DA) >= 1 If PlayerRef.IsInCombat() Debug.Notification("Dragonborn Armor can not be unequipped while in combat") PlayerRef.EquipItem(DA,false,true) Else Debug.Notification("Dragonborn Armor is being unequipped") EndIf EndIf EndIf EndEvent Event OnEquipped(Actor akActor) If akActor == PlayerRef If PlayerRef.GetItemCount(DA) >= 1 If PlayerRef.IsInCombat() Debug.Notification("Dragonborn Armor can not be equipped while in combat") PlayerRef.UnequipItem(DA,false,true) Else Debug.Notification("Dragonborn Armor is being equipped") EndIf EndIf EndIf EndEvent I do not know if you actually need the global variable for some reason other than trying to track the equip status of the item. As far as a pre-existing means of not being able to equip or unequip an item.... That is done inside the EquipItem and UnEquipItem functions. Basically, EquipItem(DA,true,true) tells papyrus to equip the DA item, making it unremovable and preventing the equip message from being displayed. UnEquipItem(DA,true,true) tells papyrus to unequip the DA item, making it impossible to equip and preventing the unequip message from being displayed.However, this won't work in your case because you are relying on the player to attempt to equip or unequip the item while the script is running on the item itself. Thanks, I like this script. I tried the script. It works very well. However when you attempt to equip the item while in combat is allows the item to be equipped and displays these two messages. "Dragonborn Armor can not be equipped while in combat""Dragonborn Armor can not be unequipped while in combat" It does not allow the item to be unequipped while in combat. I also wanted to clarify the problem with my script a bit. When I attempt to equip the item while in combat the text displays. "Dragonborn Armor can not be equiped while in combat" and " Dragonborn Armor can be unequiped while not in combat " indicating clearly that it is firing while the player is in combat. When I attempt to Unequip the item it just shows."Dragonborn Armor can not be unequiped while in combat" indicating that the same event under the onequipeed event is not. The global is to make sure the script does not get caught in a loop of equipping and unequipping the armor and to make sure the player can equip or unequip when not in combat. Edited January 8, 2015 by Masterofnet Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 8, 2015 Share Posted January 8, 2015 (edited) If I were you I would use OnObjectEquipped and OnObjectUnEquipped instead of those.This is a general script, it works for all the armors and weapons/spells. You can replace the "as Armor" for armors with "as Weapon" for Weapons or with "as Spell" for Spells.Scriptname CombatChange extends ObjectReference Actor Property PlayerRef auto Function UnequipItem(Form akItem, bool abPreventEquip = false, bool abSilent = false) native Function EquipItem(Form akItem, bool abPreventRemoval = false, bool abSilent = false) native Int Property WasUnEquip auto Int Property WasEquip auto Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) akReference = PlayerRef if PlayerRef.IsInCombat()==1 && akBaseObject as Armor && WasEquip==0 PlayerRef.EquipItem(akBaseObject,false,true) Debug.Notification("You can't change armors in combat.") WasUnEquip=1 endif if PlayerRef.IsInCombat()!=1 WasUnEquip=0 endif EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) akReference = PlayerRef if PlayerRef.IsInCombat()==1 && akBaseObject as Armor && WasUnEquip==0 PlayerRef.UnequipItem(akBaseObject,false,true) Debug.Notification("You can't change armors in combat.") WasEquip=1 endif if PlayerRef.IsInCombat()!=1 WasEquip=0 endif EndEventThis is my go on the script. Tested it and it works. Edited January 8, 2015 by Kerberus14 Link to comment Share on other sites More sharing options...
Masterofnet Posted January 8, 2015 Author Share Posted January 8, 2015 (edited) Thanks Edited January 9, 2015 by Masterofnet Link to comment Share on other sites More sharing options...
Recommended Posts