Jump to content

First Time Scripting Help


Recommended Posts

So what Im trying to do is simple in theory but idk the difficulty in Papyrus. I may be over my head with this.

Goal: First shot of rifle is normal, second shot fires an explosive shot

 

Scriptname CoolShotRifleScript extends ObjectReference Const

Function CoolShotRifle.AttachMod(mod_Lengendary_Weapon_ExplosiveBullets, 1) 
EndFunction

Function RegisterForAnimationEvent(ObjectReference Game.GetPlayer(), "WPNFireSingleReady")
EndFunction

Event OnAnimationEvent(ObjectReference Game.GetPlayer(), "WPNFireSingleReady")
    if (Game.GetPlayer() = self) && ("WPNFireSingleReady" = True)
        AttachMod
    endIf
endEvent

 

 

Papyrus is extremely confusing. I try to compile but I keep getting an error lol. 

 

 

Link to comment
Share on other sites

You could try this code:

Scriptname CoolShotRifleScript extends ObjectReference Const		; if it extends ObjectReference, you either need to attach this script to the reference (since PlayerRef 0x14 is hardcoded it's not really an option) or the reference's base form (in which case all object references of this base would inherit this script)


Event OnInit()				; sent when this script is initialized
	; RegisterForAnimationEvent is a native function so it looks like "bool Function RegisterForAnimationEvent(ObjectReference akSender, string asEventName) native" in ScriptObject.psc; it doesn't have "EndFunction" as it's native: it's only declared in ScriptObject.psc while being defined in the native code
	; "Self" is technically this script instance, so an instance of CoolShotRifleScript bound to the object the script is attached to: in this case it is an ObjectReference; the vanilla code automatically casts it to ObjectReference, that's why you don't need to type "Self as ObjectReference" (the first parameter of RegisterForAnimationEvent is ObjectReference)
	RegisterForAnimationEvent(Self, "weaponFire")
EndEvent

Function AttachModFunction()		; you could call it "user defined function"
	Debug.Notification("AttachModFunction called.")
EndFunction

Event OnAnimationEvent(ObjectReference akSource, string asEventName)		; parameters don't contain the value like Game.GetPlayer() but the type and name, e.g. ObjectReference akSource
	If akSource == Game.GetPlayer() && asEventName == "weaponFire"			; the anim event is called "weaponFire" as far as I remember
		AttachModFunction()
	EndIf
EndEvent

The notes above the native functions and events in the vanilla .psc (Papyrus script source) files aren't always in depth descriptions so you should take a look at the Creation Kit wiki.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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