Jump to content

[LE] Need Help Trying To Fill Quest Alias By Checking IsInList


Cheyron

Recommended Posts

So I have a FormList of beds. CommonBed01 for example. Beds inherit Activator which inherit Form so they are valid objects to load into the list. Now when I try to find the closest furniture in the list, it never seems to find one because after stopping and starting the quest in order to force the quest to fill aliases... the aliases are always empty... I try to call GetReference after starting the quest when I am standing next to one of these beds on the list and it always returns None/Null. I am simply using a matching condition in the quest alias to check IsInList and then I point to the list that has the list of Furnitures. Can someone explain how to do this properly?



I want to be able to dynamically find furniture at runtime. I always assumed to find objects loaded in the world... you create quest aliases with conditions and then start the quest to begin looking for them. What am I missing?


Link to comment
Share on other sites


Scriptname _cheyron_FindBedEffect extends activemagiceffect

ObjectReference Function FindBedToSleepIn()
;begin search for beds in loaded area
;the quest aliases ClosestSingleBedRef, ClosestDoubleBedRef, and ClosestBedrollRef...
;all have the condition that checks if the base furniture object of the object matches a furniture on the list using IsInList
;i made sure to mark this quest as able to run more than once by unchecking the box on the quest data tab and the aliases are optional as well
Debug.Notification("Starting Bed Quest")
FindBedQuest.Stop()
Utility.Wait(0.1)
FindBedQuest.Start()
Utility.Wait(0.1)

;check results of search
ObjectReference sBed = ClosestSingleBedRef.GetReference()
Float sDist = 9999.0
ObjectReference dBed = ClosestDoubleBedRef.GetReference()
Float dDist = 9999.0
ObjectReference rBed = ClosestBedrollRef.GetReference()
Float rDist = 9999.0
Actor player = PlayerRef.GetReference() as Actor
Int found = 0
If sBed != None
found += 1
sDist = player.GetDistance(sBed)
Debug.Notification("Single Bed Found")
EndIf
If dBed != None
found += 1
dDist = player.GetDistance(dBed)
Debug.Notification("Double Bed Found")
EndIf
If rBed != None
found += 1
rDist = player.GetDistance(rBed)
Debug.Notification("Bedroll Found")
EndIf

If found > 0
If dDist <= sDist && dDist <= rDist
Return dBed
ElseIf sDist <= dDist && sDist <= rDist
Return sBed
Else
Return rBed
EndIf
Else
Debug.Notification("No Bed Found!")
Return None
EndIf
EndFunction

Event OnEffectStart(Actor akTarget, Actor akCaster)
;cast spell then check debug messages... it always says "No Bed Found!" even when I am standing next to a valid bed
ObjectReference bed = FindBedToSleepIn()
EndEvent


Quest Property FindBedQuest Auto

ReferenceAlias Property ClosestSingleBedRef Auto

ReferenceAlias Property ClosestDoubleBedRef Auto

ReferenceAlias Property ClosestBedrollRef Auto

ReferenceAlias Property PlayerRef Auto

 

Edited by Cheyron
Link to comment
Share on other sites

Hmm.. maybe next script is helpful for you. Please read the comments inside and make sure the formlist is created with baseobject content in right order for script comparing!

 

_cheyron_FindBedEffectScript

 

Scriptname _cheyron_FindBedEffectScript extends ActiveMagicEffect
; spell of type: fire and forget, no spell or effect conditions
; https://forums.nexusmods.com/index.php?/topic/9076003-need-help-trying-to-fill-quest-alias-by-checking-isinlist/

  Quest    PROPERTY myQuest auto                ; the own new created quest
  Formlist PROPERTY myList  auto                ; create a new formlist with all the baseObjects of furniture you like to find

  GlobalVariable PROPERTY myGateKeeper auto     ; a globalVar (new created with CK by you) to control spell casting [default=global.GetValue()==0.0]


; Cheyron wrote: "cast spell then check debug messages... it always says "No Bed Found!" even when I am standing next to a valid bed"
;                "the aliases are optional as well"

; -- EVENT --

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
IF ( myGateKeeper )
ELSE
    RETURN    ; - STOP -    missing property, not filled or not existant
ENDIF
;---------------------
IF (myGateKeeper.GetValue() == 1.0)
;;;    self.Dispel()
    RETURN    ; - STOP -    still running another searching
ENDIF
;---------------------
    myGateKeeper.SetValue(1.0)        ; ***
    objectReference oRef = FindBedToSleepIn(akCaster as ObjectReference)        ; we assume the caster is the player

        ; more code here, if needed

    myGateKeeper.SetValue(0.0)        ; ***
ENDEVENT


; -- FUNCTION --

; https://www.creationkit.com/index.php?title=FindClosestReferenceOfAnyTypeInListFromRef_-_Game

;-------------------------------------------------------------------
ObjectReference FUNCTION FindBedToSleepIn(ObjectReference playerRef)
;-------------------------------------------------------------------
    Debug.Notification("Start searching for beds")
    objectReference oRef = Game.FindClosestReferenceOfAnyTypeInListFromRef(myList, playerRef, 5000.0)        ; radius 5000.0

IF ( oRef )
    form fm = oRef.GetBaseObject()
    referenceAlias RA

    IF     (fm == myList.GetAt(0))
        Debug.Notification("Single Bed Found")
        RA = myQuest.ClosestSingleBedRef
    
    ELSEIF (fm == myList.GetAt(1))
        Debug.Notification("Double Bed Found")
        RA = myQuest.ClosestDoubleBedRef
    
    ELSEIF (fm == myList.GetAt(2))
        Debug.Notification("Bedroll Found")
        RA = myQuest.ClosestBedrollRef
    ENDIF

    RA.ForceRef(oRef)        ; bind objectRef to RefAlias from quest

ELSE
    Debug.Notification("No Bed Found!")
ENDIF

    RETURN oRef        ; None or the closest bed found
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...