public void prepareVehicle(StreamedVehicle vehicle)
 {
     if (vehicle.gameReference != null)
     {
         prepareVehicle(vehicle.gameReference);
     }
 }
        public void updateVehicle(uint id, UpdateDataStruct data, StreamedPed ped)
        {
            if (data.vehicle_id > 0)
            {
                var             posnew = new Vector3(data.pos_x, data.pos_y, data.pos_z);
                StreamedVehicle veh    = vehicleController.GetInstance(data.vehicle_id);
                if (veh != null)
                {
                    if (veh.IsStreamedIn())
                    {
                        if (ped != null && ped.IsStreamedIn() && !ped.gameReference.isInVehicle())
                        {
                            if ((data.state & PlayerState.IsPassenger1) != 0)
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.RightFront);
                            }
                            else if ((data.state & PlayerState.IsPassenger2) != 0)
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.LeftRear);
                            }
                            else if ((data.state & PlayerState.IsPassenger3) != 0)
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.RightFront);
                            }
                            else
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.Driver);
                            }
                        }

                        int healthDelta = data.ped_health - ped.gameReference.Health;
                        ped.gameReference.Health = data.ped_health;
                        ped.last_game_health     = data.ped_health;

                        if (healthDelta > 20 && healthDelta < 100)
                        {
                            var bpf = new BinaryPacketFormatter(Commands.Player_damage);
                            bpf.Add(id);
                            //Client.instance.chatController.writeChat("damaged " + healthDelta) ;
                            Client.instance.serverConnection.write(bpf.getBytes());
                        }

                        int vehicleHealthDelta = data.vehicle_health - veh.gameReference.Health;
                        veh.gameReference.Health = data.vehicle_health;
                        veh.last_game_health     = data.vehicle_health;

                        if (vehicleHealthDelta > 20 && vehicleHealthDelta < 2000 && data.vehicle_id > 0)
                        {
                            var bpf = new BinaryPacketFormatter(Commands.Vehicle_damage, id, data.vehicle_id, vehicleHealthDelta);
                            Client.instance.serverConnection.write(bpf.getBytes());
                        }

                        if ((data.vstate & VehicleState.IsAsPassenger) != 0)
                        {
                            return;
                        }
                        veh.position = posnew;
                        if (veh.gameReference.Position.DistanceTo(posnew) > 1.0f)
                        {
                            veh.gameReference.Position = posnew;
                        }
                        //veh.gameReference.Position = posnew;
                        veh.orientation = new Quaternion(data.rot_x, data.rot_y, data.rot_z, data.rot_a);
                        //veh.gameReference.ApplyForce(, Vector3.Zero);
                        veh.gameReference.RotationQuaternion = veh.orientation;
                        var vel = new Vector3(data.vel_x, data.vel_y, data.vel_z);
                        if (System.Math.Abs(veh.gameReference.Velocity.Length() - vel.Length()) > 6.0f)
                        {
                            veh.gameReference.ApplyForce(vel);
                        }
                        if ((data.vstate & VehicleState.IsBraking) == 0)
                        {
                            ped.gameReference.Task.DrivePointRoute(veh.gameReference, 999.0f, posnew - veh.gameReference.Velocity);
                        }
                        else
                        {
                            ped.gameReference.Task.DrivePointRoute(veh.gameReference, 999.0f, posnew + veh.gameReference.Velocity);
                        }
                        if ((data.state & PlayerState.IsShooting) != 0)
                        {
                            Vector3 pos = veh.gameReference.Position + veh.gameReference.Direction;
                            GTA.Native.Function.Call("FIRE_PED_WEAPON", ped.gameReference, pos.X, pos.Y, pos.Z);
                            GTA.Native.Function.Call("TASK_SHOOT_AT_COORD", ped.gameReference, pos.X, pos.Y, pos.Z, (Int32)4, 999992);
                        }
                    }
                }
            }
        }
 public void prepareVehicle(StreamedVehicle vehicle)
 {
     if (vehicle.gameReference != null) prepareVehicle(vehicle.gameReference);
 }