pxd2050 Posted November 16, 2021 Share Posted November 16, 2021 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 More sharing options...
dylbill Posted November 16, 2021 Share Posted November 16, 2021 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 EndEventThen, 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 EndFunctionThe 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 More sharing options...
pxd2050 Posted November 16, 2021 Author Share Posted November 16, 2021 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 EndEventThen, 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 EndFunctionThe 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 More sharing options...
dylbill Posted November 17, 2021 Share Posted November 17, 2021 No problem, I haven't tested it but I think it should work. Also note that the Utility.CreateFormArray() and Utility.CreateFloatArray() functions require skse. Link to comment Share on other sites More sharing options...
Sphered Posted November 18, 2021 Share Posted November 18, 2021 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 More sharing options...
Recommended Posts