Jump to content

Recommended Posts

Posted (edited)

Is there any way to find out what groups are in a zone?

Or if I find the units in a zone, can I create a table of groups those units are in?

I'd like to make a script that will spawn units by target area, and rather than putting the names in the script by hand, I'd like to use something like GetUnitsInZones to find them all automatically, using a trigger zone from the ME.

 

Any ideas?

 

Also, is it possible to use one respawn command to respawn a table of groups? That would make life a lot easier as well.

Thanks.

Edited by Wrench
Added second question
  • 4 weeks later...
Posted

I have to self bump, but I still can't figure this out.

I don't see any way to find what group a unit belongs to, or something like this would work:

local redunits = mist.makeUnitTable({'[red][vehicle]'})
local zone_names = {'AO_1'}
local units_AO_1 = mist.getUnitsInZones(redunits, zone_names, 'cylinder')

 

That gives me a list of units in the zone, but I don't see any way find what group a unit belongs to.

Posted
I have to self bump, but I still can't figure this out.

I don't see any way to find what group a unit belongs to, or something like this would work:

local redunits = mist.makeUnitTable({'[red][vehicle]'})
local zone_names = {'AO_1'}
local units_AO_1 = mist.getUnitsInZones(redunits, zone_names, 'cylinder')

 

That gives me a list of units in the zone, but I don't see any way find what group a unit belongs to.

 

Anytime you have a unit name you can use that information to find its group. You could either directly use the scripting functions or search the mist.DB tables to find whatever you are looking for.

 

local redunits = mist.makeUnitTable({'[red][vehicle]'})
local zone_names = {'AO_1'}
local units_AO_1 = mist.getUnitsInZones(redunits, zone_names, 'cylinder')
local groups = {}
local groupIndex = {}
for i = 1, #units_AO_1 do -- iterate through the units
   if not groups[unit.getGroup(units_AO_1[i]):getName] then 
       groups[unit.getGroup(units_AO_1[i]):getName] = true
       groupIndex[groupIndex + 1] = groups[unit.getGroup(units_AO_1[i]):getName]
   end
end

 

So it is iterating through the units returned and checking if the group name was added to the groups table. If it isn't, then it adds it to the table. I also added the groupIndex table so it gives you another option to iterate the tables. It is basically the difference of:

groups = {
   ['groupA'] = true,
   ['groupB'] = true,
   ['groupC'] = true,
}

groupIndex = {
   [1] = 'groupA',
   [2] = 'groupB',
   [3] = 'groupC',
}

  • 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

Posted

Wow, Grimes.

Parts of that are simple enough to make me feel dumb.

Parts of that are things I had no idea where a thing, which makes me feel dumb. :doh:

 

Either way, thanks a lot, dear sir.

Rep most deservedly inbound.

-Wrench

Posted (edited)

Hey buddy,

I've got a bit of a problem here.

I'm not very familiar with lua (i'm trying to get there but it's very unintuitive for me)

I'm getting an error like this:

[string
"C:\etc..."]:
7:function arguments expected near ']'

I know what it's saying, but I'm not sure what arguments it's expecting.

From what I see it's not accepting the as a valid argument or wants something else.

Any chance I could get a hand debugging this?

 

I hate to have to ask for help at every step, but I can't wrap my head around lua for some reason. I've done ARMA script in the past, and have made some pretty serious SQF script, but C type languages come pretty naturally to me.

 

Anyway, thanks for the help so far.

 

**edit**

Looking into this some more, I think I was a little off base.

it seems that given : is meant to call a function, the syntax is messed up, and it's expecting the arguments for "getname" after the call, not before?

Like I said, lua is really not my native language. :music_whistling:

Edited by Wrench
Posted

Brainfarted on adding the () function call.

 

   if not groups[unit.getGroup(units_AO_1[i]):getName()] then 
       groups[unit.getGroup(units_AO_1[i]):getName()] = true
       groupIndex[groupIndex + 1] = groups[unit.getGroup(units_AO_1[i]):getName()]

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 (edited)

Okay, I figured it out after much wiki-ing.

 if not groups_AO_1[unit.getGroup(units_AO_1[i]):getName()] then 

works fine.

I basically wanted to make it so you can use the radio to respawn them, but mist gives me errors.

I've tried various syntax, and I keep getting an error message that says the group name is "a nil value"

 

I've tried

for i = 1, #groups_AO_1 do
	local myGroup = Group.getByName(groups_AO_1[i])
	mist.respawnGroup (myGroup, true)
end

and

for i = 1, #groups_AO_1 dops_AO_1[i])
Group.getByName(groups_AO_1[i]):mist.respawnGroup ()
end

as well as some others I can't even remember.

things like

Group.getByName(groups_AO_1[i]):getController():setOnOff(false)
local myGroup = Group.getByName(groups_AO_1[i])
Group.destroy(myGroup)

work fine, so I'm not sure what mist is having trouble with.

 

To be clear, I've tried running that code in-line for debugging, as well as using "missionCommands.addCommand" and calling it with the radio. Same result either way.

 

**edit**

Just saw I didn't notice you'd responded. Thanks. Probably would have saved me some work if I had checked back. lol

Edited by Wrench
Posted

You are confusing some of the syntax.

 

Group.getByName('whatever') is returning a group object. Which you can read up on here. You can run different member functions on the group in two ways. For example Group.destroy(myGroup) and myGroup:destroy() do exactly the same thing. When you use myGroup:whatever() it is placing the group object as the first input value for that function.

 

Mist is entirely separate from the objects, though some functions do accept an object as an input value. So this: Group.getByName(groups_AO_1):mist.respawnGroup () simply doesn't work because its looking for mist.respawnGroup() within the group object which it obviously can't find.

 

mist.respawnGroup (myGroup, true) almost works because the first value for respawnGroup is a string of the groups name and not a group object. You got the right idea, your just giving it the wrong value. So you can change it to mist.respawnGroup(groups_AO_1, true) and it would work. It'd be a little redundent but you can also think of it as mist.respawnGroup (myGroup:getName(), true)

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

  • Recently Browsing   0 members

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