ED Forums

ED Forums (https://forums.eagle.ru/index.php)
-   Mission Editor Discussion and Questions (https://forums.eagle.ru/forumdisplay.php?f=210)
-   -   Hoggit Wiki style respawn script no longer functional (https://forums.eagle.ru/showthread.php?t=251981)

Wrench 10-09-2019 06:01 AM

Hoggit Wiki style respawn script no longer functional
 
I've used the conditional from the Hoggit wiki for many years to control a respawn script, here:
Code:

if not Group.getByName('groupName') then
however, that has recently been changed so that a group set to late activation, and I believe even a group that has been destroyed, are no longer evaluated as false with this condition.
I think that has been changed to determine if a group exists in the mission, as opposed to how it used to work where it determined if the group is currently alive.

I've also tried Group.isExist with the same results.

Does anyone know a conditional that is still functional?

Grimes 10-09-2019 06:23 AM

A be all catch all. Basically if there is not a group object or there is a group object and is exist is false or size is 0.

Code:

        local function groupIsDead(groupName).
                if (Group.getByName(groupName) and ( Group.getByName(groupName):isExist() == false or #Group.getByName(groupName):getUnits() < 1)) or not Group.getByName(groupName) then
                        return true
                end
                return false
        end


Wrench 10-09-2019 10:26 PM

Tried that, returns mission editor group size for unactivated groups now.
I'm not sure if it'll be the same if they are killed.

I could simply have the group spawn, then explode at mission start, then selectively respawn them if needed, but that's pretty clunky.

If I wanted a ground start group I'd have to teleport them first to avoid damaging the airfield and nearby aircraft as well.l, and that's assuming the conditionals will work on a group which has been killed.
I'll give it a shot tonight.

Hardcard 10-10-2019 02:50 AM

@Wrench

What you report is both weird and disturbing.

Have you tried using Unit class instead of Group class?

This works for me (apparently, at least):

Code:

if Unit.getByName(unitname) == nil or Unit:isExist() == false then
  -- Respawn the unit because it's dead
end


Also, in case you absolutely must use Group class and none of the stuff Grimes proposed really works, I guess you could try silly stuff like:

Code:

local function Group_Alive_Check(GroupName)
 
  local Group_2_Check = Group.getByName(GroupName)
 
  local Initial_Size = Group_2_Check:getInitialSize()
 
  Ded_Count = 0
 
  for i , unit in pairs (Group_2_Check:getUnits()) do -- Here I'm assuming that getUnits will return a table containing all units in the group, regardless of whether they're dead
     
      if unit:getPoint() == nil then
          Ded_Count = Ded_Count + 1
      end
  end
 
  if Ded_Count == Initial_Size then
    -- The group is definitely dead
  end
end


Wrench 10-11-2019 12:28 AM

So for groups that die,
Code:

if not Group.getByName(group) then
will work, but late activated groups return the class for that one as well.
Code:

Group.getByName(group):isExist()
will return true.
Code:

#Group.getByName(group):getUnits()
will return the number of units assigned to the group.
Code:

grpunits = Group.getByName(group):getUnits()
for i=1,#grpunits do
        bool = Unit.isExist(grpunits[i])
        Wrench_Log:msg(bool)
end

will return true for all unspawned units in an unspawned group.
Code:

if Group.getByName(group) then
        local grp = Group.getByName(group)
        local grpunit = grp:getUnit(1)
        local pos1 = grpunit:getPoint()
        Wrench_Log:msg(pos1)
end

will return the unit's initial position from the ME.

So the only way I can think of is to spawn all groups at mission start, and then kill any you'd have otherwise set to late activation.

Grimes 10-11-2019 05:08 AM

Ah, didn't read the whole thing and realized you were using it while checking groups that haven't activated yet.

Probably though in a: https://wiki.hoggitworld.com/view/DCS_func_isActive check on one of the units.

Hardcard 10-11-2019 11:33 AM

Quote:

Originally Posted by Wrench (Post 4069159)
Code:

if Group.getByName(group) then
        local grp = Group.getByName(group)
        local grpunit = grp:getUnit(1)
        local pos1 = grpunit:getPoint()
        Wrench_Log:msg(pos1)
end

will return the unit's initial position from the ME.

This is weird ... :huh:

What about getPosition() ?

Does it actually return numeric values if you do something like:
Code:

if Group.getByName(group) then
        local grp = Group.getByName(group)
        local grpunit = grp:getUnit(1)
        local pos_1 = grpunit:getPosition()
         
        Wrench_Log:msg(pos_1.x.x)
        Wrench_Log:msg(pos_1.x.y)
        Wrench_Log:msg(pos_1.x.z)
       
        Wrench_Log:msg(pos_1.y.x)
        Wrench_Log:msg(pos_1.y.y)
        Wrench_Log:msg(pos_1.y.z)
       
        Wrench_Log:msg(pos_1.z.x)
        Wrench_Log:msg(pos_1.z.y)
        Wrench_Log:msg(pos_1.z.z)
end

I mean, if it returns orientation values for units that haven't been spawned, it won't make any sense to me :cry:

Wrench 10-12-2019 01:49 AM

It does.
It returns the orientation and position tables for where the unit *will* spawn.

Wrench 10-12-2019 02:15 AM

Okay, so I had to rework the script a bit to handle both cases, but it works once again.

Code:

function Wrench.respawn(group, drone, zones, msg)
        if Group.getByName(group) then
                local spawnGroup = ''
                Wrench_Log:msg('Wrench.respawn called for '..group)
                local grp = Group.getByName(group)
                local units = grp:getUnits()
                local activebool = false
                for i=1,#units do
                        if units[i]:isActive() and units[i]:isExist() then
                                activebool = units[i]:isActive()
                        end
                end
                if not activebool then
                        Wrench_Log:msg(group .. ' not found, respawning now.')
                        if msg then
                                trigger.action.outText('Respawning ' .. group, 10 , false)
                        end               
                        if zones then
                                spawnGroup = mist.respawnInZone(group, zones, true, 0)
                                local route = mist.getGroupRoute(group , true)
                                route[1] = nil
                                for i=2,#route do
                                        route[i-1] = route[i]
                                end
                                mist.scheduleFunction(mist.goRoute ,{spawnGroup["groupId"] ,route} ,timer.getTime() + 1 , 10 ,6 )
                        else
                                spawnGroup = mist.respawnGroup(group, true)
                        end
                        if drone == true then
                                local con = Group.getByName(group):getController()
                                con:setOption(AI.Option.Air.id.PROHIBIT_AA, true)
                        end
                       
                        grp:destroy()
                        return spawnGroup
                else
                        Wrench_Log:msg(group .. ' was found to be alive')
                end
        else
                Wrench_Log:msg(group .. ' not found, respawning now.')
                        if msg then
                                trigger.action.outText('Respawning ' .. group, 10 , false)
                        end               
                        if zones then
                                spawnGroup = mist.respawnInZone(group, zones, true, 0)
                                local route = mist.getGroupRoute(group , true)
                                route[1] = nil
                                for i=2,#route do
                                        route[i-1] = route[i]
                                end
                                mist.scheduleFunction(mist.goRoute ,{spawnGroup["groupId"] ,route} ,timer.getTime() + 1 , 10 ,6 )
                        else
                                spawnGroup = mist.respawnGroup(group, true)
                        end
                        if drone == true then
                                local con = Group.getByName(group):getController()
                                con:setOption(AI.Option.Air.id.PROHIBIT_AA, true)
                        end
                       
                        return spawnGroup
        end
               
end

Given the extra complexity, I should probably break it into two functions, but I just don't care enough. :music_whistling:

Hardcard 10-14-2019 12:13 AM

Quote:

Originally Posted by Wrench (Post 4070641)
It does.
It returns the orientation and position tables for where the unit *will* spawn.

Alright, that's both weird and potentially useful.


So, in the end, the answer is to combine isActive and isExist, right?

Code:

units[i]:isActive() and units[i]:isExist()

I'll need to keep this one in mind, thanks for the info! :thumbup:


All times are GMT. The time now is 01:48 PM.

Powered by vBulletin®.
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.