Jump to content

What do I need to do to get this scipt to work?


Bount227

Recommended Posts

Scriptname Tier_PerkRestrictions extends ReferenceAlias


Group Keywords

	Keyword Property Tier_Lvl Auto Const

EndGroup

FormList Property EquippedWeapon Auto Const

Weapon Property Equipped Auto Const



Function UnEquipItem(Form Equipped, bool abPreventEquip = true, bool abSilent = false) 
	If Game.GetPlayer().IsEquipped(EquippedWeapon) && EquippedWeapon.HasKeyword(Tier_Lvl)
		Game.GetPlayer().UnEquipItem(EquippedWeapon)
	EndIf
EndFunction

I am trying to write a script that will prevent the player from equipping certain weapons based on Keywords. So far, no dice. The way it is seen gives the impression it should work but I am learning on the fly and am missing something as it does not, in fact, work. Here is a screenshot on how I got the perk set up. Found a thread that opened this idea and very thankful as it really was helpful in broadening my horizons. Forum thread

I feel it is important to mention that the Keyword is working in-game and that the perks are present as well.

 

Screenshot of Perk window

 

Quote

Screenshot(50).thumb.png.04a26e893a077bf1a494fe6b4d4c640c.png

 

Link to comment
Share on other sites

I am not a scripter so i can't offer any code but I'm familiar enough with the game engine and papyrus functions to offer some insight. I don't see any condition set for your function to fire. Given what you are trying to do you I think you need a condition that causes your function to fire on player equip item.

  • Like 1
Link to comment
Share on other sites

5 hours ago, worm82075 said:

I am not a scripter so i can't offer any code but I'm familiar enough with the game engine and papyrus functions to offer some insight. I don't see any condition set for your function to fire. Given what you are trying to do you I think you need a condition that causes your function to fire on player equip item.

Would you be able elaborate? In my head I have set those conditions, so I am unable to see what you mean, if that makes sense?

 

Talking about something like this?

Quote

Screenshot(51).thumb.png.d08a0620a5b5ab5cee9f808f0e58b010.png

Screenshot(52).thumb.png.9070f300855ecccede8ad3aa1c733049.png

 

Link to comment
Share on other sites

13 hours ago, Bount227 said:

I am trying to write a script that will prevent the player from equipping certain weapons based on Keywords.

 

 

It's been a while since I made something like this but if I'm remembering right, the keyword "playerCannotEquip [KYWD:001CF299]" needs to be added to the item to make it non-equippable.

Here's its dev notes: "For items which we want to appear as lootable, but not usable by the player.  (ie: creature armors, other things for which "unplayable" is not quite right)"

("Playable" is an equippable Form data flag (e.g. Weapon) which, if unchecked, can also prevent the player from equipping the item).

A Perk with Perk Entry "Activate" can't be used to block equipping a weapon found in the game world. (Maybe it can be used to block taking it with Target Condition: HasKeyword 'playerCannotEquip' == 0, I'm not sure right right, but it surely doesn't make it unequippable).

You can't add keywords to non-persistent items directly if they're already in the inventory because vanilla Papyrus doesn't provide any function for this. If there's only instance of this item in the inventory, you can use AttachModToInventoryItem. (Just add the relevant Property Modifier to the ObjectMod to attach a keyword to the item; see mod_armor_Synth_Leg_Material_0 "Standard" [OMOD:00046D9C] and its dn_HasMaterial_0 [KYWD:00182E73] keyword for example).

If you want to instantly Unequip the item to prevent it from staying equipped, then here's a quick code that should work or at least point you to the right direction:

Scriptname Tier_PerkRestrictions extends ReferenceAlias

Group Keywords
	Keyword Property Tier_Lvl Auto Const
EndGroup

FormList Property EquippedWeapon Auto Const
Weapon Property Equipped Auto Const


Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)			; event sent when the reference filled into the RefAlias this script is attached to equips something
	Actor PlayerRef = Game.GetPlayer()										; store Player variable to be used later in this event to prevent calling Game.GetPlayer() again (to speed up script execution; i.e. no need to "ask" Game script to return the Player reference again)
	If Self.GetReference() == PlayerRef										; Player is the reference filled into this RefAlias
		If akBaseObject == Equipped && akBaseObject.HasKeywordInFormList(EquippedWeapon) == true		; akBaseObject of the event OnItemEquipped is the weapon you're looking for AND this akBaseObject has any of the keywords found in the FormList "EquippedWeapon" (Form script function: HasKeywordInFormList)
			PlayerRef.UnequipItem(akBaseObject)				; then unequip this item
		EndIf
	EndIf
