Jump to content

Recommended Posts

Posted

I'm relatively new to the mission editor and I was trying to make a way so I can land my plane on a base with no enemy units on it to change its coalition to mine. I've tried many different ways but none I tired worked, so if you know a way i'd greatly appreciate it. 

Posted
9 hours ago, gammaxy said:

I can land my plane on a base with no enemy units on it to change its coalition to mine.

This is currently not supported in vanilla DCS. In order to capture a base, you need 'boots on the ground' - infantry: a solider or a vehicle. So what you need is a small script that, when you land on an airfield, it spawns a unit of your coalition inside the 2km airfield zone, and if that unit is the only ground unit, you'll capture the zone. 

If I have the time, I'll try and come up with a small script that can do that for you.

  • Solution
Posted
10 hours ago, gammaxy said:

so if you know a way i'd greatly appreciate it. 

Here's the script, simply paste it into a DOSCRIPT Action on MISSION START. It will monitor all your landings, and if you (a player) land on an airfield that does not belong to your faction, it puts an infantry soldier close to your touch-down point in an attempt to capture the base. You'll see a message appear when you were successful.

Script:

Spoiler

grabber = {}
grabber.version = "1.0.0"
grabber.uuid = 0

function grabber.getUUID()
    grabber.uuid = grabber.uuid + 1 
    return grabber.uuid 
end
--
-- script to "grab" an airfield after landing a plane 
--
function grabber.getClosestAirbase(theUnit)
    local p = theUnit:getPoint()
    local all = world.getAirbases()
    local dist = math.huge
    local closest = nil 
    for idx, theBase in pairs(all) do 
        local ap = theBase:getPoint()
        local dx = ap.x - p.x 
        local dz = ap.z - p.z
        local d = math.sqrt(dx * dx + dz * dz)
        if d < dist then 
            dist = d 
            closest = theBase
        end
    end
    return closest
end

function grabber:onEvent(event)
    if not event then return end 
    if not event.initiator then return end 
    if event.id == 10 then 
        trigger.action.outText("Airfield " .. event.place:getName() .. " was captured by " .. event.initiator:getName(), 30)
        return 
    end 
    
    if event.id ~=4 then return end -- not 'landing'
    local theUnit = event.initiator 
    if not theUnit then return end 
    local theField = grabber.getClosestAirbase(theUnit)    
    -- player landed on 'theField'
    local coa = theUnit:getCoalition()
    if coa == theField:getCoalition() then return end -- belongs to us 
    
    -- drop a SoldierM4 slightly away from out landing pos 
    local p = theUnit:getPoint()
    local groupData = {}
    groupData.name = "grabby-"..grabber.getUUID()
    groupData.task = "Ground Nothing"
    groupData.units = {}
    local gUnit = {}
    gUnit.x = p.x + 100
    gUnit.y = p.z + 100
    gUnit.name = groupData.name 
    gUnit.type = "Soldier M4"
    table.insert(groupData.units, gUnit)
    
    -- spawn it 
    coalition.addGroup(theUnit:getCountry(), Group.Category.GROUND, groupData)
    
    trigger.action.outText("Attempting to grab airfield " .. theField:getName(), 30)
end

--
-- start up
--
world.addEventHandler(grabber)
 

 Demo mission and script as file below. You many need to change to A-10 to any aircraft that you currently fly and can land reliably.

 

grab'em now.miz grabber.lua

  • Like 1
  • Thanks 2
  • 8 months later...
Posted (edited)

You sir, are brilliant! I am a scripting newb and have been working with MOOSE and MIST for days to get my idea to work, looks like you did that over a lunch break.

 

Many Thanks!

Edited by 74DELTA
  • 1 month later...
Posted

@74DELTA, Sir, @cfrag is a god to me. Go check out his DML Tool box. You will not have to learn coding to do things like this. You just drop in the required module. Its not a mod either so put the required module(s) in your mission and everyone then gets it. No need for them to do anything extra.

Modules are added just as he described with the script he did for you, use DOSCRIPT and paste the module code in. Job done. It has transformed my mission building.

Visit the Dangerdogz at www.dangerdogz.com. We are a group based on having fun (no command structure, no expectations of attendance, no formal skills required, that is not to say we can not get serious for special events, of which we have many). We play DCS and IL2 GBS. We have two groups one based in North America / Canada and one UK / Europe. Come check us out. 

  • 3 months later...
Posted
10 hours ago, HungryCoyote said:

@cfrag When you have some free time, could you check if this still works since latest dcs update? I just tried the mission but nothing happens when I land.

I haven't had time to debug - but I'm suspicious that ...

 if event.id ~=4 then return end -- not 'landing'

... is not triggering as expected. I haven't been logging stuff down (I need to start) - but I've got the feeling that there's numerous events that are broken, or are undocumented removals of functions in the latest patch. 

I don't have access to DCS at the moment to test, but if you modify the script to add the following, you should be able to see if it makes it past this line or not:

trigger.action.outText("DEBUG: EventID 4 recognised!", 30)

ie:

grabber = {}
grabber.version = "1.0.0"
grabber.uuid = 0

function grabber.getUUID()
    grabber.uuid = grabber.uuid + 1 
    return grabber.uuid 
end
--
-- script to "grab" an airfield after landing a plane 
--
function grabber.getClosestAirbase(theUnit)
    local p = theUnit:getPoint()
    local all = world.getAirbases()
    local dist = math.huge
    local closest = nil 
    for idx, theBase in pairs(all) do 
        local ap = theBase:getPoint()
        local dx = ap.x - p.x 
        local dz = ap.z - p.z
        local d = math.sqrt(dx * dx + dz * dz)
        if d < dist then 
            dist = d 
            closest = theBase
        end
    end
    return closest
