Jump to content

Recommended Posts

Posted

Hi,

 

I'm a noob to scripting and the the DCS Scripting Engine.  I've looked at the DCS Hoggit DCS Simulator Scripting Engine documentation, but QUICKLY get lost.

So, being a little lazy, I thought I would ask here to see if someone could point me in the correct direction.

What I would like to do is to change the number of units in a group that I have added via the ME, from 1, to 2, 3, or 4.  I know that it is EASILY done in  the ME.

1) can that be done via scripting?

2) Is there an existing function to do that with?

3) would it require setting up a unit table(??) for each unit to be added?

Again, just looking for pointers on where to start, or a simple "Can't be done".

Thanks,

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted
1 hour ago, AKA_Clutter said:

can that be done via scripting?

Yes - as long as you don’t require the unit types to change. The trick is to set up the maximum group (4 units) and then start deleting randomly to go to 3, 2 or 1 units.

Use Unit.destroy to remove the units

If I have time I can throw out a script tomorrow to do this, unless someone beats me to it (it’s not very difficult: create a function that deletes one random unit from any group that you pass it, and then create a second function that invokes the removing function a random number of times.

 

 

Posted

Thanks,  That points me in the right direction!

 

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted
6 hours ago, cfrag said:

Yes - as long as you don’t require the unit types to change. The trick is to set up the maximum group (4 units) and then start deleting randomly to go to 3, 2 or 1 units.

Use Unit.destroy to remove the units

If I have time I can throw out a script tomorrow to do this, unless someone beats me to it (it’s not very difficult: create a function that deletes one random unit from any group that you pass it, and then create a second function that invokes the removing function a random number of times.

 

 

hehe  - Works like a charm.

  Unit.getByName('A2A_LAG_1-3'):destroy() 
  Unit.getByName('A2A_LAG_1-4'):destroy()

 

That is a s long as I know the unit name.  That shouldn't be a problem with what I'm doing now, but I assume that you get it from just know the group name via a form of getGroup.  Is that on the correct track?

Thanks for pointing me in the correct direction!👏

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted

Tangentially related; if you spawn a new group and re-use a unit name and unit id then the unit from the existing group will be despawned. This is useful if you want that unit to go off and do their own task. 

Sadly we cannot join/split groups without spawning a new group. Nor give individual orders to individual ground 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

Posted
13 hours ago, AKA_Clutter said:

That is a s long as I know the unit name.  That shouldn't be a problem with what I'm doing now, but I assume that you get it from just know the group name via a form of getGroup.  Is that on the correct track?

It is. Here's one possible (over-engineered in hopes of being easier to understand) way to do it:


pickemoff = {}

function pickemoff.removeRandomUnit(theGroup)
	if not theGroup then return end -- sanity check
	-- get all units into a convenient array
	local allUnits = theGroup:getUnits()
	if not allUnits then return end -- sanity check 

	-- pick a random number from 1-# of units in group
	local uNum = #allUnits 
	if uNum < 1 then return end -- sanity check 
	local rndUnit = math.random(uNum)
	-- access this unit
	trigger.action.outText("Group " .. theGroup:getName() .. " has " .. uNum .. " units and I will remove unit " .. rndUnit, 30)
	local unitToRemove = allUnits[rndUnit]
	-- remove it from game 
	unitToRemove:destroy()
end

function pickemoff.removeRandomNumberOfUnitsFromGroupNamed(groupName)
	local theGroup = Group.getByName(groupName)
	if not theGroup then return end -- no such group 
	
	local size = theGroup:getSize() -- how many in group?
	
	-- determine how many to remove
	local rndNum = math.random(size) -- returns a random between 1 and groupsize
	if rndNum > size - 1 then rndNum = rndNum - 1 end -- sanity check

	-- remove rndNum units
	trigger.action.outText("I will now remove " .. rndNum .. " units from " ..  groupName, 30)
	for i=1, rndNum do
		pickemoff.removeRandomUnit(theGroup)
	end
end 

-- to invoke, simply call pickemoff.removeRandomNumberOfUnitsFromGroupNamed("somename")

The methods that may be of interest to you are Group.getByName(), Group.getSize() and Group.getUnits(). The rest is just showing off 🙂

I've put it in a demo mission. Use communications-->Other-->Remove Some units to remove a random number of units from your group.

 

pickemoff.miz

Posted

GREAT!!  Thanks!!

 

I'll dig into this over tge next few days.  This looks like it contains a lot I csn learn from.

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

  • Recently Browsing   0 members

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