Jump to content

[LE] How to obtain nearby followers?


pxd2050

Recommended Posts

How to obtain nearby followers and arrange them according to distance?

Is there a similar reference?

Function setAlias(Actor ActorRef)
	if !ActorRef
		return
	endif
	RemoveSubject()
	Targets[0].ForceRefTo(ActorRef)
	??????
	??????
	Targets[1].ForceRefTo(????)
	Targets[2].ForceRefTo(????)
	Targets[3].ForceRefTo(????)
	...

EndFunction
Link to comment
Share on other sites

Here is what I would do. First to find followers, make a new spell, script archetype, that is an area spell. Make the radius something like 10,000 units. Put the condition on the spell GetRelationshipRank >= 3 to the player, that way it only affects ally's. Then put a script on the spell's magic effect that adds the target to a formlist.:

 

Scriptname TM_MagicEffectScript extends ActiveMagicEffect 

FormList Property NearbyFollowers Auto 

Event OnEffectStart(Actor akTarget, Actor akCaster) 
    NearbyFollowers.AddForm(akTarget) ;add target of spell to formlist
EndEvent

Then, in another script, you can use arrays to sort them by distance:

 

Spell Property FindFollowersSpell Auto 
;spell is an area spell, say with 10,000 unit range. Has the condition getRelationShipRank >= 3

FormList Property NearbyFollowers Auto 
;Stores nearby followers from above spell.

Actor Property PlayerRef Auto

Function FindNearbyFollowers() 
    NearbyFollowers.Revert() ;clear formlist first 
    FindFollowersSpell.Cast(PlayerRef) ;player casts the FindFollowersSpell, adding nearby followers to formlist
Endfunction
    
Form[] Function SortRefsByDistance() 
    FindNearbyFollowers() 
    
    Utility.Wait(1) ; wait for spell to cast and find followers 
    
    Int M = NearbyFollowers.GetSize() ;find max entries 
    Int I = 0 ;index int 
    
    Form[] NearbyFollowersArray = Utility.CreateFormArray(M) ;easier to sort actors in array rather than formlist 
    Float[] Distances = Utility.CreateFloatArray(M)
    
    While I < M 
        NearbyFollowersArray[I] = NearbyFollowers.GetAt(I) ;store actors in formlist to array 
        I += 1 
    EndWhile
    
    I = 0    
    
    While I < M 
        Distances[I] = PlayerRef.GetDistance(NearbyFollowersArray[I] as actor) ;get and save current actor's distance from center ref to array
        I += 1 ;add 1 to I moving to next actor in array 
    EndWhile 
    
    I = 0 
    Int M2 = M - 1 ;only need next to last entry for sorting
    
    While I < M 
        
        Int I2 = 0 
        While I2 < M2
        
            Int Next_I = I2 + 1 ;save next index to check against current index 
            If Distances[I2] > Distances[Next_I] ;is the current distance greater than the next?
                Float NextDistance = Distances[Next_I]
                Distances[Next_I] = Distances[I2]
                Distances[I2] = NextDistance ;swap the current and next distances in array 
                
                Form NextActor = NearbyFollowersArray[Next_I]
                NearbyFollowersArray[Next_I] = NearbyFollowersArray[I2] 
                NearbyFollowersArray[I2] = NextActor ;swap the current and next actors in array 
            Endif 
            
            I2 += 1
        Endwhile 
        
        I += 1
    EndWhile 

    Return NearbyFollowersArray
                
EndFunction

The function should return a form array, where the actors are sorted the closest to the player to the farthest away.

Link to comment
Share on other sites

Here is what I would do. First to find followers, make a new spell, script archetype, that is an area spell. Make the radius something like 10,000 units. Put the condition on the spell GetRelationshipRank >= 3 to the player, that way it only affects ally's. Then put a script on the spell's magic effect that adds the target to a formlist.:

 

Scriptname TM_MagicEffectScript extends ActiveMagicEffect 

FormList Property NearbyFollowers Auto 

Event OnEffectStart(Actor akTarget, Actor akCaster) 
    NearbyFollowers.AddForm(akTarget) ;add target of spell to formlist
EndEvent

Then, in another script, you can use arrays to sort them by distance:

 

Spell Property FindFollowersSpell Auto 
;spell is an area spell, say with 10,000 unit range. Has the condition getRelationShipRank >= 3

FormList Property NearbyFollowers Auto 
;Stores nearby followers from above spell.

Actor Property PlayerRef Auto

Function FindNearbyFollowers() 
    NearbyFollowers.Revert() ;clear formlist first 
    FindFollowersSpell.Cast(PlayerRef) ;player casts the FindFollowersSpell, adding nearby followers to formlist
Endfunction
    
Form[] Function SortRefsByDistance() 
    FindNearbyFollowers() 
    
    Utility.Wait(1) ; wait for spell to cast and find followers 
    
    Int M = NearbyFollowers.GetSize() ;find max entries 
    Int I = 0 ;index int 
    
    Form[] NearbyFollowersArray = Utility.CreateFormArray(M) ;easier to sort actors in array rather than formlist 
    Float[] Distances = Utility.CreateFloatArray(M)
    
    While I < M 
        NearbyFollowersArray[I] = NearbyFollowers.GetAt(I) ;store actors in formlist to array 
        I += 1 
    EndWhile
    
    I = 0    
    
    While I < M 
        Distances[I] = PlayerRef.GetDistance(NearbyFollowersArray[I] as actor) ;get and save current actor's distance from center ref to array
        I += 1 ;add 1 to I moving to next actor in array 
    EndWhile 
    
    I = 0 
    Int M2 = M - 1 ;only need next to last entry for sorting
    
    While I < M 
        
        Int I2 = 0 
        While I2 < M2
        
            Int Next_I = I2 + 1 ;save next index to check against current index 
            If Distances[I2] > Distances[Next_I] ;is the current distance greater than the next?
                Float NextDistance = Distances[Next_I]
                Distances[Next_I] = Distances[I2]
                Distances[I2] = NextDistance ;swap the current and next distances in array 
                
                Form NextActor = NearbyFollowersArray[Next_I]
                NearbyFollowersArray[Next_I] = NearbyFollowersArray[I2] 
                NearbyFollowersArray[I2] = NextActor ;swap the current and next actors in array 
            Endif 
            
            I2 += 1
        Endwhile 
        
        I += 1
    EndWhile 

    Return NearbyFollowersArray
                
EndFunction

The function should return a form array, where the actors are sorted the closest to the player to the farthest away.

I saw your reply as soon as I got up. Thank you very much.
Link to comment
Share on other sites

I like using Mod Events for batch commanding muliple units. Once tagged, have your followers enter listening mode via RegisterForModEvent. When you want to relay a command to all of them, SendModEvent out, which basically broadcasts a command to them

 

This ModEvent can contain arguments. You can also command them to Send another ModEvent to a central listener. This can tell the listener where they are and you can relay commands at will. Kinda complicated if you havent played with ModEvents but incredibly powerful underused capability there

Link to comment
Share on other sites

  • Recently Browsing   0 members

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