end

function grabber:onEvent(event)
    if not event then return end 
    if not event.initiator then return end 
    if event.id == 10 then 
        trigger.action.outText("Airfield " .. event.place:getName() .. " was captured by " .. event.initiator:getName(), 30)
        return 
    end 
    
    if event.id ~=4 then return end -- not 'landing'
    trigger.action.outText("DEBUG: EventID 4 recognised!", 30)
    local theUnit = event.initiator 
    if not theUnit then return end 
    local theField = grabber.getClosestAirbase(theUnit)    
    -- player landed on 'theField'
    local coa = theUnit:getCoalition()
    if coa == theField:getCoalition() then return end -- belongs to us 
    
    -- drop a SoldierM4 slightly away from out landing pos 
    local p = theUnit:getPoint()
    local groupData = {}
    groupData.name = "grabby-"..grabber.getUUID()
    groupData.task = "Ground Nothing"
    groupData.units = {}
    local gUnit = {}
    gUnit.x = p.x + 100
    gUnit.y = p.z + 100
    gUnit.name = groupData.name 
    gUnit.type = "Soldier M4"
    table.insert(groupData.units, gUnit)
    
    -- spawn it 
    coalition.addGroup(theUnit:getCountry(), Group.Category.GROUND, groupData)
    
    trigger.action.outText("Attempting to grab airfield " .. theField:getName(), 30)
end

--
-- start up
--
world.addEventHandler(grabber)

CFrag is no doubty flat out in spare time trying to solve a bunch of other broken things (as are a lot of us as well), so any debugging you're willing to help with would be greatly appreciated. 😉 

  • Like 1
Posted

Also - to add to my previous post, you may be able to use Airbase.setCoalition to capture the airbase without putting down a unit now:

DCS func setCoalition - DCS World Wiki - Hoggitworld.com

Or in MOOSE:

AB = AIRBASE:FindByName(AIRBASE.PersianGulf[airbasename])
AB:SetAutoCaptureOFF()
AB:SetCoalition(1)

Replace airbasename with constant of airbase. Coalition 1 for Red, 2 for Blue.

It will save dropping unnecessary units down to capture airbases, but will also mean that they can't be captured except through lua code - so keep that as a consideration. 

CFrag's method is better if you want units from the other side to be able to re-capture the airbase by overtaking the forces there. The above is better if you want to control it yourself using scripting. 

Posted
8 hours ago, HungryCoyote said:

Most of that is over my head, but I appreciate your reply. Tried it with your debug line but still nothing.

trigger.action.outText("DEBUG: EventID 4 recognised!", 30)

Thanks. If you weren't getting that message, then it sounds like it could be an issue with 'on landing' not being recognized, or similar. There's a number of event functions no longer working that used to. Until we know whether or not these are intentional and aren't going to be fixed moving forward, or whether they're an accident/bug and will be fixed in a future patch, I'm not sure there's much more that can be done at the moment. Might be worth just waiting to the next patch to see if it starts working again?

  • 3 months later...
Posted
3 hours ago, Gunslinger52 said:

Hi @Dangerzone,

do you know if this has since been fixed?

Cheers,

'52

Sorry mate, I don't know, but I doubt it. Event_Dead is still broken AFAIK, and scoreboards seem to be bugged as well. I think there's some serious issues with events behind the scenes being broken, and this would seem related. Try it for yourself, but  I would honestly suggest for your own sanity that you find another way to do what you want to achieve. Waiting for ED to fix something that was working and they've now broken is a fools game. 

'73   (< kudo's to you if you get the reference) 😉

  • Like 1
  • Thanks 1
Posted (edited)

Just (re-)stumbled across this thread. The fix is as easy as it is annoying: ED introduced (without announcing nor justifying the change) a new event 'runway touch' that sometimes (it seems randomly) fires instead of 'landing'. 

So fixing the grabber script is simple:

if (event.id ~=4) and (event.id ~= 55) then return end -- neither 'landing' nor 'runway touch'

Below please find an updated script that should work as described (read: untested, please let me know if something is wrong so I can take a look at it, was on my way to grab a coffee).

 

grabber.lua grab'em now.miz

Edited by cfrag
  • Like 2
  • Thanks 1
  • 4 weeks later...
Posted
On 10/25/2024 at 7:32 AM, cfrag said:

So fixing the grabber script is simple:

Do I assume correctly, that if the heli will land anywhere in the field, it will also trigger the "deployment" of the M4 trooper, so actually only event 55 should be monitored?
And second question, how to avoid creation of soldier in the middle of the runway?

Natural Born Kamikaze

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

AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.

Posted (edited)
42 minutes ago, Amarok_73 said:

heli will land anywhere in the field, it will also trigger the "deployment" of the M4 trooper,

Yes.

42 minutes ago, Amarok_73 said:

so actually only event 55 should be monitored?

You may find out the hard way if/when the kind people at ED change the logic without notice again, so why assume if it works? The second test won’t constitute much performance.

42 minutes ago, Amarok_73 said:

how to avoid creation of soldier in the middle of the runway?

Change the offset? It’s not guaranteed though. You could use the airfield’s runway info, build a quad from it, and then test if the guy is inside the quad. Not difficult, but a lot of ugly code for an edge case.

Edited by cfrag
  • Like 2
  • Recently Browsing   0 members

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