TheRizzler1 Posted August 10, 2016 Share Posted August 10, 2016 A kind coder on another forum has whipped up some code for me but I can't seem to get it to work. The aim is to 'damage' the player's AP by a certain value if they fire a weapon outside of power armour. (with intentions to add a few more conditions, such as nullifying the penalty if using a certain receiver etc.) As I am and artist and only have a small amount of coding experience, I'd like to humbly request a more experienced coder's help. Here's the script; Scriptname MagnumRevolverRifleAPPenalty extends Weapon Weapon Property theGun Auto Const ActorValue Property ActionPoints Auto Const Event OnInit() Self.RegisterForAnimationEvent(Game.GetPlayer(), "weaponFire") EndEvent Event OnAnimationEvent(ObjectReference akSource, string asEventName) if((akSource as Actor).GetEquippedWeapon() == theGun && asEventName == "weaponFire") if(!(akSource as Actor).IsInPowerArmor()) (akSource as Actor).DamageValue(ActionPoints, 5) ;Maybe a GlobalVariable for customizability? endIf endIf EndEvent I guess my first question is, how do I go about properly using this in the CK? I went into my WEAP file and added the script using the scripts box in the bottom right of the window. Is this correct? The script might even be working if I could put it in the right place. Link to comment Share on other sites More sharing options...
scrivener07 Posted August 10, 2016 Share Posted August 10, 2016 Hows this work for you? Scriptname WeaponFirePenalty extends Weapon string WeaponFireAnimation = "weaponFire" Const int ValueCost = 5 Const ; Maybe a GlobalVariable for customizability? ActorValue Property ValueType Auto Const Mandatory ; you must "fill" this in the CK Event OnInit() Actor kActor = Game.GetPlayer() RegisterForRemoteEvent(kActor, "OnEquipped") RegisterForRemoteEvent(kActor, "OnUnequipped") EndEvent Event ObjectReference.OnEquipped(ObjectReference akSender, Actor akActor) self.RegisterForAnimationEvent(akSender, WeaponFireAnimation) EndEvent Event ObjectReference.OnUnequipped(ObjectReference akSender, Actor akActor) self.UnregisterForAnimationEvent(akSender, WeaponFireAnimation) EndEvent Event OnAnimationEvent(ObjectReference akSource, string asEventName) Actor kSubject = akSource as Actor If (kSubject) If !(kSubject.IsInPowerArmor()) ; not in power armor kSubject.DamageValue(ValueType, ValueCost) EndIf EndIf EndEvent its generic enough where you can specify the ActorValue type such as stamina or Health or whatever on the properties window in the CK. Link to comment Share on other sites More sharing options...
TheRizzler1 Posted August 10, 2016 Author Share Posted August 10, 2016 (edited) Doesn't seem to be working I'm afraid. Pasted it over my script in the Scripts/Source/User, went into CK and assigned ActionPoints as the value, compiled and went ingame but nothing happens when I fire the weapon. I'm guessing I am putting it in the right place though? Edited August 10, 2016 by TheRizzler1 Link to comment Share on other sites More sharing options...
scrivener07 Posted August 10, 2016 Share Posted August 10, 2016 Ive got to run to work now but maybe you could try adding smoe debug tracing to see if the functions/events are being called. Ive assumed the animation event names are correct but since I havent tested it myself it could be any numbers of mistakes I missed. Hopefully someone else can jump in and help too. Link to comment Share on other sites More sharing options...
TheRizzler1 Posted August 10, 2016 Author Share Posted August 10, 2016 (edited) Okay, thanks for helping me! I have some C# experience but none for Papyrus. Even if I figured out how to add debugging commands I wouldn't know where the log is to check them, haha edit: unless it's just the ingame console? hmm Edited August 10, 2016 by TheRizzler1 Link to comment Share on other sites More sharing options...
Elathia Posted August 10, 2016 Share Posted August 10, 2016 I would instead make a quest, no stages, etc, make the player an alias, and change the extension of that script to ReferenceAlias. Link to comment Share on other sites More sharing options...
TheRizzler1 Posted August 11, 2016 Author Share Posted August 11, 2016 Alright, I'll try and give that a shot today. Link to comment Share on other sites More sharing options...
TheRizzler1 Posted August 11, 2016 Author Share Posted August 11, 2016 Not working, not sure if I did the whole reference Alias thing right though; Data / Reference Alias / Script Link to comment Share on other sites More sharing options...
Elathia Posted August 11, 2016 Share Posted August 11, 2016 Try this code block instead(it's the "skyrim way" which is still valid for Fallout scripting in most areas). No need for equip events, unless you're wanting to recieve animation events from a specific weapon. Then states would be needed, because UnEquipped still might fire before OnEquipped. Event OnInit() RegisterForAnimationEvent((GetReference() as Actor), WeaponFireAnimation) EndEvent Event OnAnimationEvent(ObjectReference akSender, String asEventName) Actor kSubject = GetReference() as Actor if !(kSubject.isInPowerArmor()) ; Should exit if player is in power armor if akSender == kSubject && asEventName == WeaponFireAnimation ; if the expression on the left is false, function exits. kSubject.DamageValue(ValueType, ValueCost) endif endif EndEvent As you're wanting this to run all the time, no need to unregister for it either, though you can to be on the safe side. Link to comment Share on other sites More sharing options...
TheRizzler1 Posted August 11, 2016 Author Share Posted August 11, 2016 Doesn't seem to work again, I fear the code is fine and I'm not setting it up correctly though, have you tested it? I tried both adding the script directly to my weapon and added it to a quest with no luck. Link to comment Share on other sites More sharing options...
Recommended Posts