Jump to content

Recommended Posts

Posted

I'm building a mission that has multiple client slots. The idea is to use the mission as a single player, but giving the player a wide variety of starting positions at various airfields. For scripting I rely heavily on MOOSE, which is working great so far. But there is one problem I cannot seem to solve.

 

After the player chooses a slot, I want to be notified. I've tried using events, but the PLAYER_ENTERED_UNIT event is only sent after changing a slot, not after the first slot is selected. So I thought I would use the database, but there do not seem to be any player or clients. The following code:

 

sched = SCHEDULER:New(nil, 
          function()
              env.info("Scheduler callback")

              env.info("num players = " .. #(_DATABASE.PLAYERS))
              env.info("num players joined = " ..  #(_DATABASE.PLAYERSJOINED))
              env.info("num clients = " .. #(_DATABASE.CLIENTS))
            end, {}, 0, 5)

yields

 

2019-01-01 14:38:26.340 INFO SCRIPTING: Scheduler call back

2019-01-01 14:38:26.340 INFO SCRIPTING: num players = 0

2019-01-01 14:38:26.340 INFO SCRIPTING: num players joined = 0

2019-01-01 14:38:26.340 INFO SCRIPTING: num clients = 0

 

 

This is after I have selected a slot ...

 

 

Any help would be appreciated!

Posted

Ok, I figured out how to do it. The PLAYER_ENTER_UNIT event is fired before the scripting is started. However use can use the initializer script option of the mission editor. This comes in two flavors: file or code. Specifying a file does exactly nothing. However the code input box does work. If you paste the following code into the box:

clientDCSUnit=nil; 
handler = {}; 
handler.init = function(self) world.addEventHandler(self); end; 
handler.onEvent = function(self, event)
   if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then 
       env.info("INIT SCRIPT: player entered unit");
       clientDCSUnit=event.initiator;
       world.removeEventHandler(self);
   end; 
   return true; 
end; 
handler:init();

Then you will have the clientDCSUnit available in the rest of your scripting.

Posted
Ok, I figured out how to do it. The PLAYER_ENTER_UNIT event is fired before the scripting is started. However use can use the initializer script option of the mission editor. This comes in two flavors: file or code. Specifying a file does exactly nothing. However the code input box does work. If you paste the following code into the box:

Then you will have the clientDCSUnit available in the rest of your scripting.

 

 

Hey,

Great minds think alike. I was just revisiting an SP mission I wanted to do the same thing with, to a certain degree.

 

 

Hope you will continue to share, as I hope to have something to contribute. Don't hold breath, as I have no idea what I'm doing.

 

 

Thanks,

Night Ops in the Harrier

IYAOYAS


 
Posted

Slot information is available as part of the server control API or "GameGUI". You can find documentation for it in your install/API folder as I haven't added that documentation to the hoggit wiki. You'd have to modify some files to access it from the mission environment though...

 

Birth events are your only mission environment side of stuff that will tell you which pilots are in which aircraft. Also client aircraft can only exist when a client is spawned in, so periodically checking what is and isn't alive would be one way to tell.

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
Birth events are your only mission environment side of stuff that will tell you which pilots are in which aircraft. Also client aircraft can only exist when a client is spawned in, so periodically checking what is and isn't alive would be one way to tell.

This seems like to way to go for me. Thanks.

  • Recently Browsing   0 members

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