EndEvent

Notes:

  - the function UnequipItem has a parameter "abPreventEquip", if you intend to set it to True, be careful with it

  - you can replace akBaseObject.HasKeywordInFormList(EquippedWeapon) with akBaseObject.HasKeyword(Tier_Lvl) if you don't want to use a FormList (i.e. you only have one keyword to check)

  - both HasKeywordInFormList and HasKeyword work on BaseForm level, not on the object instance level (so you can check what keywords the Weapon form you see in the Creation Kit has with them but if you attach an ObjectMod to an item ("object instance") and that ObjectMod has dn_HasMaterial_0 [KYWD:00182E73] for example, this keyword won't be seen by HasKeywordInFormList or HasKeyword because it's not "form keyword data" but "item instance data").

Edited by LarannKiar
Link to comment
Share on other sites

1 hour ago, LarannKiar said:

It's been a while since I made something like this but if I'm remembering right, the keyword "playerCannotEquip [KYWD:001CF299]" needs to be added to the item to make it non-equippable.

Here's its dev notes: "For items which we want to appear as lootable, but not usable by the player.  (ie: creature armors, other things for which "unplayable" is not quite right)"

("Playable" is an equippable Form data flag (e.g. Weapon) which, if unchecked, can also prevent the player from equipping the item).

A Perk with Perk Entry "Activate" can't be used to block equipping a weapon found in the game world. (Maybe it can be used to block taking it with Target Condition: HasKeyword 'playerCannotEquip' == 0, I'm not sure right right, but it surely doesn't make it unequippable).

You can't add keywords to non-persistent items directly if they're already in the inventory because vanilla Papyrus doesn't provide any function for this. If there's only instance of this item in the inventory, you can use AttachModToInventoryItem. (Just add the relevant Property Modifier to the ObjectMod to attach a keyword to the item; see mod_armor_Synth_Leg_Material_0 "Standard" [OMOD:00046D9C] and its dn_HasMaterial_0 [KYWD:00182E73] keyword for example).

If you want to instantly Unequip the item to prevent it from staying equipped, then here's a quick code that should work or at least point you to the right direction:

Scriptname Tier_PerkRestrictions extends ReferenceAlias

Group Keywords
	Keyword Property Tier_Lvl Auto Const
EndGroup

FormList Property EquippedWeapon Auto Const
Weapon Property Equipped Auto Const


Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)			; event sent when the reference filled into the RefAlias this script is attached to equips something
	Actor PlayerRef = Game.GetPlayer()										; store Player variable to be used later in this event to prevent calling Game.GetPlayer() again (to speed up script execution; i.e. no need to "ask" Game script to return the Player reference again)
	If Self.GetReference() == PlayerRef										; Player is the reference filled into this RefAlias
		If akBaseObject == Equipped && akBaseObject.HasKeywordInFormList(EquippedWeapon) == true		; akBaseObject of the event OnItemEquipped is the weapon you're looking for AND this akBaseObject has any of the keywords found in the FormList "EquippedWeapon" (Form script function: HasKeywordInFormList)
			PlayerRef.UnequipItem(akBaseObject)				; then unequip this item
		EndIf
	EndIf
EndEvent

Notes:

  - the function UnequipItem has a parameter "abPreventEquip", if you intend to set it to True, be careful with it

  - you can replace akBaseObject.HasKeywordInFormList(EquippedWeapon) with akBaseObject.HasKeyword(Tier_Lvl) if you don't want to use a FormList (i.e. you only have one keyword to check)

  - both HasKeywordInFormList and HasKeyword work on BaseForm level, not on the object instance level (so you can check what keywords the Weapon form you see in the Creation Kit has with them but if you attach an ObjectMod to an item ("object instance") and that ObjectMod has dn_HasMaterial_0 [KYWD:00182E73] for example, this keyword won't be seen by HasKeywordInFormList or HasKeyword because it's not "form keyword data" but "item instance data").

Thank you for this, I was getting hard tunnel vision. The FormList was a way to see if I can get it to work, but ultimately for what I am doing Keywords is the best way to do it. I already have a way to insert the keyword thankfully. This effect is only suppose to be temporary and go away with the removal of the perk under certain conditions. Going to work this in and see if it works

Link to comment
Share on other sites

  • Recently Browsing   0 members

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