Jump to content

Hoggit Wiki style respawn script no longer functional


Wrench

Recommended Posts

I've used the conditional from the Hoggit wiki for many years to control a respawn script, here:

 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?

Link to comment
Share on other sites

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.

 

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

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

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.

Link to comment
Share on other sites

@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):

 

if Unit.getByName(unitname) == nil or Unit:isExist() == false then
  [color="Blue"]-- Respawn the unit because it's dead[/color]
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:

 

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 [color="Blue"]-- Here I'm assuming that [i][b]getUnits[/b][/i] will return a table containing all units in the group, regardless of whether they're dead[/color]
      
      if unit:getPoint() == nil then
         Ded_Count = Ded_Count + 1
      end
  end
  
  if Ded_Count == Initial_Size then
    [color="Blue"] -- The group is definitely dead[/color]
  end
end


Edited by Hardcard
Link to comment
Share on other sites

So for groups that die,

if not Group.getByName(group) then

will work, but late activated groups return the class for that one as well.

Group.getByName(group):isExist()

will return true.

#Group.getByName(group):getUnits()

will return the number of units assigned to the group.

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.

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.


Edited by Wrench
Link to comment
Share on other sites

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.

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

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:

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:


Edited by Hardcard
Link to comment
Share on other sites

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

 

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:

Link to comment
Share on other sites

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?

 

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

 

 

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

Link to comment
Share on other sites

  • Recently Browsing   0 members

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