Jump to content

Form List Comparison Question


Dantioch01

Recommended Posts

Seasons greetings,

 

I'm working on a mod to create an array of actors that are potential followers - the goal is to then manipulate all the mod added followers to make their recruitment more interersting. I've got most of what i wanted working using SkyPal, however i've run into a problem in excluding some vanilla followers from my list to edit. I've created a form list in the CK with the specific actors to exclude, and created a function to check that each of my potential actors isn't in the list using the HasForm fucntion. However i still see these actors in my array when I test - the code for the function is below but the line that doesn't seem to work correctly is:

 

DTFollowersToExcludeList.HasForm(ref_to_check) == false

 

with DTFollowersToExcludeList being the formlist. The first 2 conditions in the statement work correctly as I only get actors in the PotentialFollowerFaction - any thoughts would be welcome,

 

Thanks

function Get_NPC_Array()
	int [] Base_Form_Types = new int[1]
   	Base_Form_Types[0] = NPC_Form_Type
	ObjectReference[] NPC_Array = SkyPal_References.All()
	Debug.MessageBox(NPC_Array.Length+"NPCs Found")
	NPC_Array = SkyPal_References.Filter_Form_Types(NPC_Array, Base_Form_Types)
	Debug.MessageBox(NPC_Array.Length+"Characters Found")
	int Index = 0
	actor ref_to_check
	int Array_Length = NPC_Array.Length
	Adventurer_Array = new Actor[128]
	while index < Array_Length
		ref_to_check = NPC_Array[index] as actor
		if ref_to_check.IsInFaction(PotentialFollowerFaction) && ref_to_check.IsInFaction(DTPotentialFollower) == false && DTFollowersToExcludeList.HasForm(ref_to_check) == false
			ArrayAddRef(Adventurer_Array, ref_to_check)
			index +=1
			ref_to_check.RemoveFromFaction(PotentialFollowerFaction)
			ref_to_check.AddToFaction(DTPotentialFollower)
			ref_to_check.SetRelationshipRank(Game.GetPlayer(), 0)
			ref_to_check.SetFactionRank(DTPotentialFollower,Utility.RandomInt(0, 100))
			;debug.Notification("Added to Array called")
		else
			index +=1
			;debug.Notification("Added to array not called")
		endif
	endWhile
	Debug.MessageBox(Adventurer_Array.Length+"Adventurers Found")
endFunction
Link to comment
Share on other sites

You wrote: "any thoughts would be welcome"

I think you should split your function in subfunctions to get a better overview. In my opinion the "Adventurer_Array" is wrong initialized!

 

maybe next code is useful to you

 

; https://forums.nexusmods.com/index.php?/topic/10894493-form-list-comparison-question/

  Faction PROPERTY PotentialFollowerFaction auto
  Faction PROPERTY DTPotentialFollower      auto

  FormList PROPERTY DTFollowersToExcludeList auto

  Int PROPERTY NPC_Form_Type auto        ; set to 0x??

;------------------------------
FUNCTION Get_Adventurer_Array()
;------------------------------
    int[] b = new Int[1]                                     ; b = Base_Form_Types
    b[0] = NPC_Form_Type
    
    objectReference[] a = SkyPal_References.All()            ;* a = NPC_Array
    Debug.MessageBox("NPCs found " +a.Length)

    a = SkyPal_References.Filter_Form_Types(NPC_Array, b)    ;* limit array to NPC_Form_Type
    Debug.MessageBox("Characters found " + a.Length)

    myF_DestroyArray()
;;;    Adventurer_Array = new Actor[128]        ; !!!
    
    int i = 0                                                ; i = Index
    WHILE (i < a.Length)

        actor aRef = a[i] as Actor                           ; aRef = ref_to_check
        IF ( aRef )
            IF aRef.IsInFaction(DTPotentialFollower)
                ; already in this faction

            ELSEIF DTFollowersToExcludeList.HasForm(aRef as Form)            ; *** suggested by Ghaunadaur ***
                ; actor found in exclude list

;?;         ELSEIF DTFollowersToExcludeList.HasForm( aRef.GetBaseObject() )  ; depends on: What is the content of your formlist?, this could also work
                ; actorbase found

            ELSEIF aRef.IsInFaction(PotentialFollowerFaction)
                myF_ADD(aRef, Utility.RandomInt(0, 100))
            ENDIF
        ENDIF

        i = i + 1
    ENDWHILE

    Debug.MessageBox("Adventurers found " +Adventurer_Array.Length)
ENDFUNCTION


  Actor[] PROPERTY Adventurer_Array auto Hidden        ; property here to get access from other scripts

;--------------------------
FUNCTION myF_DestroyArray()
;--------------------------
    actor[] b
    Adventurer_Array = b
ENDFUNCTION

;-----------------------
FUNCTION myF_InitArray()
;-----------------------
    Adventurer_Array = new Actor[128]
ENDFUNCTION

;----------------------------------
FUNCTION myF_ADD(Actor aRef, Int r)
;----------------------------------
    ArrayAddRef(Adventurer_Array, aRef)                        ;** no idea what function is that??

    aRef.RemoveFromFaction(PotentialFollowerFaction)
    aRef.AddToFaction(DTPotentialFollower)

    aRef.SetRelationshipRank(Game.GetPlayer(), 0)
    aRef.SetFactionRank(DTPotentialFollower, r)                ;  valid range: -128 .. 127
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

NPC_Array is an ObjectReference array. You are casting those values into Actor and assigning it to ref_to_check. Then you are checking to see if these actors are in the DTFollowersToExcludeList form list.

 

The question then is this: What did you assign to the DTFollowersToExcludeList? The base actor or the pre-placed object reference?

 

If the base actor, you probably need to use: ref_to_check.GetActorBase()

If the pre-placed object reference, you probably need to use: NPC_Array[index]

 

It may be a good idea to temporarily trace out the contents (actual ID numbers not names) of the array and the form list to ensure that you are trying to compare the correct things.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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