Difference between revisions of "User:PROXiCiDE/GetSleepStateEx"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>PROXiCiDE
(Created page with " 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 act...")
 
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">
Int Function GetSleepStateEx(Actor akActor,Package akSleepPackage = None,Location akLocation = None)
Function AddItemsToPlayerFromForm(FormList pList, Bool bRemove = False)
</source>
</source>


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


== Return Value ==
== Return Value ==
The actor's current sleep state.
None
 
*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">
Int nSleepResults = GetSleepStateEx(akBalimund,pRiftenBalimundSleep0x6,pRiftenBlacksmithLocation)
FormList Property _PX_DebugSpellList Auto
 
Event OnInit()
;Check for both normal value of GetSleepState incase the player is same location as Actor
;Debug
;else lets check for Dead or the Sleep Package
AddItemsToPlayerFromForm(_PX_DebugSpellList)
If nSleepResults == 3 || nSleepResults == 5 || nSleepResults == 7
EndEvent
Debug.Trace("Actor is sleeping")
EndIf
</source>
</source>


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

Revision as of 17:30, 7 February 2014

Adds or Removes items from the player inventory / spell list.

Syntax

Function AddItemsToPlayerFromForm(FormList pList, Bool bRemove = False)

Parameters

  • pList: The form list containing Spells / Ammo / Weapon.
  • bRemove : Items from the FormList will be removed instead of added to the player.
    • Default: False

Return Value

None

Example

FormList Property _PX_DebugSpellList Auto
Event OnInit()
	;Debug
	AddItemsToPlayerFromForm(_PX_DebugSpellList)
EndEvent

Script

Function AddItemsToPlayerFromForm(FormList pList, Bool bRemove = False)
	If pList == None
		Return
	EndIf
	
	Actor pPlayer = Game.GetPlayer()
	Ammo pAmmo = None
	Weapon pWeapon = None
	Spell pSpell = None
	
	Int Size = pList.GetSize()
	While Size > 0
		Size -= 1
		Form fmItem = pList.GetAt(Size)
		If fmItem As Spell
			pSpell = fmItem As Spell
			If bRemove
				pPlayer.RemoveSpell(pSpell)
			Else
				pPlayer.AddSpell(pSpell)
			EndIf
		ElseIf fmItem As Ammo
			pAmmo = fmItem As Ammo
			If bRemove
				pPlayer.RemoveItem(fmItem, 100)
			Else
				pPlayer.AddItem(fmItem, 100)
			EndIf
		ElseIf fmItem As Weapon
			pWeapon = fmItem As Weapon
			If bRemove
				pPlayer.RemoveItem(fmItem, 1)
			Else
				pPlayer.AddItem(fmItem,1)
			EndIf
		EndIf
	EndWhile
	
	If !bRemove
		pPlayer.EquipItem(pAmmo)
		pPlayer.EquipItem(pWeapon)
	EndIf
	
EndFunction