Jump to content

Problem with script


Masterofnet

Recommended Posts

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
endEvent

This 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() == 2

HelmetVar.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 by Masterofnet
Link to comment
Share on other sites

Try this simplified script without the global variable logic. See if it works for your needs.

 

 

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

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

Try this simplified script without the global variable logic. See if it works for your needs.

 

 

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 by Masterofnet
Link to comment
Share on other sites

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

EndEvent

This is my go on the script. Tested it and it works.

Edited by Kerberus14
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...