Jump to content

Spawning actors to become followers from a menu


Sars99

Recommended Posts

Apologies for not having the clearest of titles.

 

I am wanting to create my own variation of the reinforcement flare but doing away with the flaregun.

 

I have created an alchemy item to act as my radio, when used it applies a magic effect with an attached script to bring up a menu.

 

Item script:

 

 

ScriptName MilMinReinforcements:RadioActivate extends ActiveMagicEffect



Group Setup

message Property RadioMenu Auto Const Mandatory

Potion Property RadioItem Auto Const

Actor Property PlayerRef Auto Const Mandatory

MilMinReinforcements:RadioReinforcementQuestInfantry Property RadioQuestInf Auto Const

MilMinReinforcements:RadioReinforcementQuestCommando Property RadioQuestCdo Auto Const

EndGroup



Event OnEffectStart(Actor akTarget, Actor akCaster)

    

    ; Show menu to player and capture button press

    Int iButton = RadioMenu.Show()

    If (iButton == 0)

        RadioQuestInf.SpawnInfantry()

    ElseIf (iButton == 1)

        SpawnInfantryDesert()

    ElseIf (iButton == 2)

        RadioQuestCdo.SpawnCommando()

    ElseIf (iButton == 3)

        SpawnCommandoDesert()

    ElseIf (iButton == 4)

        ;the cancel button

    Endif



    ; Return radio to inventory

    PlayerRef.AddItem(RadioItem as Form, abSilent = True)

EndEvent

 

 

 

Depending on the menu button pressed will spawn a different type of squad to move to and follow the player. I had originally placed the actor spawners within this script, which I was able to get a rough working model using:

 

PlayerRef.PlaceActorAtMe(Commando1)

 

This worked but with a pretty big side effect: https://i.redd.it/ja7cj9ppi2y51.jpg as they are affected by the orientation of the player when spawned. Those that could walk also didn't follow the player.

 

That led me to create script event quests to manage the spawning of the squads, which can be seen through some of the code above in the "Item Script".

 

I've watched several tutorial videos (I have been following seddon and Kinggath's youtube tutorials) and also searched through these forums to try and progress further.

 

Currently the quest script that is called from the item script is as follows:

 

Infantry Quest script:

 

 

ScriptName MilMinReinforcements:RadioReinforcementQuestInfantry extends Quest

ReferenceAlias Property Workshop01 Auto Const
actor Property PlayerRef auto Const Mandatory
worldspace Property Commonwealth Auto Const Mandatory
ReferenceAlias[] Property MarkerAliases Auto Const
ReferenceAlias Property InfantryLeader Auto Const
RefCollectionAlias Property Infantry Auto Const

int minMarkerDistance = 4000 const ; minimum distance of marker to start soldiers at

Function SpawnInfantry()
    ; figure out where to place soldiers, and then enable
    ; first in array is closest, work your way down
    int i = 0
    bool foundMarker = false
    while i < MarkerAliases.Length && foundMarker == false
        ObjectReference marker = MarkerAliases[i].GetRef()
        if (marker && marker.GetDistance(PlayerRef) > minMarkerDistance && PlayerRef.HasDirectLOS(marker) == false && PlayerRef.HasDetectionLOS(marker) == false)
            foundMarker = true
            debug.trace(self + " found valid marker " + marker + " (distance=" + marker.GetDistance(PlayerRef) + ")")
            ; move Minutemen here
            Infantry.MoveAllTo(marker)
            InfantryLeader.TryToMoveTo(marker)
        else
            debug.trace(self + " skipping marker " + marker + " (distance=" + marker.GetDistance(PlayerRef) + ")")
        endif
        i += 1
    endWhile

    ;Enable the soldiers
    InfantryLeader.TryToEnable()
    int iSoldierCount = 5
    i = 0
    While (i < iSoldierCount)
        Infantry.GetAt(i).Enable()
        i += 1
    endWhile
    ObjectReference workshopRef = Workshop01.GetRef()
EndFunction

 

 

 

 

