Difference between revisions of "Talk:IsSneaking - Actor"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>MaboroshiDaikon
imported>MaboroshiDaikon
 
(4 intermediate revisions by the same user not shown)
Line 44: Line 44:
: -- [[User:Cipscis|Cipscis]] 23:11, 10 February 2012 (EST)
: -- [[User:Cipscis|Cipscis]] 23:11, 10 February 2012 (EST)


:I was originally doing the comparison just as you did, but when that didn't work, I switched to the comparison with 1. 


:I was originally using just as you did, but when that didn't work, I switched to the comparison with 1I'm wondering if this is an issue with the ReferenceAlias type script instead of the command itselfHere's the complete code I'm having issues with:
:I deleted a bunch of code and comments as I've figured out what the issue is.  In short, when activating a horse in sneak mode, the game takes the player out of sneak mode to mount the horse before the OnActivate block on the horse can run.  Using a BlockActivation(true) on the horse ahead of time will allow you to properly check the OnSneak condition of the playerAfterwards, you can unblock the activation and activate the horse with the player actor reference to get the player to mount the horse if that is the desired effectNot sure why the same doesn't apply for IsWeaponDrawn.


<source lang="papyrus">Scriptname PlayerHorseScript extends ReferenceAlias 
: -- [[User:MaboroshiDaikon|MaboroshiDaikon]] 13:21, 12 February 2012 (CST)
 
 
Event OnDeath(Actor akKiller)
MySelf = GetActorReference()
EndEvent
 
Event 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)
EndIf
EndEvent
 
Event 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
EndIf
EndEvent
 
Actor Property MySelf  Auto 
ObjectReference Property StablesPosition  Auto 
ActorBase Property LvlHorseSaddled  Auto 
ReferenceAlias Property Alias_HorseRef  Auto 
Faction Property StablesFaction  Auto 
ObjectReference Property HorseChest Auto</source>
 
Replacing IsSneaking() with IsWeaponDrawn() works.
 
:UPDATE- In case things weren't weird enough... this works just fine:
 
<source lang="papyrus">Scriptname PlayerHorseScript extends ReferenceAlias 
 
bool IsPlayerSneaking
 
Event OnDeath(Actor akKiller)
MySelf = GetActorReference()
EndEvent
 
Event 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)
EndIf
EndEvent
 
Event OnActivate(ObjectReference akActionRef)
If Game.GetPlayer().IsSneaking()
IsPlayerSneaking = true
Else
IsPlayerSneaking = false
EndIf
If (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)
EndIf
EndEvent
 
 
 
Actor Property MySelf  Auto 
 
ObjectReference Property StablesPosition  Auto 
 
ActorBase Property LvlHorseSaddled  Auto 
 
ReferenceAlias Property Alias_HorseRef  Auto 
 
Faction Property StablesFaction  Auto 
 
ObjectReference Property HorseChest Auto</source>

Latest revision as of 14:24, 12 February 2012

Syntax[edit source]

I can get the following to work as expected:

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

But the following does not:

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

Tried the following syntax and still no luck:

If (Game.GetPlayer().IsSneaking())
	;Do Something
EndIf


This script worked exactly as I expected:
Scriptname CodeTestScript extends Quest  

Event OnInit()
	RegisterForUpdate(3)
EndEvent

Event OnUpdate()

	if (Game.GetPlayer().IsSneaking())
		Debug.Notification("Player is sneaking")
	else
		Debug.Notification("Player is not sneaking")
	endif

EndEvent
As a side note, this function returns a bool, so why are you comparing it with 1? It's more semantically correct, but just as superfluous, to compare it with true
-- Cipscis 23:11, 10 February 2012 (EST)
I was originally doing the comparison just as you did, but when that didn't work, I switched to the comparison with 1.
I deleted a bunch of code and comments as I've figured out what the issue is. In short, when activating a horse in sneak mode, the game takes the player out of sneak mode to mount the horse before the OnActivate block on the horse can run. Using a BlockActivation(true) on the horse ahead of time will allow you to properly check the OnSneak condition of the player. Afterwards, you can unblock the activation and activate the horse with the player actor reference to get the player to mount the horse if that is the desired effect. Not sure why the same doesn't apply for IsWeaponDrawn.
-- MaboroshiDaikon 13:21, 12 February 2012 (CST)