Jump to content

Can't seem to detect certain hats? Script help?


Recommended Posts

hi guys i have a script tied to a quest simply looking for an "OnItemEquipped" event to find if the player has a specific hat equipped and if so to change the hair style.

 

This is what i have so far...

Scriptname SM_Skytails_Equip extends ReferenceAlias

Keyword Property ArmorTypeHat Auto
HeadPart Property Skytails03 Auto
HeadPart Property Skytails03_Hat Auto
HeadPart Property Skytails03_Cap Auto

Armor Property TeddyHat Auto
Armor Property LongshoremanHat Auto

Event Oninit()
	RegisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
	RegisterForRemoteEvent(Game.GetPlayer(), "OnItemUnEquipped")
EndEvent

Event Actor.OnItemEquipped(Actor akActor, Form akBaseObject, ObjectReference akReference)
	if (Utility.IsInMenuMode() == TRUE)
		If (akBaseObject == LongshoremanHat)
			Debug.notification("LongshoremanHat found")
			EquipCap()
		Else
		CheckEquip()
		EndIf
	EndIf
EndEvent

Event OnItemUnequipped(Form akBaseObject, ObjectReference akReference)
	if (Utility.IsInMenuMode() == TRUE)
		if akBaseObject.HasKeyword(ArmorTypeHat)
			CheckUnequip()
		EndIf
	endIf
endEvent

FUNCTION CheckEquip()
	Form Equipment = Game.GetPlayer().GetWornItem(0).Item
		If Equipment.HasKeyword(ArmorTypeHat)
			UnregisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
				If Equipment == Longshoremanhat
					Debug.notification("beany hat")
				Else
					EquipHat()
				EndIf
		EndIf
EndFUNCTION

FUNCTION CheckUnequip()
		Debug.notification("hat unequipped")
		UnequipHat()
EndFUNCTION

Event OnTimer(int aiTimerID)		
	If aiTimerID == 10
		if (Utility.IsInMenuMode() == TRUE)
			RegisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
			RegisterForRemoteEvent(Game.GetPlayer(), "OnItemUnEquipped")
				Debug.Notification("Done")
		EndIf
	EndIf
	If aiTimerID == 11
		if (Utility.IsInMenuMode() == TRUE)
			RegisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
				Debug.Notification("Done")
		EndIf
	EndIf
EndEvent

FUNCTION EquipHat() ; 																					<-- hat
  UnRegisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
  UnRegisterForRemoteEvent(Game.GetPlayer(), "OnItemUnEquipped")
	ActorBase PlayerBase = Game.GetPlayer().GetActorBase()
	HeadPart[] headparts = PlayerBase.GetHeadParts()
	Form Equipment = Game.GetPlayer().GetWornItem(0).Item
		If headparts.Find(SkyTails03) <1
			Game.getplayer().changeHeadPart(SkyTails03, True, True) ; <--- remove normal hair
			Game.getplayer().changeHeadPart(SkyTails03_Hat, false, false) ; <--- force equip hat hair
				StartTimer(1, 10)
		EndIf	
		If headparts.Find(SkyTails03_Cap) <1
			Game.getplayer().changeHeadPart(SkyTails03_Cap, True, True) ; <--- remove normal hair
			Game.getplayer().changeHeadPart(SkyTails03_Hat, false, false) ; <--- force equip hat hair
				StartTimer(1, 10)
		EndIf	
EndFUNCTION

FUNCTION EquipCap()																				<--- cap
  UnRegisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
  UnRegisterForRemoteEvent(Game.GetPlayer(), "OnItemUnEquipped")
	ActorBase PlayerBase = Game.GetPlayer().GetActorBase()
	HeadPart[] headparts = PlayerBase.GetHeadParts()

		If headparts.Find(SkyTails03_Hat) <1
			Game.getplayer().changeHeadPart(SkyTails03_Hat, True, True) 
			Game.getplayer().changeHeadPart(SkyTails03_Cap, false, false)
				StartTimer(1, 10)
		EndIf
		If headparts.Find(SkyTails03) <1
			Game.getplayer().changeHeadPart(SkyTails03, True, True) 
			Game.getplayer().changeHeadPart(SkyTails03_Cap, false, false)
				StartTimer(1, 10)
		EndIf
EndFUNCTION

FUNCTION UnequipHat()
  UnRegisterForRemoteEvent(Game.GetPlayer(), "OnItemEquipped")
  UnRegisterForRemoteEvent(Game.GetPlayer(), "OnItemUnEquipped")
	ActorBase PlayerBase = Game.GetPlayer().GetActorBase()
	HeadPart[] headparts = PlayerBase.GetHeadParts()
		If headparts.Find(SkyTails03_Hat) >0
			Game.getplayer().changeHeadPart(SkyTails03_hat, True, True) ; <--- remove hat hair
			Game.getplayer().changeHeadPart(SkyTails03_Cap, True, True) ; <--- remove cap hair
			Game.getplayer().changeHeadPart(SkyTails03, false, false)
				StartTimer(1, 11)
		EndIf	
		If headparts.Find(SkyTails03_Cap) >0
			Game.getplayer().changeHeadPart(SkyTails03_hat, True, True) ; <--- remove hat hair
			Game.getplayer().changeHeadPart(SkyTails03_Cap, True, True) ; <--- remove cap hair
			Game.getplayer().changeHeadPart(SkyTails03, false, false)
				StartTimer(1, 11)
		EndIf	
ENDFUNCTION


But both ways of trying to find the hat fail, and i dont know why...

If (akBaseObject == LongshoremanHat)
Form Equipment = Game.GetPlayer().GetWornItem(0).Item
  If Equipment == Longshoremanhat

The "GetWornItem" line seems to detect that the hat in slot 0 has the "ArmorTypeHat" keyword

Form Equipment = Game.GetPlayer().GetWornItem(0).Item
If Equipment.HasKeyword(ArmorTypeHat)

but it wont detect if the worn item is the LongshoremanHat.

 

does anyone know why? or how to fix the script so that it wil find the LongshoremanHat if its equipped?

Link to comment
Share on other sites

You are comparing Armor with From, cast it:

Armor Equipment = Game.GetPlayer().GetWornItem(0).Item As Armor
If Equipment && Equipment == LongshoremanHat

If you try to cast a base object to an invalid type it returns false, so the next statement means if base object can be casted as armor and the base object casted as armor is equal to LongshoremanHat:

If akBaseObject As Armor && akBaseObject As Armor == LongshoremanHat

On the other hand, in a ReferenceAlias, the script is already listening to Actor and ObjectReference events, you don't need to listen as remote event. So if your alias is pointing to the player you can listen for events like if the script were attached to the ObjectReference/Actor. Also you can get the actor reference or the object reference with GetActorReference() and GetReference() (instead of using Self or Self As Actor as you would use in a ObjectReference script).

Edited by DieFeM
Link to comment
Share on other sites

Thankyou DieFeM, that worked nicely - well, it works for another hat im testing, but it still wont find the LongshoremanHat (the blue one) specifically :/ hmm i wonder if another mod is replacing that hat or something?

 

*EDIT*

Yep, as it turns out i was consoling in the wrong hat all along hahaha.

Thanks DieFeM, i think your solution is going to work really well :)

Edited by SandMouseAnarchy
Link to comment
Share on other sites

  • Recently Browsing   0 members

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