paulatreides0 Posted August 17, 2016 Share Posted August 17, 2016 My script isn't applying consistently. Or at least, it's inconsistent to how it was working before. The purpose of the script is to detect if heavy weapons are equipped, and then does some stuff. For reference, here's the current script, it is attached to a script-archetype magiceffect applied to an ability-type spell applied to the humanrace record: Scriptname RestrictionFunctions:HeavyWeaponryRestriction extends activemagiceffect Keyword Property HeavyRangedWeapon Auto Const Keyword Property HeavyMeleeWeapon Auto Const Message Property CantEquipWearPA Auto Const Message Property EquipWithLargeMaluses Auto Const Message Property EquipWithSmallMaluses Auto Const Keyword Property isPowerArmorFrame Auto Const ActorValue Property Strength Auto Const Perk Property BigLeagues01 Auto Const Perk Property BigLeagues02 Auto Const Perk Property BigLeagues03 Auto Const Perk Property HeavyGunner01 Auto Const Perk Property HeavyGunner02 Auto Const Perk Property HeavyGunner03 Auto Const Perk Property StrongBack01 Auto Const Perk Property StrongBack02 Auto Const Perk Property StrongBack03 Auto Const Actor this_actor Form this_weapon Event OnEffectStart(Actor akTarget, Actor akCaster) this_actor = akTarget endEvent Event OnItemEquipped(Form akBaseObject, ObjectReference akReference) this_weapon = akBaseObject If (this_actor != none) If (this_weapon.HasKeyword(HeavyRangedWeapon) == True && this_actor.IsInPowerArmor() == False) If (this_actor.HasPerk(StrongBack01) == False || this_actor.HasPerk(HeavyGunner01) == False || this_actor.GetBaseValue(Strength) < 8) this_actor.UnequipItem(this_weapon, True, True) If this_actor == Game.GetPlayer() CantEquipWearPA.Show() endIf If this_actor != Game.GetPlayer() this_actor.RemoveItem(this_weapon) RegisterForRemoteEvent(this_actor, "OnDeath") endIf endIf ElseIf (this_weapon.HasKeyword(HeavyMeleeWeapon) == True && this_actor.IsInPowerArmor() == False) If (this_actor.HasPerk(StrongBack01) == False || this_actor.HasPerk(BigLeagues01) == False || this_actor.GetBaseValue(Strength) < 8) this_actor.UnequipItem(this_weapon, True, True) If this_actor == Game.GetPlayer() CantEquipWearPA.Show() endIf If this_actor != Game.GetPlayer() this_actor.RemoveItem(this_weapon) RegisterForRemoteEvent(this_actor, "OnDeath") endIf endIf endIf endif endEvent Event OnItemUnequipped(Form akBaseObject, ObjectReference akReference) If (this_actor != none) If akBaseObject.HasKeyword(isPowerArmorFrame) == True If this_actor.GetEquippedWeapon().HasKeyword(HeavyRangedWeapon) If (this_actor.HasPerk(StrongBack01) == False || this_actor.HasPerk(HeavyGunner01) == False || this_actor.GetBaseValue(Strength) < 8) this_actor.UnequipItem(this_actor.GetEquippedWeapon(), True, True) If this_actor == Game.GetPlayer() CantEquipWearPA.Show() endIf endIf ElseIf this_actor.GetEquippedWeapon().HasKeyword(HeavyMeleeWeapon) If (this_actor.HasPerk(StrongBack01) == False || this_actor.HasPerk(BigLeagues01) == False || this_actor.GetBaseValue(Strength) < 8) this_actor.UnequipItem(this_actor.GetEquippedWeapon(), True, True) If this_actor == Game.GetPlayer() CantEquipWearPA.Show() endIf endIf endIf endIf endIf endEvent The script seems to work fine, except for people who begin with the weapon in their inventory. For example, Ack-Ack in the satellite station or any of the flamer guys at Saugus. They will be able to keep their weapons equipped in opposition to the script, but after you kill them all other actors will behave consistently and follow the script. Now, the reason that this is mysterious is because I used to have another script that did the similar thing. This script was attached directly to weapons and was as follows: 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 Weapon Property this_gun 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.GetBaseObject()) RegisterForRemoteEvent(akActor, "OnDeath") endIf endIf endIf 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 But this script did remove the weapons from people like Ack-Ack and the flamer guys. Any idea why this seeming inconsistency is there? Afterall, both the "OnEquipped" and the "OnItemEquipped" fire on an item being an equipped, no? So why is this [seeming] inconsistency there? Link to comment Share on other sites More sharing options...
Reneer Posted August 17, 2016 Share Posted August 17, 2016 (edited) The problem is that the weapon is already equipped on those actors before your magic effect has a chance to run on them. What you will want to do is something like this with your OnEffectStart:Event OnEffectStart(Actor akTarget, Actor akCaster) this_actor = akTarget if (this_actor.GetEquippedWeapon() != none) this_actor.UnequipItem(this_actor.GetEquippedWeapon()) Utility.Wait(1.0) this_actor.EquipItem(this_actor.GetEquippedWeapon()) endif endEventAll that really does is just cycle the weapon in and out so your script can then check to see if the weapon meets the requirements. Edited August 17, 2016 by Reneer Link to comment Share on other sites More sharing options...
paulatreides0 Posted August 17, 2016 Author Share Posted August 17, 2016 (edited) The problem is that the weapon is already equipped on those actors before your magic effect has a chance to run on them. What you will want to do is something like this with your OnEffectStart: Event OnEffectStart(Actor akTarget, Actor akCaster) this_actor = akTarget if (this_actor.GetEquippedWeapon() != none) this_actor.UnequipItem(this_actor.GetEquippedWeapon()) Utility.Wait(1.0) this_actor.EquipItem(this_actor.GetEquippedWeapon()) endif endEventAll that really does is just cycle the weapon in and out so your script can then check to see if the weapon meets the requirements. Ahh, thanks, I was presuming that was happening. Thanks for the solution! But what was really puzzling me was why it was working back when I had an "OnEquipped" event on the weapons, as opposed to know when it's an "OnItemEquipped" event on the race record. Also, a quick question: this_actor.GetEquippedWeapon() is none when you are running the equip function, no? After all, we unequip the actor earlier, so he would have nothing equipped. Or am I getting something wrong here? Edited August 17, 2016 by paulatreides0 Link to comment Share on other sites More sharing options...
TummaSuklaa Posted August 17, 2016 Share Posted August 17, 2016 Hmm yeah, the weapon would first have to be stored to a variable(I think), otherwise it will error when EquipItem is called; Log complaining about can't call it on a none object. Link to comment Share on other sites More sharing options...
Reneer Posted August 17, 2016 Share Posted August 17, 2016 (edited) Also, a quick question: this_actor.GetEquippedWeapon() is none when you are running the equip function, no? After all, we unequip the actor earlier, so he would have nothing equipped. Or am I getting something wrong here?You're absolutely right. Here is the fixed code:Event OnEffectStart(Actor akTarget, Actor akCaster) this_actor = akTarget if (this_actor.GetEquippedWeapon() != none) Weapon equippedweapon = this_actor.GetEquippedWeapon() this_actor.UnequipItem(equippedweapon) Utility.Wait(1.0) this_actor.EquipItem(equippedweapon) endif endEvent Edited August 17, 2016 by Reneer Link to comment Share on other sites More sharing options...
paulatreides0 Posted August 17, 2016 Author Share Posted August 17, 2016 Also, a quick question: this_actor.GetEquippedWeapon() is none when you are running the equip function, no? After all, we unequip the actor earlier, so he would have nothing equipped. Or am I getting something wrong here?You're absolutely right. Here is the fixed code: Event OnEffectStart(Actor akTarget, Actor akCaster) this_actor = akTarget if (this_actor.GetEquippedWeapon() != none) Weapon equippedweapon = this_actor.GetEquippedWeapon() this_actor.UnequipItem(equippedweapon) Utility.Wait(1.0) this_actor.EquipItem(equippedweapon) endif endEvent Ahh, okay. Thank you for letting me know! I was confused for a moment. Link to comment Share on other sites More sharing options...
Recommended Posts