paulatreides0 Posted August 5, 2016 Share Posted August 5, 2016 (edited) So, in my long quest to try to make it so that an item is dynamically unequipped outside of PA, I've tried many things. First I tried forcing them to unequip the item. This didn't work because they would just keep unequipping it. Then I tried setting the "can't equip" setting on UnequipItem() to "True" as follows: Event OnEquipped(Actor AkActor) If (Self.HasKeyword(HeavyRangedWeapon) == True && akActor.IsInPowerArmor() == false) If (akActor.HasPerk(StrongBack1) == false || akActor.HasPerk(HeavyGunner1) == false || akActor.GetBaseValue(Strength) < 8) akActor.UnequipItem(Self.GetBaseObject(), True, True) CantEquipWearPA.Show() endIf endIf endEvent And that didn't work either. They would just keep trying to re-equip it and because there was some slight delay between it being equipped and unequipped, they could get a few shots off. I don't know why it doesn't work - they shouldn't even be able to try to re-equip the thing! (An explanation would be greatly appreciated). So then I decided to try something different: remove the item entirely, and add it back on the death of the NPC. So I did this (whole script ahead): Scriptname RestrictionFunctions:HeavyRangedWeaponry extends ObjectReference Const Message Property CantEquipWearPA Auto Const Perk Property HeavyGunner1 Auto Const Perk Property StrongBack1 Auto Const Keyword Property isPowerArmorFrame Auto Const Keyword Property HeavyRangedWeapon Auto Const ActorValue Property Strength Auto Const Event OnInit() RegisterForRemoteEvent(Game.GetPlayer(), "OnItemUnequipped") ; Register for player unequipping item, in this case Power Armor EndEvent Event OnEquipped(Actor AkActor) If (Self.HasKeyword(HeavyRangedWeapon) == True && akActor.IsInPowerArmor() == false) If (akActor.HasPerk(StrongBack1) == false || akActor.HasPerk(HeavyGunner1) == false || akActor.GetBaseValue(Strength) < 8) akActor.UnequipItem(Self.GetBaseObject(), True, True) CantEquipWearPA.Show() If akActor != Game.GetPlayer() akActor.RemoveItem(Self) RegisterForRemoteEvent(akActor, "OnDeath") endIf endIf endIf endEvent Event Actor.OnDeath(Actor akSender, Actor akKiller) akSender.AddItem(Self.GetBaseObject()) endEvent Event Actor.OnItemUnequipped(Actor akSender, Form akBaseObject, ObjectReference akReference) If akBaseObject.HasKeyword(isPowerArmorFrame) == True ; Check if the player did unequip Power Armor If akSender.GetEquippedWeapon().HasKeyword(HeavyRangedWeapon) If (akSender.HasPerk(StrongBack1) == false || akSender.HasPerk(HeavyGunner1) == false || akSender.GetBaseValue(Strength) < 8) akSender.UnequipItem(akSender.GetEquippedWeapon(), True, True) CantEquipWearPA.Show() endIf endIf endIf EndEvent And...it kinda worked. They finally didn't have the weapon around anymore...but when they died the weapon didn't get re-added to their inventory. What is going wrong here? Also, if you guys don't mind a bonus question: at the bottom is a bit of script to prevent the equipment of equipment outside of power armor when you exit it. Because of the OnInit() thing it only applies to the player right now, and I can't think of how to extend it to all human-type actors. Because I can't just state a generic actor, it's a bit of a problem. Any idea how that can be resolved? Edited August 5, 2016 by paulatreides0 Link to comment Share on other sites More sharing options...
Reneer Posted August 5, 2016 Share Posted August 5, 2016 The main problem is that your script is attached to the ObjectReference - the gun - that is in your actor's inventory. When you tell the actor to remove the gun that the script is attached to, well, the script no longer functions because the object no longer exists. The best solution to your problem, I think, is to create a Quest script that finds nearby Actors using FindRandomActor and gives them an Ability or Perk. The script on the Ability then does what your script does now, except as an Ability it won't be nullified when you remove the weapon from the Actor. The above method would also allow you to give the Perk / Ability to the player, making sure that they can't use those weapons either. You would also need to make a Formlist of the Weapons you want to restrict so that the Ability script can know if the actor has one of those weapons equipped / in their inventory. Link to comment Share on other sites More sharing options...
steve40 Posted August 5, 2016 Share Posted August 5, 2016 Like Reneer said, "akActor.RemoveItem(Self)" will delete the weapon and it won't subsequently register for OnDeath. Secondly, isn't PA a furniture not an armor? So checking OnItemUnequipped for power armor probably won't work...? Link to comment Share on other sites More sharing options...
paulatreides0 Posted August 5, 2016 Author Share Posted August 5, 2016 (edited) Like Reneer said, "akActor.RemoveItem(Self)" will delete the weapon and it won't subsequently register for OnDeath. Secondly, isn't PA a furniture not an armor? So checking OnItemUnequipped for power armor probably won't work...? Actually, that part does work. Tested it and everything. It's a modified version of a companion affinity script. Unfortunately, I can only get it to apply to the player character, which is a bit of a pain, as it means that if you shoot the core out of an NPC's PA and they get out, then they will be able to wield the weapon despite their not being able to normally. The main problem is that your script is attached to the ObjectReference - the gun - that is in your actor's inventory. When you tell the actor to remove the gun that the script is attached to, well, the script no longer functions because the object no longer exists. Is there any way of "saving" the object for later referrence? Like, for example, assigning it to some variable? I tried finding out how to do so but couldn't find out a way of doing so. If I could say at the beginning: this_gun = self, that would resolve the problem, no? I just don't know how to do that with papyrus. Ideally this could be resolved with the "abPreventEquip" parameter of the UnequipItem function, but every time I try that they just go and equip it again. That's why I am trying to do the roundabout way of deleting the item. Would you happen to know the reason why abpreventequip isn't working?? The best solution to your problem, I think, is to create a Quest script that finds nearby Actors using FindRandomActor and gives them an Ability or Perk. The script on the Ability then does what your script does now, except as an Ability it won't be nullified when you remove the weapon from the Actor. The above method would also allow you to give the Perk / Ability to the player, making sure that they can't use those weapons either. You would also need to make a Formlist of the Weapons you want to restrict so that the Ability script can know if the actor has one of those weapons equipped / in their inventory. Thank you for the suggestion. I have a question about that method though - how would I iterate through the actors in the location? I'm not sure of how I could say "while actors in cell don't have perk A" in Papyrus. Edited August 5, 2016 by paulatreides0 Link to comment Share on other sites More sharing options...
registrator2000 Posted August 7, 2016 Share Posted August 7, 2016 You can consider using a cloak magic effect to attach a spell to nearby actors (a technique that's been established for a while in Skyrim - you will be able to find a lot more documentation if you do a search with skyrim in your list of keywords. Fallout 4 works mostly in the same way regarding scripting. Here's the Skyrim CK page for dynamically attaching scripts.) The Pain Train perk uses a cloak-archetype magic effect to apply stagger and is a vanilla example of how Bethesda implemented a cloak MGEF in Fallout 4. Link to comment Share on other sites More sharing options...
Recommended Posts