Jump to content

Lua - detecting client aircraft entering/leaving in multiplayer


Recommended Posts

Posted

aircraftUnit = Unit.getByName(aircraftName)

if aircraftUnit ~= nil then

.............

end

 

 

I've been using something like this code to check whether a human client aircraft has entered or left the game in multiplayer or has died, and it may (or may not be) working, it's kinda hard for me to test. But can someone tell me exactly at what point a client aircraft unit would be become nil or not nil? Does it become not nil when a client clicks Fly? And then does it become nil again when the client aircraft dies or disconnects for whatever reason?

 

Is there a better way to do this?

Posted

The object will exist once a player hits fly and spawns in. I think once a player aircraft is completely destroyed or they despawn by selecting another aircraft or going to spectators, their aircraft object will be nil.

 

You can also use event handlers to see when player enter/leave units, spawn, or get destroyed. It would be a more automated process instead of just continuously checking if an unit exists or not.

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

The _ENTER_UNIT and _LEAVE_UNIT events are not working/not dispatched for clients.

 

I solved it this way:

the _BIRTH event is called once a player enters a unit. You can make sure it is a player by calling aircraftUnit:getPlayerName(), if it returns nil it is AI. As long as you get true on aircraftUnit:isExist() the player is actively in the aircraft. You may also wanna watch for _DIED _CRASHED and _EJECTED events as a substitute for the broken _LEAVE_UNIT event, as it is essentially the same end result.

Posted

Thanks for the replies!

 

I was able to set up a multiplayer test scenario to see exactly when the client aircraft unit went from nil to NOT nil and vice versa, and Grimes you were exactly right...of course. The client' aircraft became NOT nil at the moment he clicked Fly. It went from NOT nil to nil at the moment he died (crashed into the ground). When a still-alive client quit the game and returned to the aircraft selection screen the aircraft didn't switch from NOT nil to nil until he moved out of the aircraft slot (either left the game completely or moved to another aircraft slot). I didn't think to check what happens when the pilot ejects.

 

Anyway, for what all that's worth...

Posted

Hi,

 

I 'm working a new modular script which made easy single et multiplayer management. I think, the best way (without enter and leave unit) is to implement S_EVENT_BIRTH to store update informations in a players personal table then, in a timer (Schedule every second enough), update the players personnal table. That works perfectly.

 

Regards

  • Recently Browsing   0 members

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