Jump to content

Simplest method for slot blocking/unblocking with Capturable airfields with Client Spawns?


Dangerzone

Recommended Posts

Hi,

 

I'm just looking for the most basic method to allow airfields to be capturable and once captured new client slots open up for spawning.

 

The idea is for a 'conquest' type mission where players start with a single airfield and as they move across the map they capture airfields and have more spawn places available to them. (Which could end up being hundreds of aircraft across the map when you consider the number of airfields, farps, and different aircraft types).

 

I'm aware that I can do this using SimpleSlotBlock - however from what I understand, I would need to specify a flag for every client aircraft individually on the map each time an airfield is captured. (Given that my ideas of grandeur mean there could be hundreds of aircraft (planes, helicopters of all sorts) across the map), plus also specify a block flag at the beginning for each aircraft. 

 

I was just wondering if there is a more simple method of blocking slots that I've missed so spawning is only available if that airfield is owned by the clients across the board instead of having to individually put in an event to set flags each time an airfield is captured?

 

I'm not familiar with lua so I know the below code is wrong - but just as an idea the concept I was kind of hoping for (if ED doesn't give a native / automatic way of doing this) was something like:

 

for i, clientslotcount - 1 do

  if client.slot[i].spawnfield.coalition <> client.slot[i].coalition then

 trigger.action.setUserFlag(client.slot[i],100)

  else

 trigger.action.setUserFlag(client.slot[i],0)
end

 

Is it possible to achieve what I'm wanting using lua/moose/simpleslotblock as simple as the above? 

 

TIA

Link to comment
Share on other sites

Not sure about doing it through coding, but it's quite easy to do with a simple flag on/off trigger.  Start with airfield as neutral.  When a red or blue ground unit moves onto the base it turns one flag on, and the other off, and vice versa.

Link to comment
Share on other sites

12 minutes ago, Baaz said:

Not sure about doing it through coding, but it's quite easy to do with a simple flag on/off trigger.  Start with airfield as neutral.  When a red or blue ground unit moves onto the base it turns one flag on, and the other off, and vice versa.

 

Thanks Baaz - but I'd have to do that individually for each client aircraft, which would mean a few hundred events - and easy to 'overlook' or miss an aircraft. (That's kinda why I was hoping to do it as a generic script).  I have done smaller missions the way that you've mentioned (and still end up messing up by missing a flag) - so looking at doing a much larger mission I was kind of hoping to automate it a little more.

Link to comment
Share on other sites

2 hours ago, Baaz said:

Sorry I couldn't be of any help.  I just haven't learned coding enough yet to be useful. 

 

Nah - that's all sweet mate. I don't know enough either - that's why I thought I'd ask before I waste 3 days trying to find a solution if one doesn't exist. 😉

Link to comment
Share on other sites

Just to clear up how SimpleSlotBlock works, you set flags for each GROUP Name (not pilotname!). So if you have multiple slots for each group name...  it's not a flag for each individual slot as you think, but it can be close.

 

 

Link to comment
Share on other sites

33 minutes ago, pacastro said:

Just to clear up how SimpleSlotBlock works, you set flags for each GROUP Name (not pilotname!). So if you have multiple slots for each group name...  it's not a flag for each individual slot as you think, but it can be close.

 

 

 

Thanks Pacastro for the clarification. But even so - is there a way to scroll recursively through the client group list and set flags accordingly instead of specifying each by individual name? I'm just looking to create a generic function that I can use that will activate or block spawns based on their location and whether the airfield is in their hands or not without having to code each group individually. Cheers. 🙂

Link to comment
Share on other sites

I have limited lua knowledge, and I have no idea how to recursively do a for function to search through all the group names in your mission. "i' should be each  "group name" in order to get the remaining function to work.

 

Also I can't find airbase as an attribute to units or groups, so as I understand you would have to repeat the if function for each airfield ("Krymsk" in the following example), make sure all your group names in mission editor contain the airfield where you place the units, and then check if "i" (a group name) contains the name of the airfield (not sure if the string.find function works).

 

 

for i ??????
local group = Group.getByName( i )
if string.find( group.getName, "Krymsk") then
if AIRBASE:FindByName("Krymsk"):GetCoalitionName()~=group:GetCoalitionName() then
	trigger.action.setUserFlag( i, 100)
else
	trigger.action.setUserFlag( i, 0)
end
end
elseif string.find( group.getName, "another airfield") then
if AIRBASE:FindByName("another airfield"):GetCoalitionName()~=group:GetCoalitionName() then
	trigger.action.setUserFlag( i, 100)
else
	trigger.action.setUserFlag( i, 0)
end
end
elseif (etc for remaining airfields)  

end

Edited by pacastro
  • Thanks 1
Link to comment
Share on other sites

This is what I've come up with so far.

 

Please keep in mind - I've had about 8hrs lua experience todate, so I'm convinced there will be a better method than this. The below has the following advantages:

 

Automatically disable all clients on startup

 

Instead of having to manually set each client to a flag value not zero, this will go through and automatically apply a flag value for each client of 100. After that, individual clients can be changed back to zero.  The only requirement for this is that units that are to be slot blocked have the group and unit name prefixed with "A_".

 

Add new clients without having to touch script

 

