Has anyone successfully used IsSneaking() ?

Post » Mon Jun 18, 2012 1:30 pm

So I actually have a couple of questions, but I'll start with the topic first. I can get the following conditional to work as expected:

If (Game.GetPlayer().IsWeaponDrawn() == 1)  ;Do SomthingElse  ;Do Something ElseEndIf

The following, however, does not:

If (Game.GetPlayer().IsSneaking() == 1)  ;Do SomthingElse  ;Do Something ElseEndIf

I mostly wanted to know if someone else has actually got this working or if I'm really just going insane :smile:

My second question involves ObjectReference Properties. I've got the following line of code in the script:

ObjectReference Property HorseChest Auto

I've gone into the existing stables quest and assigned a chest reference to the property in the existing SolitudeHorse under Quest Aliases by selecting the existing script in the Papyrus Scripts list and asigning the property. It seems like it should work properly and that's where the other objects are defined, but the reference comes up null in the script itself at runtime. I tried buying a new horse, but that didn't work either. Do I need to make an Alias for the Chest Reference instead? I'm a little lost here.
User avatar
luke trodden
 
Posts: 3445
Joined: Sun Jun 24, 2007 12:48 am

Post » Mon Jun 18, 2012 11:00 am

Ya i have used in my mod called Arcane Assassin and Thief, I made a quest that would run and detect in the background if the player was sneaking using OnUpdate

I had it as a quest so i could have it continuously run in the background so i didnt have to attach any scripts to other objects, because my purpose was just to do a simple detection and apply a Ghost Shader in my mod

Scriptname QST_IsSneakingExample extends Quest  ConditionalEvent OnInit()RegisterForUpdate(1)EndEventEvent OnUpdate()if game.GetPlayer().IsSneaking()  ;do CodeendifEndEvent
User avatar
liz barnes
 
Posts: 3387
Joined: Tue Oct 31, 2006 4:10 am

Post » Mon Jun 18, 2012 1:56 pm

Your if statement is correct and should work fine, but can you post your whole code please it would make this much easier but use spoiler tags.

I have also successfully used it in my own personal bag of holding mod in which if the player dropped the bag it would replace the 'Item' object with a 'Container' the player could use it like a normal container but if they want to pick it back up they just activate it in sneak mode.
Spoiler

Scriptname BagOfHoldingContainerScript extends ObjectReference  GlobalVariable Property ThruItem AutoArmor Property BoHARMO Autoevent OnInit()  GoToState("closed")endeventstate closed  event OnBeginState()	BlockActivation(True)  endevent  event OnActivate(ObjectReference akActionRef)	if(Game.GetPlayer().IsSneaking() && ThruItem.GetValueInt() == 0)	  Game.GetPlayer().AddItem(BoHARMO)	  MoveToMyEditorLocation()	else	  BlockActivation(False)	  GoToState("open")	endif  endeventendstatestate open  event OnBeginState()	ThruItem.SetValueInt(0)	Activate(Game.GetPlayer())	Utility.Wait(0.5)	GoToState("closed")  endeventendstate
User avatar
Heather beauchamp
 
Posts: 3456
Joined: Mon Aug 13, 2007 6:05 pm

Post » Mon Jun 18, 2012 10:24 am

If you want to do something simple with .IsSneaking(), here's how I do it:

Spoiler

Scriptname _SneakingScript extends Form Conditional

Event OnInit()
RegisterForUpdate(1)
gotostate ("polling")
EndEvent

STATE polling
Event OnUpdate()

if game.getplayer().isSneaking()
;do neat stuff!
else
;do evil stuff!
endif

EndEvent

EndState

Then I attach the script to the "Player" Actor.

That's my way even if I'm a beginner and it's working.
User avatar
Tanika O'Connell
 
Posts: 3412
Joined: Fri Jan 26, 2007 1:34 am

Post » Mon Jun 18, 2012 6:23 am

So the chest issue turned out to be a problem with my CK silently and partially crashing. I found out something was up when I tried to restart Steam so it could update itself, it said it had to wait for the CK to close even though it was. After a reboot, I deleted the compiled scripts, restarted the ck and opened the mod, then compiled the script and quest. The chest reference now works just fine.

The IsSneaking() comparison, however, does not... This is on a Horse object, so I wonder if it has something to do with it... Before the reboot, I did try waiting until the eye went closed before activation, but I haven't tried that since the reboot. Will test now. EDIT: Tested. Doesn't work.

