Jump to content

How to check if player is in combat


Xander9009

Recommended Posts

There was a thread a long time ago about this here. They started the thread by saying that "GetCombatState()" doesn't work on the player. But I just found it used in the vampire script (the one that turns you into a vampire attached to the disease). I tested it in a different place to notify me if the player is or is not in combat and it appeared to work perfectly. Can anyone confirm that this is the proper way to test for player combat or point out it causes problems in certain situations?

Link to comment
Share on other sites

Ok, thanks. I'll be using GetCombatState() for this one then, since it's actually -supposed- to be on a magic effect. I wonder why it wasn't working for them. Oh well. It's good to know IsInCombat() also works. They said that was also not working. Looks like they were just having bad luck all around. I just wanted to ask because when I googled the question looking for an answer, that was was the only thing I found.

Link to comment
Share on other sites

I know that feeling, most of the time rather than asking I just Google a question until I find someone else asking how to get a certain function working and figure it out from there, because a lot of times they'll just go "Oh, got it working, thanks!" or "Nevermind, figured it out" and provide absolutely no detail on what they did.

 

That being said, this is an example of where I use IsInCombat(), it's a script for portable crafting so I prevent the user from using it in situations where forging is unreasonable or causes animation breaks:

Scriptname MiscCraftingItemScript extends ObjectReference

MiscObject Property MiscCraftingItem Auto
ObjectReference Property MiscCraftingItemREF Auto

Event OnEquipped(Actor akActor)
    If (akActor == Game.GetPlayer())
        If (akActor.IsInCombat())
            debug.notification("You cannot use this item while in combat.")
        ElseIf (akActor.IsSneaking())
            debug.notification("You cannot use this item while sneaking.")
        ElseIf (akActor.IsSwimming())
            debug.notification("You cannot use this item while swimming.")
        ElseIf (akActor.GetAnimationVariableBool("bInJumpState"))
            debug.notification("You cannot use this item while falling.")
        ElseIf (akActor.IsOnMount())
            debug.notification("You cannot use this item while mounted.")
        ElseIf (akActor.GetSitState() == 3)
            debug.notification("You cannot use this item while sitting.")
        Else
            Game.DisablePlayerControls(false, false, false, false, false, true, false)
            utility.wait(0.1)
            Game.EnablePlayerControls(false, false, false, false, false, true, false)
            MiscCraftingItemREF.Activate(akActor)
        EndIf
    EndIf
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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