Jump to content

CK: How to use a script (or condition) to determine if a player is currently controlling a companion?


g2mXagent

Recommended Posts

i know there is some function like IsDoingFavor() or condition function IsInFavor() for Companion.
but is there a way to directly determine the player's status?
this is my way:

;Property
Faction Property CurrentCompanionFaction auto

;Function
int Function IsFollowerInFavorState()
    Actor[] playerFollowers = Game.GetPlayerFollowers()
    int index = 0
    while (index < playerFollowers.Length)
        if (playerFollowers[index].IsInFaction(CurrentCompanionFaction) && playerFollowers[index].IsDoingFavor())
            Return 1    ;Yes, you are currently controlling a companion!
        endIf
        index += 1
    endWhile
    Return 0    ;No.
EndFunction


It is inefficient and difficult to use. I need a smarter way to do this.

Edited by g2mXagent
Link to comment
Share on other sites

If (Alias_Companion.GetActorReference().IsCommandedActor() == TRUE) ;Alias property direct from Followers Quest

 

Elseif (Alias_DogmeatCompanion.GetActorReference().IsCommandedActor() == TRUE) ;Alias property direct from Followers Quest

Link to comment
Share on other sites

Thanks for the two tips. I have improved my approach now.

 

zUa3dqd.png

 

this is script:

...
Event OnCommandModeEnter()
    ;mark the player in command mode.
endEvent


Event OnCommandModeExit()
    ;mark the player not in command mode.
endEvent
It can partially work properly. suppose I have 4 companions, it can only work randomly on a single companion, other companions did not respond.
I tried to change the [Reference Alias] to [Ref Collection Alias], after that, all companions no longer responded ... ...
** oh, I use [Unlimited Companion Framework], it allows multiple companions.
I am thinking, can I apply OnCommandModeEnter() to Player?
Edited by g2mXagent
Link to comment
Share on other sites

If by controlling you mean if you have a companion with you at the time, then yes.

 

 

Use "Getinfaction: Currentcompanionfaction" as a requirement to make something trigger only if that target of the requirement is your follower, and use "Getinfaction: HasbeenCompanionfaction" to make it only fire/not fire if the companion has never been recruited before/has been recruited before.

Link to comment
Share on other sites

  On 10/28/2018 at 11:55 AM, charliedfsf said:

If by controlling you mean if you have a companion with you at the time, then yes.

Use "Getinfaction: Currentcompanionfaction" as a requirement to make something trigger only if that target of the requirement is your follower, and use "Getinfaction: HasbeenCompanionfaction" to make it only fire/not fire if the companion has never been recruited before/has been recruited before.

 

GetInFaction

https://www.creationkit.com/index.php?title=GetInFaction

it say: This console command works if used in Console, but doesn't work if used as Condition.

 

and when i use it in Conditions, It turns purple:

 

 

and it didn't work.

Link to comment
Share on other sites

If you are interested in base game companions CurrentCompanionFaction is always the current fill of either Alias_Companion or Alias_DogmeatCompanion on the Followers Quest.


Be careful with HasBeenCompanionFaction, most base game companions initialize as members with rank -1 which GetInfaction returns TRUE, so you need to check for GetFactionRank() >= 0 to actually test if they HAVE BEEN or ARE AVAILABLE as a companion. It's the base activation logic for SKKUnlockAllCompanions.


PS GetInfaction works fine as a condition in Fallout4, thats a Skyrim page.
Link to comment
Share on other sites

If by "controlling a companion" you imply having someone with you, then I would approach this whole thing different.

 

Create an alias which is "External Alias Ref -- Followers -- Companion". Mark it 'Optional' and 'Allow Reserved'. Then when you need to check something, say in a stage fragment script, I would call a function on it there (just when needed). For that I would add a script on the quest itself, where to keep custom funtions (as a library) to be called in action -- in a stage fragment, as an example above.

 

Check, if alias contains reference first (meaning, the companion is with us) -- this is why we ticked it 'Optional', and then everything else, such as going into a STATE within script where you wait for events like


OnCommandModeEnter()
but for that, you must register your quest script for a remote event from this Reference Alias. For instance:
Scriptname TestQuestSCR extends Quest

ReferenceAlias property RA01 auto        ;That ReferenceAlias, discussed earlier
Actor ActorREF01 = NONE


    Function CheckCompanionIfAny()        ;to be called from the quest fragment scripts, ect
        ActorREF01 = RA01.GetActorRef()
        
        if ActorREF01 != NONE
            RegisterForRemoteEvent(ActorREF01, "OnCommandModeEnter")
            GoToState("CommandModeStateCheck")
        endif
    endfunction
        
    Event Actor.OnCommandModeEnter(Actor akSender)
        if akSender == ActorREF01
            ;do your filthy stuff
            
            UnregisterForRemoteEvent(ActorREF01, "OnCommandModeEnter")
            GoToState("Finished")
        endif
    endevent
    
    STATE Finished
        ;finished working. Waiting for the next external call of CheckCompanionIfAny()
    ENDSTATE
Edited by werr92
Link to comment
Share on other sites

  • Recently Browsing   0 members

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