Hoggit Wiki style respawn script no longer functional - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 10-09-2019, 06:01 AM   #1
Wrench
Member
 
Join Date: Feb 2015
Posts: 606
Default 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?
__________________
Carrier Script.
Wrench is offline   Reply With Quote
Old 10-09-2019, 06:23 AM   #2
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 8,052
Default

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
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 10-09-2019, 10:26 PM   #3
Wrench
Member
 
Join Date: Feb 2015
Posts: 606
Default

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.
__________________
Carrier Script.
Wrench is offline   Reply With Quote
Old 10-10-2019, 02:50 AM   #4
Hardcard
Member
 
Hardcard's Avatar
 
Join Date: May 2013
Posts: 654
Default

@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
__________________

Last edited by Hardcard; 10-11-2019 at 10:52 AM.
Hardcard is offline   Reply With Quote
Old 10-11-2019, 12:28 AM   #5
Wrench
Member
 
Join Date: Feb 2015
Posts: 606
Default

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.
__________________
Carrier Script.

Last edited by Wrench; 10-11-2019 at 12:34 AM.
Wrench is offline   Reply With Quote
Old 10-11-2019, 11:33 AM   #6
Hardcard
Member
 
Hardcard's Avatar
 
Join Date: May 2013
Posts: 654
Default

Quote:
Originally Posted by Wrench View Post
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 ...

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
__________________

Last edited by Hardcard; 10-11-2019 at 11:39 AM.
Hardcard is offline   Reply With Quote
Old 10-11-2019, 05:08 AM   #7
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 8,052
Default

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.
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 10-12-2019, 01:49 AM   #8
Wrench
Member
 
Join Date: Feb 2015
Posts: 606
Default

It does.
It returns the orientation and position tables for where the unit *will* spawn.
__________________
Carrier Script.
Wrench is offline   Reply With Quote
Old 10-14-2019, 12:13 AM   #9
Hardcard
Member
 
Hardcard's Avatar
 
Join Date: May 2013
Posts: 654
Default

Quote:
Originally Posted by Wrench View Post
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!
__________________
Hardcard is offline   Reply With Quote
Old 10-12-2019, 02:15 AM   #10
Wrench
Member
 
Join Date: Feb 2015
Posts: 606
Default

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.
__________________
Carrier Script.
Wrench is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 06:45 PM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.