Jump to content

Papyrus - Weapon script not working


Recommended Posts

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

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

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 by TheRizzler1
Link to comment
Share on other sites

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

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 by TheRizzler1
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

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