Anyway here's the full code. Most of it is Beth's code at this point, I've just added the OnActivate block and the one property:

Spoiler
Scriptname PlayerHorseScript extends ReferenceAlias  Event OnDeath(Actor akKiller)    MySelf = GetActorReference()EndEventEvent OnUnload()    If MySelf.IsDead() == 1        ; disable the dead horse if it is unloaded        MySelf.Disable()        MySelf.Delete()        ; added a new horse that can be bought at the stables        Myself = StablesPosition.PlaceActorAtMe(LvlHorseSaddled)        Alias_HorseRef.ForceRefTo(MySelf)        Alias_HorseRef.GetRef().SetFactionOwner(StablesFaction)    EndIfEndEventEvent OnActivate(ObjectReference akActionRef)            If (akActionRef == Game.GetPlayer())        If Game.GetPlayer().IsSneaking()            Debug.MessageBox("Sneak Activate Horse!!")            HorseChest.Activate(Game.GetPlayer(), true)                Else            Debug.MessageBox("Normal Activate Horse!! " + HorseChest)            ;HorseChest.Activate(Game.GetPlayer(), true)        EndIf            EndIfEndEventActor Property MySelf  Auto  ObjectReference Property StablesPosition  Auto  ActorBase Property LvlHorseSaddled  Auto  ReferenceAlias Property Alias_HorseRef  Auto  Faction Property StablesFaction  Auto  ObjectReference Property HorseChest Auto
User avatar
Tarka
 
Posts: 3430
Joined: Sun Jun 10, 2007 9:22 pm

Post » Mon Jun 18, 2012 11:39 am

In case things couldn't get weirder, this code works fine:

Spoiler
Scriptname PlayerHorseScript extends ReferenceAliasbool IsPlayerSneakingEvent OnDeath(Actor akKiller)MySelf = GetActorReference()EndEventEvent OnUnload()If MySelf.IsDead() == 1  ; disable the dead horse if it is unloaded  MySelf.Disable()  MySelf.Delete()  ; added a new horse that can be bought at the stables  Myself = StablesPosition.PlaceActorAtMe(LvlHorseSaddled)  Alias_HorseRef.ForceRefTo(MySelf)  Alias_HorseRef.GetRef().SetFactionOwner(StablesFaction)EndIfEndEventEvent OnActivate(ObjectReference akActionRef)If Game.GetPlayer().IsSneaking()  IsPlayerSneaking = trueElse  IsPlayerSneaking = falseEndIfIf (akActionRef == Game.GetPlayer() && IsPlayerSneaking)  Debug.MessageBox("Sneak Activate Horse!!")  HorseChest.Activate(Game.GetPlayer(), true)Else  Debug.MessageBox("Normal Activate Horse!! " + HorseChest)  ;HorseChest.Activate(Game.GetPlayer(), true)EndIfEndEventActor Property MySelf  AutoObjectReference Property StablesPosition  AutoActorBase Property LvlHorseSaddled  AutoReferenceAlias Property Alias_HorseRef  AutoFaction Property StablesFaction  AutoObjectReference Property HorseChest Auto

Okay, not so much, actually. If it's timed right (just as your feet hit the floor after dismounting), it works. Otherwise, not. It's almost like the IsSneaking function only works the moment the player goes into sneak mode.

EDIT2:

I'm thinking it's because the activation takes place a brief moment after the player starts mounting the horse and is therefore no longer actually sneaking. I'm going to take a cue from Lozzipop and use BlockActivation to see if that clears up the issue. Strange that it works for IsWeaponDrawn, though.
User avatar
Jose ordaz
 
Posts: 3552
Joined: Mon Aug 27, 2007 10:14 pm

Post » Mon Jun 18, 2012 4:05 am

Just want to make note that I've resolved the issue. The problem seems to stem from the fact that if you activate a horse in sneak mode, the game takes the player out of sneak mode to mount the horse before the OnActivate block executes. By using BlockActivation, you can properly test for the IsSneaking condition.

Ah, and thanks to everyone posting their sample code and confirming the function does work :) You both helped point me in the right direction and verify that I hadn't gone insane... at least, not quite yet.
User avatar
JaNnatul Naimah
 
Posts: 3455
Joined: Fri Jun 23, 2006 8:33 am


Return to V - Skyrim