Function MessageReceiveCallback(entity:TEntity, Name:String, extra:Object)
heloid = GetEntityKey(entity, "guid");
DebugLog(" MessageReceiveCallback :" + Name + " heloid:" + heloid + " GetEntityKey returns:" + GetEntityKey(entity, "guid"));
Case ACTION_MOUNT BindHelicopterToPlayer(heloid);
' CALLED WHEN THELICOPTER MESSAGE IS RECIEVED
helo = THelicopter(game.Helicopters.ValueForKey(linkid));
If helo Then
game.PlayerVehicle = helo.entity;
game.PlayerVehicleBody = helo.body;
AlignToVector(game.PlayerVehicleMount, game.PlayerVehicle.Position, 2, 1, 180);
Local crewpos:TEntity = CreatePivot(game.PlayerVehicleMount);
Local newloc:TVec3 = TFormPoint(PLAYER_SLOT_APACHE[CurrentSlot], game.PlayerVehicleMount, Null);
PositionEntity(crewpos, newloc, 1);
EntityParent(game.scene.cam, crewpos, 1);
EntityParent(game.scene.cam, game.PlayerVehicleMount, 1);
DebugLog(" BindHelicopterToPlayer :" + linkid + " failed. LinkID not found.");
A short explanation, when the game sends a message to a helicopter TEntity object to mount (ACTION_MOUNT is defined as the text literal "mount") the BindHelicopterToPlayer(...) function is called which gets information from the game about that particular helicopter and binds the player and game camera to the current active position within the helicopter.
Using messaging has advantages in that it can be scripted externally by LUA sending the message to the helicopter, this a script can bind a player to any helicopter at the start of a mission, or during some scene, or as a result of multiplayer code.
The player has key commands to Unbind from the helicopter which will be locked off at some point in the future. We don't want players jumping out of helicopters mid-flight do we?
We have some logging in there to check what's going on for debugging. Each vehicle type we want the player to control will have a function like this, the main game code knows which vehicle mode is active and calls appropriate control input and vehicle update functions. Right now we have Apache helicopter and ground pounder.
You may notice that the BindHelicopterToPlayer parameter [linkid] is a string. All objects are identified by a texted based key, Apache Longbows use the base key "LONGBOW00xxx" where xxx is a number assigned automatically at object creation. For human interation, tail numbers can be assigned. Callsigns based on rifles and handgun names will be added later for the benefit of grouping helicopters for mission triggers and voice scripting.