Jump to content

Using MIST to spawn late activation groups


104th_Maverick

Recommended Posts

Im trying to build a mission that has all SAMS set to late activation, I want these SAMS to activate once a player gets within a certain zone.

 

I'm trying to use MIST to spawn the SAM groups in however when I use -

 if not Group.getByName('R/QESHM/SA2/2') then
   mist.respawnGroup('R/QESHM/SA2/2', true)
end

 

This only works if the unit is NOT set to Late Activation.  To get it to work I have to spawn the group in at the start of the mission then use -

trigger.action.deactivateGroup(Group.getByName'R/QESHM/SA2/2')

To turn the SAM group off then use the above MIST trigger to get it to spawn in.

 

Is there anyway around this?  Can I have the group just set to late activation so it doesn't spawn in at the mission start and can be spawned by MIST when a player enters a zone?

Or do I have to use the DCS triggers for the initial spawn in?

[sIGPIC][/sIGPIC]



104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad

Link to comment
Share on other sites

First, respawn is used for units that was destroyed.

Here you have only late activation, use :

 if not Group.getByName('R/QESHM/SA2/2') then
    trigger.action.activateGroup('R/QESHM/SA2/2')
end

https://wiki.hoggitworld.com/view/DCS_func_activateGroup

 

Check if unit is in zone with this MIST function: https://wiki.hoggitworld.com/view/MIST_units_in_zones (carefull, it is UNIT name, not Group Name)

Call the activate trigger function with a scheduler: https://wiki.hoggitworld.com/view/MIST_scheduleFunction

do

 mist.flagFunc.units_in_zones{ 
   units = {'R/QESHM/SA2/2-unitname'}, 
   zones = {'YourZoneNAme'}, 
   flag = 100, 
   zone_type = 'sphere' 
 }


function activateGroup
    if trigger.misc.getUserFlag(100) == 1 then
          trigger.action.activateGroup('R/QESHM/SA2/2')
    end
end

mist.scheduleFunction(activateGroup, {}, timer.getTime() + 10, 900, timer.getTime() + 3600)

end

So, the MIST function will check if your UNIT is in zone, and if it is will set a flag true.

Then check the flag and activate the group.

Hope it helps

  • Like 1
Link to comment
Share on other sites

Thank you so much sir!

The respawn part makes perfect sense now, sorry, I'm a total scripting noob.  Built 100s of missions but always used the in game editor GUI, I'm trying to use scripting more now and the struggle is real.

  • Like 1

[sIGPIC][/sIGPIC]



104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad

Link to comment
Share on other sites

7 hours ago, dark_wood said:

First, respawn is used for units that was destroyed.

Here you have only late activation, use :

 if not Group.getByName('R/QESHM/SA2/2') then
    trigger.action.activateGroup('R/QESHM/SA2/2')
end

https://wiki.hoggitworld.com/view/DCS_func_activateGroup

 

 

 

Im running into an interesting issue with this mate.

When I run -

if not Group.getByName('R/QESHM/SA2/2') then
trigger.action.activateGroup('R/QESHM/SA2/2')
end

With the group set to Late Activation, they still don't spawn.

 

The only way I can get them to spawn in by adding a deactivateGroup trigger after the activateGroup trigger (even in the same DO action).

 

So if I do -

if not Group.getByName('R/QESHM/SA2/2') then
trigger.action.activateGroup('R/QESHM/SA2/2')
end

trigger.action.deactivateGroup(Group.getByName'R/QESHM/SA2/2')

then

if not Group.getByName('R/QESHM/SA2/2') then
mist.respawnGroup('R/QESHM/SA2/2', true)
end

 

The group spawns.  If I don't do it this way, they don't activate at all.

 

Am I doing something wrong, or will I have to use this activate, deactivate and respawn logic?

 

I have attached a small mission with the trigger set up to show the issue.

Spawn_Test.miz

[sIGPIC][/sIGPIC]



104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad

Link to comment
Share on other sites

if not Group.getByName('R/QESHM/SA2/2') then

There are a few problems and things you need to understand with scripting (triggers also) and that statement. First off it is checking if that group object exists. Unfortunately the state of a group object has changed over the years. It used to be if all of the units in the group were dead then the group object wouldn't exist and it was like that for a really long time. That may have changed, but the gist is that it isn't the surefire check to know if a group and the units within are alive or dead. 

However in this case it doesn't matter at all because groups set to "late activation" still exist. So that function will always return the group object. Likewise the trigger conditions Group Alive and Group Dead both see a late activated group as alive. Which is why you are finding that you need to deactivate the group in order for it to work. That said you can just call the respawn group function at anypoint without checking if the group is first dead and it'll respawn. 

 

