walder/Skynet-IADS

Difficulty connecting Power Sources and Connection Nodes to Units

Opened this issue · 4 comments

I have two sets of groups Iraq-AA-SAM-SA2-1 to Iraq-AA-SAM-SA2-7 and Iraq-AA-SAM-Support-SA2-1 to Iraq-AA-SAM-Support-SA2-7

Each Support group has C2, supply, and generator units for the SAM group of the same number. SAM-1 is with Support-1, etc.

I'm using this code to try to connect the generators and C2 from the Supply groups to the SAM groups

iraqIADS:addSAMSitesByPrefix("Iraq-AA-SAM-SA2")
for i = 1, 7 do
    iraqIADS:getSAMSiteByGroupName("Iraq-AA-SAM-SA2-" .. i)
        :setAutonomousBehaviour(math.random(SkynetIADSAbstractRadarElement.AUTONOMOUS_STATE_DCS_AI, SkynetIADSAbstractRadarElement.AUTONOMOUS_STATE_DARK))
        :setCanEngageAirWeapons(true)
        :setCanEngageHARM(true)
        :setEngagementZone(SkynetIADSAbstractRadarElement.GO_LIVE_WHEN_IN_SEARCH_RANGE)
        :setGoLiveRangeInPercent(math.random(75, 150))
        :setHARMDetectionChance(math.random(15, 30))

    local connectionNode = Unit.getByName("Iraq-AA-SAM-SA2-" .. i .. "-4")

    local searchRadar = Unit.getByName("Iraq-AA-SAM-SA2-" .. i .. "-1")
    local searchRadarPower = Unit.getByName("Iraq-AA-SAM-Support-SA2-" .. i .. "-16")
    searchRadar:addPowerSource(searchRadarPower):addConnectionNode(connectionNode)

    local trackingRadar = Unit.getByName("Iraq-AA-SAM-SA2-" .. i .. "-2")
    local trackingRadarPower = Unit.getByName("Iraq-AA-SAM-Support-SA2-" .. i .. "-15")
    trackingRadar:addPowerSource(trackingRadarPower):addConnectionNode(connectionNode)

    local rangingRadar = Unit.getByName("Iraq-AA-SAM-SA2-" .. i .. "-3")
    local rangingRadarPower = Unit.getByName("Iraq-AA-SAM-Support-SA2-" .. i .. "-14")
    rangingRadar:addPowerSource(rangingRadarPower):addConnectionNode(connectionNode)
end

however I'm getting this error attempt to call method 'addPowerSource' (a nil value).

I've confirmed that the power source units and SAM units do exist and the names are correct.
ex. ["name"] = "Iraq-AA-SAM-SA2-1-1", and ["name"] = "Iraq-AA-SAM-Support-SA2-1-16",

I'm using this same method earlier in the script to connect power and command to EWR without any error notifications

iraqIADS:addEarlyWarningRadarsByPrefix("Iraq-AA-EWR")
for i = 1, 3 do
    iraqIADS:getEarlyWarningRadarByUnitName("Iraq-AA-EWR-" .. i .. "-1")
        :addPowerSource(Unit.getByName("Iraq-AA-EWR-" .. i .. "-2"))
        :addConnectionNode(Unit.getByName("Iraq-AA-EWR-" .. i .. "-3"))
end

So I'm a little confused at to what I'm doing wrong and any help would be appreciated!

Is there a way you can attach the miz or send it to me on Discord? Discord name is just "whiskey11". It's a lot easier to diagnose some issues with the raw miz file! :)

Is there a way you can attach the miz or send it to me on Discord? Discord name is just "whiskey11". It's a lot easier to diagnose some issues with the raw miz file! :)

@Whiskey-11 Here you go. This backup should be roughly the same mission state as whan I made this issue. the IADS script inside it is different, but the code I have above is still there but commented out.

From futher testing I've done it seems like you cannot do Unit:addPowerSource(Unit2)
Group:addPowerSouce(Unit2) works fine.

Operation RED FIST - Copy (12).zip

My goal is to have each radar unit in the SAM group have it's own seperate power source. So that if the power source for the search radar is destroyed then only the search radar would lose power.

Yeah, I don't think you'd be able to separate it quite like you want there (a specific search radar having a power unit, etc.). You might be able to go into the actual function in the Skynet-Compiled LUA file and modify it to allow for Unit Name... but I'm not sure. This is a little beyond my coding expertise (took me quite a minute to work out the logic of all the for/do stuff in your LUA ;)

I generally break mine out into individual lines so I can see each site's connections, power, and command centers... but I'm a little on the LUAtarded side. ;) The Discord might be able to help you more specifically as there are people with far better knowledge of how the actual Compiled works.