Jump to content

Easy Way to Check for Followers?


Recommended Posts

Is there any easy way to check if an actor is a follower? I need it because I need to handle followers differently from other NPCs for my mod (normally NPCs get heavy weapons removed until they die, and I can't do that with followers for obvious reasons).

 

The only way I can think of is to use an array of the player's followers using Game.GetPlayerFollowers(), but I'm running into issues with that with regards as to how to update the list. I couldn't find a way of updating the list whenever the player gets a new follower, which obviously poses a problem because the only way I can think of resolving that is to, in turn, run a function that updates every x seconds, which could just weigh the game down with constantly running scripts (granted, it's not much, but would still prefer to avoid it if possible).

Link to comment
Share on other sites

You pretty much answered your own question. Set up your array

 

Actor[] playerFollowers = Game.GetPlayerFollowers()

 

Fills playerFollowers[0] through playerFollowers[playerFollowers.Length-1]. if player.Followers.Length = 0 you have no followers.

 

Manage changes with a script that registers for the CompanionChange event.

 

Event OnInit()
RegisterForCustomEvent(FollowersScript.GetScript(), "CompanionChange")
EndEvent
Event FollowersScript.CompanionChange(FollowersScript akSender, Var[] akArgs)
{stuff}
EndEvent
This was on a script that extends Actor, attached to actors that would be changing, and they also need the FollowersScript attached (and set up correctly) as well.
Hope that gets you started. Messing with companion and follower stuff is my favorite, so far.
Link to comment
Share on other sites

Ahh, okay, thank you. I was mainly curious as to how handle updating, and now I know!

 

So then, something like this would work?

Actor this_actor

Actor[] companions_list

Form this_weapon

Event OnEffectStart(Actor akTarget, Actor akCaster)

	this_actor = akTarget

	If this_actor == Game.GetPlayer()

		companions_list = Game.GetPlayerFollowers( )

		RegisterForCustomEvent (FollowersScript.GetScript(), "CompanionChange")

	endIf

endEvent

Event FollowersScript.CompanionChange(FollowersScript akSender, Var[] akArgs)
 
	companions_list	= Game.GetPlayerFollowers()

endEvent

Edited by paulatreides0
Link to comment
Share on other sites

Yeah looks functional for a start. You can use akTarget directly you don't need to use a this_Actor variable, but nothing wrong with it either.

 

I do notice the CompanionChange event gets called on both parties, old and new companion. So you'll likely need some logic to figure out which actors are doing what via the akArgs array.

 

You won't want to update your 'companions_list' if this event is firing on the companion that you are dismissing. It does provide you with 'old' and 'new' you just have to code some logic to handle it.

 

I'm not 100% sure of the sequence of events (when you hire/dismiss) and when CompanionChange gets called. I would take the stance, if possible, that whatever code you're doing in this event may be running in parallel to some other code, and the 'companion changing procedure' may not be complete.

 

That all being said, I believe the CompanionChange event is called after you close any dialogue that hired/dismissed/chose return location, and before the actor is actually 'released' from your service and directed by code to walk or teleport away, but the companion that is leaving should be designated as the leaving companion and already removed from the Game.GetPlayerFollowers() array. ...I THINK (famous last words)

 

Give it a try with those assumptions and see how it goes!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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