Base Capture
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Base Capture
Refreshing this script from a while ago and have it working 90%, need a bit of help getting it over the line though.
I've set up a 'unit remains in area' trigger around an airbase that the player needs to capture. When the script runs the base elements change sides and a new group is made.
What doesn't happen is the individual base elements don't get added to the new base so it ends up that everything is on the side it is supposed to be but the base is sitting there and all the hangars, runways etc are also there as individual units. This isn't the end of the world but it should work.
---Airport captured
local base = ScenEdit_GetUnit( { name='Bornholm/Ronne', side='NATO' })
--print(base.group.unitlist);print(base.guid)
local glist =base.group.unitlist
local inc
local u
for inc =2, #glist
do
local id = glist[inc]
u = ScenEdit_GetUnit( { name=id }); u.group=''
ScenEdit_SetUnitSide({side="NATO", guid=id, newside="Captured"})
end
-- suppress the first item as it is part of group
table.remove( glist, 1 )
local facilities = table.concat(glist, ',' )
ScenEdit_SetKeyValue( "FaciltiesAtSocotra", facilities )
u = ScenEdit_GetUnit({ name=base.group.unitlist[1]})
ScenEdit_SetUnitSide({side="NATO", name=u.guid, newside="Captured"})
-- new group
u.group = 'Bornholm/Ronne (captured)'
base = ScenEdit_GetUnit( { name='Bornholm/Ronne (captured)', side='Captured' })
ScenEdit_SetKeyValue( "BaseAtBornholm", base.guid )
I've set up a 'unit remains in area' trigger around an airbase that the player needs to capture. When the script runs the base elements change sides and a new group is made.
What doesn't happen is the individual base elements don't get added to the new base so it ends up that everything is on the side it is supposed to be but the base is sitting there and all the hangars, runways etc are also there as individual units. This isn't the end of the world but it should work.
---Airport captured
local base = ScenEdit_GetUnit( { name='Bornholm/Ronne', side='NATO' })
--print(base.group.unitlist);print(base.guid)
local glist =base.group.unitlist
local inc
local u
for inc =2, #glist
do
local id = glist[inc]
u = ScenEdit_GetUnit( { name=id }); u.group=''
ScenEdit_SetUnitSide({side="NATO", guid=id, newside="Captured"})
end
-- suppress the first item as it is part of group
table.remove( glist, 1 )
local facilities = table.concat(glist, ',' )
ScenEdit_SetKeyValue( "FaciltiesAtSocotra", facilities )
u = ScenEdit_GetUnit({ name=base.group.unitlist[1]})
ScenEdit_SetUnitSide({side="NATO", name=u.guid, newside="Captured"})
-- new group
u.group = 'Bornholm/Ronne (captured)'
base = ScenEdit_GetUnit( { name='Bornholm/Ronne (captured)', side='Captured' })
ScenEdit_SetKeyValue( "BaseAtBornholm", base.guid )
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
I don't understand what's so special about so special about index 1 in glist?
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
---Airport capturedORIGINAL: Gunner98
Refreshing this script from a while ago and have it working 90%, need a bit of help getting it over the line though.
I've set up a 'unit remains in area' trigger around an airbase that the player needs to capture. When the script runs the base elements change sides and a new group is made.
What doesn't happen is the individual base elements don't get added to the new base so it ends up that everything is on the side it is supposed to be but the base is sitting there and all the hangars, runways etc are also there as individual units. This isn't the end of the world but it should work.
---Airport captured
local base = ScenEdit_GetUnit( { name='Bornholm/Ronne', side='NATO' })
--print(base.group.unitlist);print(base.guid)
local glist =base.group.unitlist
local inc
local u
for inc =2, #glist
do
local id = glist[inc]
u = ScenEdit_GetUnit( { name=id }); u.group=''
ScenEdit_SetUnitSide({side="NATO", guid=id, newside="Captured"})
end
-- suppress the first item as it is part of group
table.remove( glist, 1 )
local facilities = table.concat(glist, ',' )
ScenEdit_SetKeyValue( "FaciltiesAtSocotra", facilities )
u = ScenEdit_GetUnit({ name=base.group.unitlist[1]})
ScenEdit_SetUnitSide({side="NATO", name=u.guid, newside="Captured"})
-- new group
u.group = 'Bornholm/Ronne (captured)'
base = ScenEdit_GetUnit( { name='Bornholm/Ronne (captured)', side='Captured' })
ScenEdit_SetKeyValue( "BaseAtBornholm", base.guid )
Code: Select all
local function AirportCaptured(base,oldSide,newSide)
if(base ==nil) then print('AirportCaptured(): Base specified was nil.') return; end;
local glist =base.group.unitlist
if((glist ==nil) or #glist == 1) then print('AirportCaptured(): Existing glist is empty.') return; end;
local u; local facilities = {}
for k,v in pairs(glist) do -- for each in glist do where k=key v=value\object.
u = ScenEdit_GetUnit( { guid=v});
if((u ~=nil) and u.type ~= "Group") then -- sanity check
u.group='' --clean the group.
ScenEdit_SetUnitSide({side=oldSide, guid=u.guid, newside=newSide}) --reset the side.
u.group='Bornholm/Ronne (captured)' -- assign the new group.
if(k == 1) then -- if the first entry
ScenEdit_SetKeyValue( "BaseAtBornholm", u.guid) -- store first unit guid?
else
table.insert(facilities,{{name=u.name,guid=u.guid}}) --populate table for all but #1? I don't follow, but this does that.
end
end
u = nil;
end --ending loop
ScenEdit_SetKeyValue( "FaciltiesAtSocotra", facilities) -- store facilities table generated? not sure can do that.
end --end function
--
local b = ScenEdit_GetUnit( { name='Bornholm/Ronne', side='NATO' }) --I'm assuming the name is name of the original group.
AirportCaptured(b,'NATO','Captured');
Not tested just writing that here as I go.
Edited: to correct some errors
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
Better version and tested, and I think I figured out you just wanted to store the NEW group guid for later reference I guess?
edited to change Red to NATO in a line (sorry my tests were with red\blue sides)
Code: Select all
local function AirportCaptured(base,oldSide,newSide,newGroupname)
if(base ==nil) then print('AirportCaptured(): Base specified was nil.') return; end;
local glist =base.group.unitlist
if((glist ==nil) or #glist == 1) then print('AirportCaptured(): Existing glist is empty.') return; end;
local u; local facilities ='';
for k,v in pairs(glist) do -- for each in glist do where k=key v=value\object.
u = ScenEdit_GetUnit( {guid=v} );
if((u ~=nil) and u.type ~= "Group") then -- sanity check
u.group='' --clean the group.
ScenEdit_SetUnitSide({side=oldSide, guid=u.guid, newside=newSide}) --reset the side.
u.group= newGroupname -- assign the new group.
if(k == 1) then -- if the first entry
ScenEdit_SetKeyValue('FaciltiesAtSocotra',tostring(u.guid)) --store the first unit guid.
end
end
u = nil;
end --ending loop
ScenEdit_SetKeyValue( "BaseAtBornholm", (ScenEdit_GetUnit({side=newSide,name=newGroupname})).guid) -- store group guid, for some purpose?
end --end function
local b = ScenEdit_GetUnit( { name='Bornholm/Ronne', side='NATO'}) --I'm assuming the name is name of the original group.
AirportCaptured(b,'NATO','Captured','Bornholm/Ronne (captured)');
-- flip it back after the fact.
--b = ScenEdit_GetUnit( {guid=ScenEdit_GetKeyValue(BaseAtBornholm)})
--AirportCaptured(b,b.side,'NATO','Bornholm/Ronne');
edited to change Red to NATO in a line (sorry my tests were with red\blue sides)
- michaelm75au
- Posts: 12465
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Base Capture
I thought that there was a method to change side - ScenEdit_SetUnitSide.
It should be able to handle changing the side of the units in the group.
It should be able to handle changing the side of the units in the group.
Michael
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
ORIGINAL: michaelm75au
I thought that there was a method to change side - ScenEdit_SetUnitSide.
It should be able to handle changing the side of the units in the group.
Yes it works fine.
ScenEdit_SetUnitSide({side='Red', name='Bornholm/Ronne', newside='Blue'}) --reset the side.
ScenEdit_SetUnit({side='Blue', name='Bornholm/Ronne', newname='Bornholm/Ronne (captured2)'})--rename after change
I'm assuming there was something else that was trying to be stored during the process or something more too it.
RE: Base Capture
Thank you very much - first method works perfectly.
Second one leaves a copy witch I believe is only a shadow contact but weirdly the shadow is marked with an 'A' for allied.
the screenclip is in Unit view and I've moved one blue unit slightly so you can see what is left.
Thank you again.
B

Second one leaves a copy witch I believe is only a shadow contact but weirdly the shadow is marked with an 'A' for allied.
the screenclip is in Unit view and I've moved one blue unit slightly so you can see what is left.
Thank you again.
B

- Attachments
-
- bornholm.jpg (21.53 KiB) Viewed 687 times
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
I didn't notice the contact problem with either during trying them... that said it was mostly all with the game paused and autodetectable=true on the units so I may not have noticed any lingering contact problems if the units were discoverable.
When you say first method, you mean the larger script and flip one way works, but flip back does not? or That it does work find including no left behind contacts.
Or
You mean the simpler process michaelm75au brought up and sampled in post#6 'works' but leaves the allied 'contacts'?
Sorry, I'm easily confused sometimes. If latter that's a pretty interesting find, particularly the allied part.
When you say first method, you mean the larger script and flip one way works, but flip back does not? or That it does work find including no left behind contacts.
Or
You mean the simpler process michaelm75au brought up and sampled in post#6 'works' but leaves the allied 'contacts'?
Sorry, I'm easily confused sometimes. If latter that's a pretty interesting find, particularly the allied part.
RE: Base Capture
mean the larger script and flip one way works, but flip back does not? or That it does work find including no left behind contacts.
That's the one that works fine. Thank you
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
BTW I recently ran into that ghosted contact issue when doing a on-detect flip side sort of thing.
If you know the specific unit it was ghosting, and you know the realname, you can easily run a timer 5 seconds later to remove it (them), if the ghost is not precise id'd.
If you know the specific unit it was ghosting, and you know the realname, you can easily run a timer 5 seconds later to remove it (them), if the ghost is not precise id'd.
Code: Select all
--ScanForGhostedContactEvent cycles and runs:
local function CleanUpGhostedContact(side,realguid,realname)
local sd = VP_GetSide( {name=side} );
for k,v in pairs(sd.contacts) do
if( v.name ~= realname) then --ghosted mobile # / generic name.
local ct = ScenEdit_GetContact({side=side,guid=v.guid})
if( (ct ~=nil) and ct.actualunitid== realguid and ct.name ~= realname) then
--^ contact ref's the real guid as the unit but doesn't have real units name. so is right one.
ct:DropContact(); --- drop the ghosted contact that gets created during the flip;
break; --leave out the break if you're changing this to do a whole list.
end
end
end --ends contact checking for
end
CleanUpGhostedContact('United States',gKH.SceneGlobals.AmericanHikersGUID,gKH.SceneGlobals.AmericanHikersName)
ScenEdit_SetEvent('ScanForGhostedContact', {IsActive=false}); --Make sure we disable ourself now. the flipper script enabled us.
- michaelm75au
- Posts: 12465
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Base Capture
I think I see the issue.
The SetUnitSide() cleans up contacts but only on the new side you are moving to. It isn't looking to see if that unit on the old side had contacts on the other sides in the scenario (as could be the case with friendly posture showing a 'A').
I can't seem to be able to reproduce this no matter what side postures I set up?
If you have a case of a base changing sides, and it leaves 'ghosts', can you please post a save before it changes side?
The SetUnitSide() cleans up contacts but only on the new side you are moving to. It isn't looking to see if that unit on the old side had contacts on the other sides in the scenario (as could be the case with friendly posture showing a 'A').
I can't seem to be able to reproduce this no matter what side postures I set up?
If you have a case of a base changing sides, and it leaves 'ghosts', can you please post a save before it changes side?
Michael
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
I can get you one seconds b4 it happens of a slightly different but I think the same thing that doesn't involve a base, just a unit which becomes allied after detection. Will that do?

The save is a few seconds before the detection in the pic will happen and the above result since a SetSidePosture is called during the detection moving it from neutral to allied\friendly. If you need to reset it, just move grasshopper one 10 miles south, delete hiker unit, use the special actions 'reset hiker posture', and run RecreateCustomAmericanHikers, and you should be able to re-trigger it. I've disabled the code that normal runs to manually find the ghost and remove it 5 seconds after detection.
It's funny if you try to move the contact out of the way it's tied to the real unit lol.

The save is a few seconds before the detection in the pic will happen and the above result since a SetSidePosture is called during the detection moving it from neutral to allied\friendly. If you need to reset it, just move grasshopper one 10 miles south, delete hiker unit, use the special actions 'reset hiker posture', and run RecreateCustomAmericanHikers, and you should be able to re-trigger it. I've disabled the code that normal runs to manually find the ghost and remove it 5 seconds after detection.
It's funny if you try to move the contact out of the way it's tied to the real unit lol.
- Attachments
-
- Leathernec..al2_repo.zip
- (278.74 KiB) Downloaded 26 times
- michaelm75au
- Posts: 12465
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Base Capture
The event is using SetSidePosture() which won't do any side switching; the original thread issue was with using SetUnitSide().
What is happening here is:
1. There is a mobile contact detected by US but whose side the unit belongs to is unknown.
2. The event fires and makes the actual unit 'allied' - friendly posture to both sides (US and Hikers), which makes the unit visible. [There are no contact changes specifically connected to this Lua function as there is with SetUnitSide().]
3. The original contact is not touched by the posture change.
However, I had thought that there was a 'cleanup' process that ran every few seconds that cleared contacts for 'allied' units in order to correct this particular 'ghosting' affect.
I'll look at that over the weekend.
What is happening here is:
1. There is a mobile contact detected by US but whose side the unit belongs to is unknown.
2. The event fires and makes the actual unit 'allied' - friendly posture to both sides (US and Hikers), which makes the unit visible. [There are no contact changes specifically connected to this Lua function as there is with SetUnitSide().]
3. The original contact is not touched by the posture change.
However, I had thought that there was a 'cleanup' process that ran every few seconds that cleared contacts for 'allied' units in order to correct this particular 'ghosting' affect.
I'll look at that over the weekend.
Michael
RE: Base Capture
ORIGINAL: michaelm75au
The event is using SetSidePosture() which won't do any side switching; the original thread issue was with using SetUnitSide().
What is happening here is:
1. There is a mobile contact detected by US but whose side the unit belongs to is unknown.
2. The event fires and makes the actual unit 'allied' - friendly posture to both sides (US and Hikers), which makes the unit visible. [There are no contact changes specifically connected to this Lua function as there is with SetUnitSide().]
3. The original contact is not touched by the posture change.
However, I had thought that there was a 'cleanup' process that ran every few seconds that cleared contacts for 'allied' units in order to correct this particular 'ghosting' affect.
I'll look at that over the weekend.
Just FYI - I have seen this same phenomenon in my Fire Arrow scenario which is posted on the Mods/Scenarios page
"We have met the enemy and they are ours" - Commodore O.H. Perry
- michaelm75au
- Posts: 12465
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Base Capture
This is part of the housekeeping I mentioned before.
Yea, a contact with a 'unknown' side is not being 'adjusted' when the posture changes.
Plus auto-detected contacts also look like they are not 'adjusted' on a posture change.
This needs a bit of thought as you just don't want all unknown contacts to be dropped when posture changes.
This would most likely affect both the side and posture change issues mentioned in this thread.
Yea, a contact with a 'unknown' side is not being 'adjusted' when the posture changes.
Plus auto-detected contacts also look like they are not 'adjusted' on a posture change.
This needs a bit of thought as you just don't want all unknown contacts to be dropped when posture changes.
This would most likely affect both the side and posture change issues mentioned in this thread.
Michael
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Base Capture
ORIGINAL: michaelm75au
This is part of the housekeeping I mentioned before.
Yea, a contact with a 'unknown' side is not being 'adjusted' when the posture changes.
Plus auto-detected contacts also look like they are not 'adjusted' on a posture change.
This needs a bit of thought as you just don't want all unknown contacts to be dropped when posture changes.
This would most likely affect both the side and posture change issues mentioned in this thread.
...
affect.
Yup it's a complicated issue, not sure how you solve for it entirely.
