Jump to content

Best Practice For Determining If An Actor Is A Player Follower?


Recommended Posts

Making the assumption that a player is using AFT how would I reliably determine if an NPC Actor object is in the follower list? How does this relate to code for determining the player's singular follower in the vanilla sense? Thanks so much!

Link to comment

I've looked through his code. And this is what I have gleaned (some code snippets probably suited for a config script):

Bool _usingAFT
Bool _usingUFO
Bool _usingEFF

Bool Function IsUsingAFT()
    Return _usingAFT
EndFunction

Bool Function IsUsingUFO()
    Return _usingUFO
EndFunction

Bool Function IsUsingEFF()
    Return _usingEFF
EndFunction

Function DiscoverFollowerFrameworks()
    Int mods = Game.GetModCount()
    Int i
    While i < mods
        String modname = Game.GetModName(i)
        If !_usingAFT && modname == "AmazingFollowerTweaks.esp"
            _usingAFT = True
        ElseIf !_usingUFO && modname == "UFO - Ultimate Follower Overhaul.esp"
            _usingUFO = True
        ElseIf !_usingEFF && modname == "XFLMain.esm" 
            _usingEFF = True
        EndIf
        
        i += 1
        
    EndWhile
EndFunction

Actor[] Function GetAllAFTFollowers()
    Actor[] dummy = DummyActorArray()
    
    If !IsUsingAFT()
        Return dummy
    EndIf
    
    TweakDFScript aftScript = DialogueFollower As TweakDFScript
    
    If !aftScript
        ToUserLog("Could not retrieve TweakDFScript through DialogueFollower quest")
        Return dummy
    EndIf
    
    ReferenceAlias[] aliases = aftscript.GetAllFollowers()
    Int count = aliases.Length
    Actor[] results = ActorArray(count)
    Int i = 0
    While i < Count
        Actor anActor = aliases[i].GetReference() As Actor
        If anActor 
            results[i] = anActor
        EndIf
        i += 1
    EndWhile
    Return results
EndFunction

Actor[] Function GetAllUFOFollowers()
    Actor[] dummy = DummyActorArray()
    Quest ufoQuest = Quest.GetQuest("0fLokiiYouKnow")
    
    If !ufoQuest
        ToUserLog("Could not retrieve UFO quest object")
        Return dummy
    EndIf
    
    Actor[] results = ActorArray(16)
    Int i = 2
    While i <= 17
        Actor anActor = (DialogueFollower.GetAlias(i) As ReferenceAlias).GetReference() As Actor
        If anActor 
            Int i2 = i - 2
            results[i2] = anActor
        EndIf
        i += 1
    EndWhile
EndFunction

Actor[] Function GetAllEFFFollowers()
    Actor[] dummy = DummyActorArray()
    Quest xflQuest = Quest.GetQuest("FollowerExtension")
    
    If !xflQuest
        ToUserLog("Could not retrieve EFF quest object")
        Return dummy
    EndIf
    
    XFLScript followerExtension = xflQuest As XFLScript
    Int count = followerExtension.XFL_GetCount()
    Actor[] results = ActorArray(count)
    Int i = 0
    While i < count && i < 100
        Actor anActor = followerExtension.XFL_GetFollower(i)
        If anActor 
            results[i] = anActor
        Else
            ; Adds one since it is possible that there are blanks in the follower list
            count += 1
        EndIf
        i += 1
    EndWhile
EndFunction

Actor Function GetRegularFollower()
    Return (DialogueFollower.GetAlias(0) As ReferenceAlias).GetReference() As Actor
EndFunction
Link to comment

Well I'm running into an issue that I cannot currently solve. Using basically the code above, I get an error in AFT's tweakdfscript.psc:

[04/29/2014 - 05:35:43PM] error: Cannot cast from None to ReferenceAlias[]
stack:
	[DialogueFollower (000750BA)].tweakdfscript.GetAllFollowers() - "tweakdfscript.psc" Line 521
	[Apropos (2F000D62)].aproposconfig.GetAllAFTFollowers() - "AproposConfig.psc" Line 494
	[Apropos (2F000D62)].aproposconfig.GetAllFollowers() - "AproposConfig.psc" Line 472
	[Apropos (2F000D62)].aproposconfig.OnPageReset() - "AproposConfig.psc" Line 228
	[Apropos (2F000D62)].aproposconfig.SetPage() - "SKI_ConfigBase.psc" Line 793

The relevant function in tweakdfscript.psc:

ReferenceAlias[] Function GetAllFollowers(Bool onlyNotWaiting=False, Bool onlyNotWerewolf = False, Bool raw = False)

	ReferenceAlias[] all = new ReferenceAlias[5]
	all[0] = pFollowerAlias
	all[1] = pFollowerAlias2
	all[2] = pFollowerAlias3
	all[3] = pFollowerAlias4
	all[4] = pFollowerAlias5

	if (raw)
		return all
	endif

	ReferenceAlias[] ret = new ReferenceAlias[5]
	int count = 0

	int i = 0
	while (i != all.length)
		if (all[i].GetActorRef() && !all[i].GetActorRef().IsDead())
			if (!onlyNotWaiting || ( 0 == all[i].GetActorRef().GetAV("WaitingForPlayer") As Int))
				if (!onlyNotWerewolf || !all[i].GetActorRef().IsInFaction(WerewolfFaction))
					ret[count] = all[i]
					count += 1
				endif
			endif
		endif
		i = i + 1
	endWhile

	ReferenceAlias[] trim;
	if (count == 5)
		trim = new ReferenceAlias[5]
	elseif (count == 4)
		trim = new ReferenceAlias[4]
	elseif (count == 3)
		trim = new ReferenceAlias[3]
	elseif (count == 2)
		trim = new ReferenceAlias[2]
	elseif (count == 1)
		trim = new ReferenceAlias[1]		
	else
		trim = none
	endif

	i = 0
	while (i < count)
		trim[i] = ret[i]
		i += 1
	endwhile

	return trim

endFunction
Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use