If you are intent on checking the state of the group, especially if the units are dead to respawn it, then you can use mist.getGroupIsDead for the check. It does the getByName to see if the group can be accessed and it checks the size of the table returned by Group.getUnits to verify that at least 1 unit is alive. 

if mist.groupIsDead('R/QESHM/SA2/2') == true then
   mist.respawnGroup('R/QESHM/SA2/2', true)
end

 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

@Grimes @toutenglisse @dark_wood

Gentlemen thank you so much for taking the time to get back to me, things are becoming clearer now and the possibilities are becoming exciting, I'm definitely catching the scripting bug!

Next question, is there anyway I can respawn only the units that have not been killed by the enemy team.

Example.

I have an SA2 site (R/QESHM/SA2/2), I want to spawn that in when a client gets close as per your instructions above.   However say that client then kills two units in that SA2 group then flys away.  I want to be able to despawn the SA2 group once the client leaves the zone, then if a client comes back into the zone respawn the SA2 group but with the two units that were previously killed missing from the group.

Is this possible?

[sIGPIC][/sIGPIC]



104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad

Link to comment
Share on other sites

@104th_Maverick I have combined all the snippets, this is the result:

function respawnSam()
    --unit is in zone
    if trigger.misc.getUserFlag(100) == 1 then
          trigger.action.activateGroup('R/QESHM/SA2/2')
		  
		   --unit is out of zone
		  elseif trigger.misc.getUserFlag(100) == 0 then
		  
		  --get initial SAM group size
		  local initialSize = Group.getByName('R/QESHM/SA2/2'):getInitialSize()
		  --get actual size
		  local actualSize = Group.getByName('R/QESHM/SA2/2'):getSize()
		  
		  --if units are missing/destroyed respawn
		  if actualSize < initialSize then
		  --remove damaged group
		    Group.getByName('R/QESHM/SA2/2'):destroy()
			--respawn a new one
			mist.respawnGroup('R/QESHM/SA2/2', true)
		  end
		  
		  
    end
end

do
--check unit is in zone
 mist.flagFunc.units_in_zones{ 
   units = {'R/QESHM/SA2/2-unitname'}, 
   zones = {'YourZoneNAme'}, 
   flag = 100, --flag on when unit is in zone
   toggle  = true --set flag false if unit is out of zone
   interval = 10, --condition will be checked each 10 seconds
   zone_type = 'sphere' 
 }
 
 --start calling function after 10 seconds, recall it after each 60 seconds, end process after 60 minutes
 mist.scheduleFunction(respawnSam(), {}, timer.getTime() + 10, 60, timer.getTime() + 3600)
end

I'm not very sure if i used correct the Group.getByName('R/QESHM/SA2/2'):destroy() syntax

I really hope is working, I did it at work, without DCS to test it - even if is not 100%, you can make an idea, maybe @Grimes and @toutenglisse have better ideas/improvements to help you 🙂

Cheers


Edited by dark_wood
  • Like 1
Link to comment
Share on other sites

5 hours ago, 104th_Maverick said:

...Next question, is there anyway I can respawn only the units that have not been killed by the enemy team...

Yes it is possible, using mist.dynAdd instead of respawn depending on the state of the group (when despawning, if group wipedout -> respawn, else collect group data for remaining units and dynAdd).

Here a .miz example. Uses 2 functions (and latest mist), ActGroup(GroupName) and DeActGroup(GroupName). There are 2 late activated SAM2 groups side by side, 2nd is hidden on map.

Time 2 sec : ActGroup() for both groups

Time 5 sec : Group1 gets some units destroyed, Group2 is wipedout (deactivated)

Time 8 sec : DeActGroup() for both groups

Time 11 sec ActGroup() for both groups (Group1 gets dynAdd with remaining units, Group2 is respawned)

test-reSpawn-remaining-Units.miz


Edited by toutenglisse
  • Like 1
Link to comment
Share on other sites

55 minutes ago, toutenglisse said:

Yes it is possible, using mist.dynAdd instead of respawn depending on the state of the group (when despawning, if group wipedout -> respawn, else collect group data for remaining units and dynAdd).

Here a .miz example. Uses 2 functions (and latest mist), ActGroup(GroupName) and DeActGroup(GroupName). There are 2 late activated SAM2 groups side by side, 2nd is hidden on map.

Time 2 sec : ActGroup() for both groups

Time 5 sec : Group1 gets some units destroyed, Group2 is wipedout (deactivated)

Time 8 sec : DeActGroup() for both groups

Time 11 sec ActGroup() for both groups (Group1 gets dynAdd with remaining units, Group2 is respawned)

test-reSpawn-remaining-Units.miz 74.31 kB · 2 downloads

 

 

Wow!  Thank you, I will test this out over the weekend and let you know how I get on once I have finished moving house.

[sIGPIC][/sIGPIC]



104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad

Link to comment
Share on other sites

  • Recently Browsing   0 members

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