pickup-helper/Source/Scripts/ETAxPlayerAliasScript.psc
2022-02-13 03:24:30 +01:00

195 lines
4.3 KiB
Plaintext

Scriptname ETAxPlayerAliasScript extends ReferenceAlias
int iFloraCount = 0
int iArrowCount = 0
event OnInit()
PlayerRef.AddPerk(ETAxTakePerk)
RegisterForSingleUpdate(10.0)
endevent
event OnPlayerLoadGame()
RegisterForSingleUpdate(10.0)
endevent
event OnUpdate()
ScanPouches()
ScanArrows()
endevent
function ScanArrows()
Form[] aItems = PO3_SKSEfunctions.GetAllForms(42) ; ammo
int i = aItems.Length
if iArrowCount == i
return
endif
iArrowCount = i
Projectile arrowProjectile
ETAxArrowList.Revert()
while i > 0
i -= 1
if aItems[i].IsPlayable()
ETAxArrowList.AddForm(aItems[i])
arrowProjectile = (aItems[i] as Ammo).GetProjectile()
if arrowProjectile && ! ETAxArrowList.HasForm(arrowProjectile)
ETAxArrowList.AddForm(arrowProjectile)
endif
endif
endwhile
endfunction
function ScanPouches()
Form[] aItems = PO3_SKSEfunctions.GetAllForms(39) ; flora
int i = aItems.Length
if iFloraCount == i
return
endif
iFloraCount = i
SoundDescriptor refSound
ETAxGoldList.Revert()
While i > 0
i -= 1
refSound = (aItems[i] as Flora).GetHarvestSound()
if refSound && ETAxPouchSounds.Find(refSound) != -1 && ! ETAxGoldList.HasForm(aItems[i])
ETAxGoldList.AddForm(aItems[i])
endif
Endwhile
endfunction
function TakeByArray(ObjectReference[] aRefs, bool bCheckWeight = false)
float fDelay = ETAxPickUpDelay.Value
int i = aRefs.Length
While i > 0
i -= 1
if aRefs[i].IsEnabled() && aRefs[i].Is3DLoaded()
if fDelay > 0
Utility.wait(fDelay)
endif
if ! bCheckWeight || aRefs[i].GetBaseObject().GetWeight() <= ETAxWeightLimit.Value
aRefs[i].Activate(PlayerRef)
endif
endif
Endwhile
endfunction
function PickFloraByType(Form rBase)
int iType = rBase.GetType()
Form pickedIngredient
if iType == 38 ; tree
pickedIngredient = (rBase as TreeObject).GetIngredient()
elseif iType == 39 ; flora
pickedIngredient = (rBase as Flora).GetIngredient()
else
return
endif
ObjectReference[] aRefs = PO3_SKSEfunctions.FindAllReferencesOfFormType(PlayerRef, iType, ETAxPickUpRadius.Value * 1.5)
int i = aRefs.Length
float fDelay = ETAxPickUpDelay.Value
Form refIngredient
while i > 0
i -= 1
if aRefs[i].GetBaseObject() == rBase
if ! aRefs[i].IsHarvested() && aRefs[i].IsEnabled() && aRefs[i].Is3DLoaded()
if fDelay > 0
Utility.wait(fDelay)
endif
aRefs[i].Activate(PlayerRef)
endif
else
if iType == 38 ; tree
refIngredient = (aRefs[i].GetBaseObject() as TreeObject).GetIngredient()
else
refIngredient = (aRefs[i].GetBaseObject() as Flora).GetIngredient()
endif
if refIngredient == pickedIngredient && ! aRefs[i].IsHarvested() && aRefs[i].IsEnabled() && aRefs[i].Is3DLoaded()
if fDelay > 0
Utility.wait(fDelay)
endif
aRefs[i].Activate(PlayerRef)
endif
endif
endwhile
endfunction
function PickFloraByTypeIdAndIngredient(int iType, Form fIngredient)
ObjectReference[] aRefs = PO3_SKSEfunctions.FindAllReferencesOfFormType(PlayerRef, iType, ETAxPickUpRadius.Value * 1.5)
int i = aRefs.Length
float fDelay = ETAxPickUpDelay.Value
Form refIngredient
while i > 0
i -= 1
if iType == 38 ; tree
refIngredient = (aRefs[i].GetBaseObject() as TreeObject).GetIngredient()
else
refIngredient = (aRefs[i].GetBaseObject() as Flora).GetIngredient()
endif
if refIngredient == fIngredient && ! aRefs[i].IsHarvested() && aRefs[i].IsEnabled() && aRefs[i].Is3DLoaded()
if fDelay > 0
Utility.wait(fDelay)
endif
aRefs[i].Activate(PlayerRef)
endif
endwhile
endfunction
function TakeByFormOrList(Form formOrList)
TakeByArray(PO3_SKSEfunctions.FindAllReferencesOfType(PlayerRef, formOrList, ETAxPickUpRadius.Value))
endfunction
function TakeByKeyword(Form keywordOrList, bool bCheckWeight = false)
TakeByArray(PO3_SKSEfunctions.FindAllReferencesWithKeyword(PlayerRef, keywordOrList, ETAxPickUpRadius.Value, false), bCheckWeight)
endfunction
function TakeByFormType(int iFormType)
TakeByArray(PO3_SKSEfunctions.FindAllReferencesOfFormType(PlayerRef, iFormType, ETAxPickUpRadius.Value))
endfunction
Actor Property PlayerRef Auto
Perk Property ETAxTakePerk Auto
GlobalVariable Property ETAxPickUpDelay Auto
GlobalVariable Property ETAxPickUpRadius Auto
GlobalVariable Property ETAxWeightLimit Auto
FormList Property ETAxPouchSounds Auto
FormList Property ETAxGoldList Auto
FormList Property ETAxArrowList Auto