I ripped this from the MinFlareGunQuest script and removed the parts I think I didn't need as it referred to the flaregun.

 

This does not work and does not spawn anything.

 

I would be very grateful if someone could assist in making this work, my knowledge is very basic and I've become stuck.

 

Link to comment
Share on other sites

You need to add a bunch of debug.trace statements to check:

 

has the quest actually started IsRunning() ... not seeing any quest.Start() command

 

are aliases filling GetReference() or GetCount()

 

and

Link to comment
Share on other sites

Thank you (again).

 

I'm guessing the debug.trace stuff populates the file within Fallout4\Logs ??

 

Reading on .TryToEnable() seemed to suggest that you didn't need to use GetReference()

 

I've changed the button press within the radio menu to RadioQuestInf.Start()

 

Within the quest the first stage that runs on start points to the SpawnInfantry function which I've tweaked slightly.

 

ScriptName MilMinReinforcements:RadioReinforcementQuestInfantry extends Quest

ReferenceAlias Property Workshop01 Auto Const
actor Property PlayerRef auto Const Mandatory
worldspace Property Commonwealth Auto Const Mandatory
ReferenceAlias[] Property MarkerAliases Auto Const
ReferenceAlias Property InfantryLeader Auto Const
ReferenceAlias Property Infantry1 Auto Const
ReferenceAlias Property Infantry2 Auto Const
ReferenceAlias Property Infantry3 Auto Const

int minMarkerDistance = 4000 const ; minimum distance of marker to start soldiers at

Function SpawnInfantry()
    ; figure out where to place soldiers, and then enable
    ; first in array is closest, work your way down
    int i = 0
    bool foundMarker = false
    while i < MarkerAliases.Length && foundMarker == false
        ObjectReference marker = MarkerAliases[i].GetRef()
        if (marker && marker.GetDistance(PlayerRef) > minMarkerDistance && PlayerRef.HasDirectLOS(marker) == false && PlayerRef.HasDetectionLOS(marker) == false)
            foundMarker = true
            debug.trace(self + " found valid marker " + marker + " (distance=" + marker.GetDistance(PlayerRef) + ")")
            ; move actors here
            InfantryLeader.TryToMoveTo(marker)
            Infantry1.TryToMoveTo(marker)
            Infantry2.TryToMoveTo(marker)
            Infantry3.TryToMoveTo(marker)
        else
            debug.trace(self + " skipping marker " + marker + " (distance=" + marker.GetDistance(PlayerRef) + ")")
        endif
        i += 1
    endWhile
    
    ;Enable the soldiers
    InfantryLeader.TryToEnable()
    Infantry1.TryToEnable()
    Infantry2.TryToEnable()
    Infantry3.TryToEnable()
    ObjectReference workshopRef = Workshop01.GetRef()
EndFunction

Function Stop()
;empty function
EndFunction

 

 

 

Edit: Seems the quest isn't launching off the button press on the menu.

Edited by Sars99
Link to comment
Share on other sites

>I'm guessing the debug.trace stuff populates the file within Fallout4\Logs ??

Read https://www.creationkit.com/fallout4/index.php?title=Enable_Debug_Logging thats 101 for scripting

 

>Reading on .TryToEnable() seemed to suggest that you didn't need to use GetReference()

 

Yes but your trying to find out IF THE QUEST IS RUNNING AND IF ANYTHING IS ACTUALLY POPULATING IN THE ALIASES. Because I bet you a billion dollars that your quest is not running and/or your aliases are not filling. Find out if they are. You could just console [ sqv QuestName ] but you dont get the same level of info.

Link to comment
Share on other sites

Thanks, that debug stuff pointed me in the right direction once I figured some stuff out. I missed adding the quest to the script event part as I didn't think it was needed loosely trying to follow your original reply to me on reddit.

 

I have the squad spawning in, I foolishly removed the keyword requirement from the conditions so will look to set that up tomorrow.

 

Until my next snag...

Link to comment
Share on other sites

  • Recently Browsing   0 members

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