Difference between revisions of "User:PROXiCiDE/GetSleepStateEx"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>PROXiCiDE
imported>PROXiCiDE
 
Line 1: Line 1:
Adds or Removes items from the player inventory / spell list.
 
Extended version of GetSleepState. Helpful detecting if a actor is sleeping in a interior while the player is in a exterior due to the limitation of GetSleepState. If the actor and player are both in the same location it will return the normal GetSleepState values.


== Syntax ==
== Syntax ==
<source lang="papyrus">
<source lang="papyrus">
Function AddItemsToPlayerFromForm(FormList pList, Bool bRemove = False)
Int Function GetSleepStateEx(Actor akActor,Package akSleepPackage = None,Location akLocation = None)
</source>
</source>


== Parameters ==
== Parameters ==
*pList: The form list containing Spells / Ammo / Weapon.
*akActor: The actor to detect if they are sleeping.
*bRemove : Items from the FormList will be removed instead of added to the player.
*akSleepPackage: AI Package that contains the Sleep information.
**'''Default''': False
**'''Default''': None
*akLocation : Compare the location of the Actor.
**'''Default''': None


== Return Value ==
== Return Value ==
None
The actor's current sleep state.
 
*5 Dead, sleeping with the fishes?
*6 Actor has the sleep package
*7 Actor has the sleep package and the confirmed location
 
Following is returned if the actor is waking up or the package has changed during
*16 Sleep package has ended / expired
*17 Sleep package has ended / expired, actor still remains in the location
 
Error Codes
*-1 Invalid Actor


== Example ==
== Example ==
<source lang="papyrus">
<source lang="papyrus">
FormList Property _PX_DebugSpellList Auto
Int nSleepResults = GetSleepStateEx(akBalimund,pRiftenBalimundSleep0x6,pRiftenBlacksmithLocation)
Event OnInit()
 
;Debug
;Check for both normal value of GetSleepState incase the player is same location as Actor
AddItemsToPlayerFromForm(_PX_DebugSpellList)
;else lets check for Dead or the Sleep Package
EndEvent
If nSleepResults == 3 || nSleepResults == 5 || nSleepResults == 7
Debug.Trace("Actor is sleeping")
EndIf
</source>
</source>


== Script ==
== Script ==
<source lang="papyrus">
<source lang="papyrus">
Function AddItemsToPlayerFromForm(FormList pList, Bool bRemove = False)
Int Function GetSleepStateEx(Actor akActor,Package akSleepPackage = None,Location akLocation = None)
If pList == None
Int iResults = -1
Return
If akActor == None
Return iResults
EndIf
EndIf
Actor pPlayer = Game.GetPlayer()
If akActor.IsDead()
Ammo pAmmo = None
iResults = 5
Weapon pWeapon = None
Else
Spell pSpell = None
Bool bValidate = False
Int Size = pList.GetSize()
;Detect normal sleep state
While Size > 0
If akActor.GetCurrentLocation().IsSameLocation(Game.GetPlayer().GetCurrentLocation())
Size -= 1
Return akActor.GetSleepState()
Form fmItem = pList.GetAt(Size)
Else
If fmItem As Spell
;Extended sleep detection
pSpell = fmItem As Spell
If akLocation == None && akSleepPackage != None
If bRemove
If akActor.GetCurrentPackage() == akSleepPackage
pPlayer.RemoveSpell(pSpell)
bValidate = True
Else
iResults = 6
pPlayer.AddSpell(pSpell)
EndIf
EndIf
EndIf
ElseIf fmItem As Ammo
pAmmo = fmItem As Ammo
If akLocation != None && akSleepPackage != None
If bRemove
If akActor.GetCurrentPackage() == akSleepPackage && akActor.GetCurrentLocation() == akLocation
pPlayer.RemoveItem(fmItem, 100)
bValidate = True
Else
iResults = 7
pPlayer.AddItem(fmItem, 100)
EndIf
EndIf
EndIf
ElseIf fmItem As Weapon
pWeapon = fmItem As Weapon
If bValidate
If bRemove
;Lets check incase the schedule for the package has expired
pPlayer.RemoveItem(fmItem, 1)
akActor.EvaluatePackage()
Else
If akActor.GetCurrentPackage() != akSleepPackage
pPlayer.AddItem(fmItem,1)
iResults += 10
EndIf
EndIf
EndIf
EndIf
EndIf
EndWhile
If !bRemove
pPlayer.EquipItem(pAmmo)
pPlayer.EquipItem(pWeapon)
EndIf
EndIf
Return iResults
EndFunction
EndFunction
</source>
</source>
== See Also ==
*[[Actor Script]]
*[[GetSleepState - Actor|GetSleepState]]
*[[GetSleeping]]
*[[IsPCSleeping]]

Latest revision as of 17:31, 7 February 2014

Extended version of GetSleepState. Helpful detecting if a actor is sleeping in a interior while the player is in a exterior due to the limitation of GetSleepState. If the actor and player are both in the same location it will return the normal GetSleepState values.

Syntax[edit | edit source]

Int Function GetSleepStateEx(Actor akActor,Package akSleepPackage = None,Location akLocation = None)

Parameters[edit | edit source]

  • akActor: The actor to detect if they are sleeping.
  • akSleepPackage: AI Package that contains the Sleep information.
    • Default: None
  • akLocation : Compare the location of the Actor.
    • Default: None

Return Value[edit | edit source]

The actor's current sleep state.

  • 5 Dead, sleeping with the fishes?
  • 6 Actor has the sleep package
  • 7 Actor has the sleep package and the confirmed location

Following is returned if the actor is waking up or the package has changed during

  • 16 Sleep package has ended / expired
  • 17 Sleep package has ended / expired, actor still remains in the location

Error Codes

  • -1 Invalid Actor

Example[edit | edit source]

Int nSleepResults = GetSleepStateEx(akBalimund,pRiftenBalimundSleep0x6,pRiftenBlacksmithLocation)

;Check for both normal value of GetSleepState incase the player is same location as Actor
;else lets check for Dead or the Sleep Package
If nSleepResults == 3 || nSleepResults == 5 || nSleepResults == 7
	Debug.Trace("Actor is sleeping")
EndIf

Script[edit | edit source]

Int Function GetSleepStateEx(Actor akActor,Package akSleepPackage = None,Location akLocation = None)	
	Int iResults = -1
	
	If akActor == None
		Return iResults
	EndIf
	
	If akActor.IsDead()
		iResults = 5
	Else
		Bool bValidate = False
		
		;Detect normal sleep state
		If akActor.GetCurrentLocation().IsSameLocation(Game.GetPlayer().GetCurrentLocation())
			Return akActor.GetSleepState()
		Else
			;Extended sleep detection
			If akLocation == None && akSleepPackage != None 
				If akActor.GetCurrentPackage() == akSleepPackage
					bValidate = True
					iResults = 6
				EndIf
			EndIf
			
			If akLocation != None && akSleepPackage != None 
				If akActor.GetCurrentPackage() == akSleepPackage && akActor.GetCurrentLocation() == akLocation
					bValidate = True
					iResults = 7
				EndIf
			EndIf
			
			If bValidate
				;Lets check incase the schedule for the package has expired
				akActor.EvaluatePackage()	
				If akActor.GetCurrentPackage() != akSleepPackage
					iResults += 10
				EndIf
			EndIf
		EndIf
		
	EndIf
	
	Return iResults
EndFunction

See Also[edit | edit source]