corvinus Posted January 1, 2019 Posted January 1, 2019 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!
corvinus Posted January 2, 2019 Author Posted January 2, 2019 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.
Hardcard Posted January 2, 2019 Posted January 2, 2019 You might have solved a really annoying problem with this! Have you shared this already in the MOOSE discord channel? [sIGPIC][/sIGPIC]
SGT Coyle Posted January 2, 2019 Posted January 2, 2019 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
corvinus Posted January 2, 2019 Author Posted January 2, 2019 These are my first steps with MOOSE and Lua too. I'm going in head first! :pilotfly:
Delta99 Posted January 2, 2019 Posted January 2, 2019 The PLAYER_ENTER_UNIT has been a long standing issue. Typically I think people get around this by entering a spectator slot first then switch over to a regular slot. Can you test that to see if your original code fires in that case? Otherwise an interesting workaround. My Missions: Valley Patrol Mission :: Valley Escort Mission :: A2A Engagements
corvinus Posted January 3, 2019 Author Posted January 3, 2019 Yeah, the original code works in that case. I am happy with my workaround for now, but it is good to have a backup solution.
Grimes Posted January 4, 2019 Posted January 4, 2019 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 Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
corvinus Posted January 4, 2019 Author Posted January 4, 2019 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.
Recommended Posts