Jump to content

Sprint disable script help (FO4 CK)


Genamine

Recommended Posts

Scriptname ARMA_DisableSprintEffectScript extends ActiveMagicEffect

Group Settings
	bool Property DisableSprinting auto
	bool Property DisableRunning auto
	actorvalue Property CountObject auto
	actor Property EffectOwner auto
EndGroup

InputEnableLayer inputLayer

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Utility.Wait(1) ;lets not run a count check before the count is actually raised
	float fCount = akTarget.GetValue(CountObject)
	EffectOwner = akTarget
	if fCount > 4
		inputLayer = InputEnableLayer.Create()
		if DisableRunning
			inputLayer.EnableRunning(false)
			inputLayer.EnableSprinting(false)
		elseif DisableSprinting
			inputLayer.EnableSprinting(false)
		endif
	endif
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	inputLayer.Delete()
	inputLayer = None
	float fCount = 0
EndEvent

Event OnItemUnequipped(Form akBaseObject, ObjectReference akReference)
	if akBaseObject as Armor
		Utility.Wait(1) ;once more, we dont want to run a count check before the count is actually lowered
		if EffectOwner ;this event shouldnt happen without the first event having taken place, but nonetheless, lets check if we actually have an actor reference
			float fCount = EffectOwner.GetValue(CountObject)
			if fCount < 5
				inputLayer.EnableSprinting(true)
				inputLayer.EnableRunning(true)
				Dispel()
			endif
		endif
	endif
EndEvent

Based on that new information, how does this look? (it compiled, so Ill be giving it a shot ingame)

I added the wait calls because previously.. it was checking the counts before the count was actually raised or lowered, I also clarified this in the script

 

EDIT: It works, flawlessly .. thanks for the advice!

Link to comment
Share on other sites

I'm thinking that may not always work. So if you run into consistency issues, keep these notes on OnEffectFinish in mind:

 

  • By the time this event is called, the active magic effect may have already been deleted by the game. Any native calls to this active magic effect may fail.
  • Also, since the game forcibly deletes ActiveMagicEffects, if the script has a circular reference to itself (via a local variable - either directly or via a struct/array) that circular reference will be forcibly cleared by the Papyrus garbage collector, resulting in the value receiving a None value.
Link to comment
Share on other sites

Should that technically not matter?, the only thing you need when the effect finishes is to enable running/sprinting again, which it does

 

From what Ive gathered, the script is run from scratch when removing and re-adding the magiceffect

Meaning you dont technically need to do anything other than re-enabling running/sprinting in OnEffectFinish (which is precisely what it does)

 

If you are referring to float fCount, thats not a variable controlled by the magiceffect script

fCount only retrieves the value of an actor value that keeps track of the amount of equipped pieces of heavy armour, the value of this actor value is controlled elsewhere

Link to comment
Share on other sites

You can delete the line "float fCount = 0" as it serves no purpose whatsoever. It does not affect the other 'fCount' variables that were declared within different events, they are completely isolated from each other. Doing so would only work if the variable was declared at the top of the script (script-wide). The variable will cease to exist as soon as the magic effect expires, so declaring it within OnEffectFinish is pointless.

Edited by steve40
Link to comment
Share on other sites

  • Recently Browsing   0 members

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