Jump to content

Trouble with equipped items


213410

Recommended Posts

Hello!
Recently I started to make a script that would prevent player from running (don't ask why, it's complicated:happy:). The idea was to force player walking by making running impossible via "pushactoraway" - when player wants to run, game will throw him/her on ground. This effect should be attached to ebony boots (for example), so when player equips it, the effect is added until unequipped. This is the code I have currently made:

Scriptname EbonyBootsWalk extends ObjectReference

Actor Property PlayerREF Auto
Armor Property EbonyBoots Auto

Event OnEquipped(Actor akActor)
	if akActor == Game.GetPlayer()
		if (PlayerREF.IsEquipped(EbonyBoots) == 1) && (PlayerREF.IsRunning() == True)
				Debug.Notification("No")
				PlayerREF.PushActorAway(PlayerREF, 0.1)
		endif
	endif
EndEvent

It is not working at all and I don't know why. Need some help, please. Thank You.

Link to comment
Share on other sites

Just some advice on cleaning that script up a bit.

First, You have already gotten a PlayerRef property, so there is no need to call Game.GetPlayer() in your script:

if akActor == Game.GetPlayer()

Can instead just use:

if akActor == PlayerRef

Secondly, when you are checking the return value of a boolean, you dont need to use == 1 if you are just checking it is true.

So:

if (PlayerREF.IsEquipped(EbonyBoots) == 1) && (PlayerREF.IsRunning() == True)

Would be better written as:

if (PlayerREF.IsEquipped(EbonyBoots)) && (PlayerREF.IsRunning())    

;I also don't think they need to be filly encapsulated in parenthesis but it doesn't hurt.

Similarly, if you were checking that a boolean was false you can use the NOT operator, in Papyrus it is a !
so to check that the player IS NOT running:

if !PlayerRef.IsRunning()

That said, what was the issue and what was the solution? Just for curiosities sake?

Link to comment
Share on other sites

That said, what was the issue and what was the solution? Just for curiosities sake?

 

Thank you for advices, I will use them in future.

 

The problem was actually split in two halves:

(1) There was two scripts in one boots and they didn't work together. So I integrated one to another (this one into bigger script).

(2) Second script used RegisterForSingleUpdate() and worked only on update, so I needed to make first script work on update too.

 

I omitted entire code (it is very big), the result of added first script looks like this:

Event OnUpdate()
  Actor akActor = GetTargetActor();
  If akActor.IsRunning() || akActor.IsSprinting()
        Debug.Notification("No")
        akActor.PushActorAway(akActor, 0)
        Utility.Wait(7)
    endif
    RegisterForSingleUpdate(0.1);
endEvent

Utility.Wait() was added for character to stand up after falling, otherwise there will be endless loop of PushActorAway().

Link to comment
Share on other sites

  • Recently Browsing   0 members

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