Jump to content

How to find number of active players / clients and spawn accordingly?


Recommended Posts

Posted

Hi,

 

I'm wanting to find the number of players so I can define how many units I spawn in. I want this to be dynamic so that as players come and go as the mission plays on, additional spawn scheduling is started and stopped.

 

I've come up with a working method - but I think it's a bit messy and not sure if it's overtaxing on CPU resources. I'm not sure of how to improve it.

 

I do things in 2 stages:

 

1) Create spawns for the units in the mission (but have them SpawnScheduleStop so they don't all spawn immediately:

 

e_main1A = SPAWN:New("e_mainair_29-1"):InitRandomizeTemplatePrefixes("e_mainair"):InitDelayOn():InitLimit(2, 16):SpawnScheduled(timetoset, 0.1):SpawnScheduleStop()
e_main1B = SPAWN:New("e_mainair_21-1"):InitRandomizeTemplatePrefixes("e_mainair"):InitDelayOn():InitLimit(2, 16):SpawnScheduled(timetoset, 0.1):SpawnScheduleStop()
... etc

 

 

I then create a scheduler that occurs every minute (every second while debugging, but will change to every minute to remove resources from the server). Depending on how many clients are connected I either trigger SpawnScheduleStart or SpawnScheduleStop.  (I include a variable that I set when I execute this so that it doesn't repeat SpawnScheduleStart or stop unneccessarily):

 

mysched = SCHEDULER:New(nil, 
    function()
       local clients = SET_CLIENT:New():FilterActive():FilterCoalitions("blue"):FilterPrefixes("A_"):FilterOnce()
       BASE:E(clients:Count() .." active clients connected")
              
       if clients:Count() > 0 then
       BASE:E("client > 0")
        if e_main1on ~= true then
         e_main1A:SpawnScheduleStart()
         e_main1B:SpawnScheduleStart()
         e_main1C:SpawnScheduleStart()
         BASE:E("main1 started")
         e_main1on = true
        end
       else --countcount < 1 
       BASE:E("client 0")
        if e_main1on ~= false then
        BASE:E("main1 stopped")
         e_main1A:SpawnScheduleStop()
         e_main1B:SpawnScheduleStop()
         e_main1C:SpawnScheduleStop()
         e_main1on = false
         
        end  
       end  --Clientcount
       
       if clients:Count() > 0 then
        if e_main2on ~= true then
         e_main2A:SpawnScheduleStart()
         e_main2B:SpawnScheduleStart()
         e_main2C:SpawnScheduleStart()
         BASE:E("main2 started")
         e_main2on = true
        end
       else --countcount < 1 
        if e_main2on ~= false then
         e_main2A:SpawnScheduleStop()
         e_main2B:SpawnScheduleStop()
         e_main2C:SpawnScheduleStop()
         BASE:E("main2 stopped")
         e_main2on = false
        end  
       end  --Clientcount
              
     ... etc  
          
   end, {}, 1, 60) --zonetrigger Scheduler   
   

 

Clients is set locally and I repeat the call each time because this is the only method I've found to get an active player count (as players join and leave). 

 

Is the above the correct way of doing this - or is there a more simpler solution?

 

(I did check out Moose's auto-balancer but from what I could tell it seems to be more about balancing AI on each side, whereas my mission is being designed to be more PvE. If I'm wrong and auto-balancing supports this as well and I've missed something please let me know).

Posted (edited)

I use MOOSE A2A_Dispatcher to launch an AI response to intruders.  With this method, MOOSE determines the number and type of aircraft to launch based on how many and what types of intruders have been detected.  I think it works very well. 

For example, a single player will get one response. A group of players will get quite another response.  A single F-16 may get one response and a flight of Tomcats another. It keeps things dynamic.  I can determine patrol zones for the AI, the type and armament of the interceptors, the total number of interceptors in a squadron, the squadron base,  etc. That way I am not limited to the same hard coded flights each time.

 

Setting this up is a detailed process.  But I can setup a complete air defense system in lua in about 25 lines of code.  

Edited by Zeagle
  • Thanks 1

 

 

Posted (edited)

I suggest you watch some of Flight Control's videos.

 

I can set my aircraft to launch from the ramp cold, ramp hot, rwy, etc.

 

Edited by Zeagle

 

 

Posted
On 5/16/2021 at 6:40 PM, Zeagle said:

I use MOOSE A2A_Dispatcher to launch an AI response to intruders. 

 

 

OK - simply wow! A2A_Dispatcher not only does what I wanted, but also the things I was dreaming about! It's incredibly powerful. Thanks so much for pointing me in the right direction!!!

  • Recently Browsing   0 members

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