Once setup. Any number of new clients can be added (say if there's a new module - not looking at the AH64 or Kiowa here 😉) without having to rescript. The only prerequisite is that both the groupname and the unit name uses a prefix (that you can define. For me - I'm using "A_B_"+airport name.  A referencing client, and B referencing blufor.

 

Automatically locks and unlocks on airbase capture

 

Using the same prerequisite as above (all units to be blocked/unblocked automatically need to have the prefix "A_B_"+airportname. ie:

 

A_B_Minakh_A10-1

A_B_Minakh_A10-2

A_B_Minakh_A10-3

A_B_Minakh_FA18-1

A_B_Minakh_FA18-2

A_B_Minakh_FA18-3

A_B_Minakh_UH1-1

A_B_Minakh_UH1-2

... etc

 

 

There are some disadvantages or things I would like to address differently which I'll post afterwards. If anyone can see anything here that can be handled differently (aka better - please let me know) 🙂

 

 

Script to be ran to setup SSB and to set all clients with prefix of A_ to flag 100:

 

trigger.action.setUserFlag("SSB",100)

local SetGroup = SET_CLIENT:New():FilterActive( false ):FilterCoalitions("blue"):FilterPrefixes("A_"):FilterOnce()
SetGroup:ForEach(
  function( GroupObject )
    _flag = GroupObject:GetName()
    trigger.action.setUserFlag(_flag, 100)
    local thisflag = trigger.misc.getUserFlag(GroupObject:GetName())
        GroupObject:E( {"Confirming: ".. GroupObject:GetName(), " Set to ".. thisflag } )
  end )

 

 

And the script I've created that will automatically block/unblock slots on a base capture event:

 

 

evh = EVENTHANDLER:New()
evh:HandleEvent(EVENTS.BaseCaptured)
function evh:OnEventBaseCaptured(EventData)
  local AirbaseName = EventData.PlaceName
  local ABItem = AIRBASE:FindByName(AirbaseName)
  local coalition = ABItem:GetCoalition()
  
  if coalition == 1 then 
   coalitionname = "Redfor"
   newflag = 100
  elseif coalition == 2 then 
   coalitionname = "Blufor"
   newflag = 0
  end
  
  MESSAGE:New(AirbaseName .." captured by "..coalitionname ,5):ToAll()  
  
  if AirbaseName ==  "Minakh"  then 
  MESSAGE:New("Minakh detected!" ,5):ToAll()  
    local SetGroup = SET_CLIENT:New():FilterActive( false ):FilterCoalitions("blue"):FilterPrefixes("A_B_Min"):FilterOnce()

    SetGroup:ForEach(
      function( GroupObject )
         _flag = GroupObject:GetName()
          trigger.action.setUserFlag(_flag, newflag)
    
         local thisflag = trigger.misc.getUserFlag(GroupObject:GetName())
         if thisflag == 0 then
           MESSAGE:NewType( GroupObject:GetName().. " unlocked", MESSAGE.Type.Information ):ToAll()
           GroupObject:E( {"Confirming: ".. GroupObject:GetName(), " UNLOCKED - Flag Set to ".. thisflag } )
         end
      end ) --Setgroup:Foreach
  end --Airbase Minakh
  
  
    if AirbaseName ==  "Tabqa"  then 
  MESSAGE:New("Tabqa detected!" ,5):ToAll()  
    local SetGroup = SET_CLIENT:New():FilterActive( false ):FilterCoalitions("blue"):FilterPrefixes("A_B_Tab"):FilterOnce()

    SetGroup:ForEach(
      function( GroupObject )
         _flag = GroupObject:GetName()
          trigger.action.setUserFlag(_flag, newflag)
    
         local thisflag = trigger.misc.getUserFlag(GroupObject:GetName())
         if thisflag == 0 then
           MESSAGE:NewType( GroupObject:GetName().. " unlocked", MESSAGE.Type.Information ):ToAll()
           GroupObject:E( {"Confirming: ".. GroupObject:GetName(), " UNLOCKED - Flag Set to ".. thisflag } )
         end
      end ) --Setgroup:Foreach
  end --Airbase Minakh
  

end --EventBaseCaptured

 

Link to comment
Share on other sites

In regards to the above - here is what's on my wishlist. The above took many hours to try and figure out being so green with lua - so I have no idea if the following is even possible or can be addressed better:

  1. I don't like addressing the airbases by text name. It makes it too easy to make a mistake and not have anything picked up (aka type in "Minahk" instead of "Minakh"). 
     
  2. I'd love to actually automate the base comparisons - maybe compare the first 4 letters of the base with the first 5th to 9th character in the group/unit name and set it automatically accordingly. (I'm not sure if there are any bases that would conflict with this - having similar names at the start, etc).
     
  3. I'd really love to ignore the base names in the prefix and find a way of determining which base a unit is 'owned' by (aka - set to spawn on). I haven't been able to find any reference to that - but I figure if that was possible, it would eliminate a lot of manual coding above and automate a lot more.

 

I'm open to other ideas that might be better. I thought of creating tables (which I don't know much about yet) with the units for each base - but then that takes away from being able to add more units later without recoding. (Although seeing how many bases are actually in the map - this may be a more 'efficient' idea).  Either way - I'm just looking for the most efficient (and one that will stop the most mistakes) of getting this to work., so I haven't ruled this out. 

 

I guess I could have some sort of validation check that would scan the tables against units with a "A_" prefix and if any units are 'left over' show a warning message window so I know that there are 'rogue' units that haven't been added to the table.

 

Again - as mentioned - I'm about 8hrs into lua at the moment and much of the above is trial and error (lots of error!) so I have no idea whether the above approach is really a good idea or if there is a better approach to automate SSB more and would appreciate any constructive criticism / feedback accordingly if anyone has ideas or thoughts.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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