Esempio n. 1
0
        private bool DisplayVehicleDriveBy()
        {
            if (!IsShooting || CurrentWeapon == 0 || VehicleSeat != -1 || !WeaponDataProvider.DoesVehicleSeatHaveMountedGuns((VehicleHash)VehicleHash))
            {
                return(false);
            }

            var isRocket = WeaponDataProvider.IsVehicleWeaponRocket(CurrentWeapon);

            if (isRocket)
            {
                if (DateTime.Now.Subtract(_lastRocketshot).TotalMilliseconds < 1500)
                {
                    return(true);
                }
                _lastRocketshot = DateTime.Now;
            }

            var isParallel = WeaponDataProvider.DoesVehicleHaveParallelWeapon(unchecked ((VehicleHash)VehicleHash), isRocket);

            var muzzle = WeaponDataProvider.GetVehicleWeaponMuzzle(unchecked ((VehicleHash)VehicleHash), isRocket);

            if (isParallel && _leftSide)
            {
                muzzle = new Vector3(muzzle.X * -1f, muzzle.Y, muzzle.Z);
            }
            _leftSide = !_leftSide;

            var start = MainVehicle.GetOffsetInWorldCoords(muzzle);
            var end   = start + Main.RotationToDirection(VehicleRotation) * 100f;
            var hash  = CurrentWeapon;
            var speed = 0xbf800000;

            if (isRocket)
            {
                speed = 0xbf800000;
            }
            else if ((VehicleHash)VehicleHash == GTA.VehicleHash.Savage || (VehicleHash)VehicleHash == GTA.VehicleHash.Hydra || (VehicleHash)VehicleHash == GTA.VehicleHash.Lazer)
            {
                hash = unchecked ((int)WeaponHash.Railgun);
            }
            else
            {
                hash = unchecked ((int)WeaponHash.CombatPDW);
            }


            var damage = IsFriend() ? 0 : 75;

            Function.Call(Hash.SHOOT_SINGLE_BULLET_BETWEEN_COORDS, start.X, start.Y, start.Z, end.X, end.Y, end.Z, damage, true, hash, Character, true, false, speed);

            return(false);
        }
Esempio n. 2
0
        private static void VehicleData(Ped player)
        {
            var veh = player.CurrentVehicle;

            var obj = new VehicleData
            {
                Position      = veh.Position.ToLVector(),
                VehicleHandle = Main.NetEntityHandler.EntityToNet(veh.Handle),
                Quaternion    = veh.Rotation.ToLVector(),
                PedModelHash  = player.Model.Hash,
                PlayerHealth  = (byte)Util.Util.Clamp(0, player.Health, 255),
                VehicleHealth = veh.EngineHealth,
                Velocity      = veh.Velocity.ToLVector(),
                PedArmor      = (byte)player.Armor,
                RPM           = veh.CurrentRPM,
                VehicleSeat   = (short)Util.Util.GetPedSeatAtVehicle(player, veh),
                Flag          = 0,
                Steering      = veh.SteeringScale,
                DirtLevel     = veh.DirtLevel,
            };

            //veh.DirtLevel;
            //veh.BrakeLightsOn
            //veh.HasRoof
            //veh.IsConvertible - roof sync
            //veh.SetNoCollision(veh, true);
            //veh.LightsOn;

            //LogManager.StreamerLog("SyncCollector " + obj.Steering);

            if (Game.Player.IsPressingHorn)
            {
                obj.Flag |= (byte)VehicleDataFlags.PressingHorn;
            }
            if (veh.IsSirenActive)
            {
                obj.Flag |= (byte)VehicleDataFlags.SirenActive;
            }
            if (veh.IsConvertible)
            {
                obj.Flag |= unchecked ((byte)VehicleDataFlags.IsConvertible);
            }
            if (veh.IsDead)
            {
                obj.Flag |= (byte)VehicleDataFlags.VehicleDead;
            }
            if (player.IsDead)
            {
                obj.Flag |= (short)VehicleDataFlags.PlayerDead;
            }
            if (Util.Util.GetResponsiblePed(veh).Handle == player.Handle)
            {
                obj.Flag |= (byte)VehicleDataFlags.Driver;
            }
            if (veh.IsInBurnout)
            {
                obj.Flag |= (byte)VehicleDataFlags.BurnOut;
            }
            if (ForceAimData)
            {
                obj.Flag |= (byte)VehicleDataFlags.HasAimData;
            }
            if (player.IsSubtaskActive(167) || player.IsSubtaskActive(168))
            {
                obj.Flag |= (short)VehicleDataFlags.ExitingVehicle;
            }
            if (Game.IsEnabledControlPressed(Control.VehicleBrake) || Game.IsEnabledControlPressed(Control.VehicleHandbrake))
            {
                obj.Flag |= (short)VehicleDataFlags.Braking;
            }

            if (!WeaponDataProvider.DoesVehicleSeatHaveGunPosition((VehicleHash)veh.Model.Hash, Util.Util.GetPedSeat(player)) &&
                WeaponDataProvider.DoesVehicleSeatHaveMountedGuns((VehicleHash)veh.Model.Hash) &&
                Util.Util.GetPedSeat(player) == -1)
            {
                obj.Flag      |= (byte)VehicleDataFlags.HasAimData;
                obj.AimCoords  = new GTANetworkShared.Vector3(0, 0, 0);
                obj.WeaponHash = Main.GetCurrentVehicleWeaponHash(player);
                if (Game.IsEnabledControlPressed(Control.VehicleFlyAttack))
                {
                    obj.Flag |= (byte)VehicleDataFlags.Shooting;
                }
            }
            else if (WeaponDataProvider.DoesVehicleSeatHaveGunPosition((VehicleHash)veh.Model.Hash, Util.Util.GetPedSeat(player)))
            {
                obj.Flag      |= (byte)VehicleDataFlags.HasAimData;
                obj.WeaponHash = 0;
                obj.AimCoords  = Main.RaycastEverything(new Vector2(0, 0)).ToLVector();
                if (Game.IsEnabledControlPressed(Control.VehicleAttack))
                {
                    obj.Flag |= (byte)VehicleDataFlags.Shooting;
                }
            }
            else
            {
                bool usingVehicleWeapon = player.IsSubtaskActive(200) || player.IsSubtaskActive(190);

                if (usingVehicleWeapon &&
                    Game.IsEnabledControlPressed(Control.Attack) &&
                    player.Weapons.Current?.AmmoInClip != 0)
                {
                    obj.Flag |= (byte)VehicleDataFlags.Shooting;
                    obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                }

                if ((usingVehicleWeapon &&
                     player.Weapons.Current?.AmmoInClip != 0) ||
                    (player.Weapons.Current?.Hash == WeaponHash.Unarmed &&
                     player.IsSubtaskActive(200)))
                {
                    obj.Flag |= (byte)VehicleDataFlags.Aiming;
                    obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                }

                var outputArg = new OutputArgument();
                Function.Call(Hash.GET_CURRENT_PED_WEAPON, player, outputArg, true);
                obj.WeaponHash = outputArg.GetResult <int>();

                lock (Lock)
                {
                    if (LastSyncPacket != null && LastSyncPacket is VehicleData &&
                        WeaponDataProvider.NeedsFakeBullets(obj.WeaponHash.Value) &&
                        (((VehicleData)LastSyncPacket).Flag & (byte)VehicleDataFlags.Shooting) != 0)
                    {
                        obj.Flag |= (byte)VehicleDataFlags.Shooting;
                        obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                    }
                }

                obj.AimCoords = Main.RaycastEverything(new Vector2(0, 0)).ToLVector();
            }

            Vehicle trailer;

            switch ((VehicleHash)veh.Model.Hash)
            {
            case VehicleHash.TowTruck:
            case VehicleHash.TowTruck2:
                trailer = veh.TowedVehicle;
                break;

            case VehicleHash.Cargobob:
            case VehicleHash.Cargobob2:
            case VehicleHash.Cargobob3:
            case VehicleHash.Cargobob4:
                trailer = SyncEventWatcher.GetVehicleCargobobVehicle(veh);
                break;

            default:
                trailer = SyncEventWatcher.GetVehicleTrailerVehicle(veh);
                break;
            }

            if (trailer != null && trailer.Exists())
            {
                obj.Trailer = trailer.Position.ToLVector();
            }

            if (Util.Util.GetResponsiblePed(veh) == player)
            {
                obj.DamageModel = veh.GetVehicleDamageModel();
            }

            lock (Lock)
            {
                LastSyncPacket = obj;
            }
        }
Esempio n. 3
0
        internal void OnTick(object sender, EventArgs e)
        {
            if (!Main.IsOnServer())
            {
                return;
            }
            var player = Game.Player.Character;

            if (player.IsInVehicle())
            {
                var veh = player.CurrentVehicle;

                var horn    = Game.Player.IsPressingHorn;
                var siren   = veh.SirenActive;
                var vehdead = veh.IsDead;

                var obj = new VehicleData();
                obj.Position      = veh.Position.ToLVector();
                obj.VehicleHandle = Main.NetEntityHandler.EntityToNet(player.CurrentVehicle.Handle);
                obj.Quaternion    = veh.Rotation.ToLVector();
                obj.PedModelHash  = player.Model.Hash;
                obj.PlayerHealth  = (byte)Util.Util.Clamp(0, player.Health, 255);
                obj.VehicleHealth = veh.EngineHealth;
                obj.Velocity      = veh.Velocity.ToLVector();
                obj.PedArmor      = (byte)player.Armor;
                obj.RPM           = veh.CurrentRPM;
                obj.VehicleSeat   = (short)Util.Util.GetPedSeat(player);
                obj.Flag          = 0;
                obj.Steering      = veh.SteeringAngle;

                if (horn)
                {
                    obj.Flag |= (byte)VehicleDataFlags.PressingHorn;
                }
                if (siren)
                {
                    obj.Flag |= (byte)VehicleDataFlags.SirenActive;
                }
                if (vehdead)
                {
                    obj.Flag |= (byte)VehicleDataFlags.VehicleDead;
                }
                if (player.IsDead)
                {
                    obj.Flag |= (short)VehicleDataFlags.PlayerDead;
                }

                if (Util.Util.GetResponsiblePed(veh).Handle == player.Handle)
                {
                    obj.Flag |= (byte)VehicleDataFlags.Driver;
                }

                if (veh.IsInBurnout)
                {
                    obj.Flag |= (byte)VehicleDataFlags.BurnOut;
                }

                if (ForceAimData)
                {
                    obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                }

                if (player.IsSubtaskActive(167) || player.IsSubtaskActive(168))
                {
                    obj.Flag |= (short)VehicleDataFlags.ExitingVehicle;
                }

                if (!WeaponDataProvider.DoesVehicleSeatHaveGunPosition((VehicleHash)veh.Model.Hash, Util.Util.GetPedSeat(Game.Player.Character)) &&
                    WeaponDataProvider.DoesVehicleSeatHaveMountedGuns((VehicleHash)veh.Model.Hash) &&
                    Util.Util.GetPedSeat(Game.Player.Character) == -1)
                {
                    obj.Flag      |= (byte)VehicleDataFlags.HasAimData;
                    obj.AimCoords  = new GTANetworkShared.Vector3(0, 0, 0);
                    obj.WeaponHash = Main.GetCurrentVehicleWeaponHash(Game.Player.Character);
                    if (Game.IsEnabledControlPressed(0, Control.VehicleFlyAttack))
                    {
                        obj.Flag |= (byte)VehicleDataFlags.Shooting;
                    }
                }
                else if (WeaponDataProvider.DoesVehicleSeatHaveGunPosition((VehicleHash)veh.Model.Hash, Util.Util.GetPedSeat(Game.Player.Character)))
                {
                    obj.Flag      |= (byte)VehicleDataFlags.HasAimData;
                    obj.WeaponHash = 0;
                    obj.AimCoords  = Main.RaycastEverything(new Vector2(0, 0)).ToLVector();
                    if (Game.IsEnabledControlPressed(0, Control.VehicleAttack))
                    {
                        obj.Flag |= (byte)VehicleDataFlags.Shooting;
                    }
                }
                else
                {
                    if ((player.IsSubtaskActive(200) || player.IsSubtaskActive(190)) &&
                        Game.IsEnabledControlPressed(0, Control.Attack) &&
                        Game.Player.Character.Weapons.Current?.AmmoInClip != 0)
                    {
                        obj.Flag |= (byte)VehicleDataFlags.Shooting;
                        obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                    }

                    if (((player.IsSubtaskActive(200) || player.IsSubtaskActive(190)) &&
                         Game.Player.Character.Weapons.Current?.AmmoInClip != 0) ||
                        (Game.Player.Character.Weapons.Current?.Hash == WeaponHash.Unarmed &&
                         player.IsSubtaskActive(200)))
                    {
                        obj.Flag |= (byte)VehicleDataFlags.Aiming;
                        obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                    }

                    var outputArg = new OutputArgument();
                    Function.Call(Hash.GET_CURRENT_PED_WEAPON, Game.Player.Character, outputArg, true);
                    obj.WeaponHash = outputArg.GetResult <int>();

                    lock (Lock)
                    {
                        if (LastSyncPacket != null && LastSyncPacket is VehicleData &&
                            WeaponDataProvider.NeedsFakeBullets(obj.WeaponHash.Value) &&
                            (((VehicleData)LastSyncPacket).Flag & (byte)VehicleDataFlags.Shooting) != 0)
                        {
                            obj.Flag |= (byte)VehicleDataFlags.Shooting;
                            obj.Flag |= (byte)VehicleDataFlags.HasAimData;
                        }
                    }

                    obj.AimCoords = Main.RaycastEverything(new Vector2(0, 0)).ToLVector();
                }

                Vehicle trailer;

                if ((VehicleHash)veh.Model.Hash == VehicleHash.TowTruck ||
                    (VehicleHash)veh.Model.Hash == VehicleHash.TowTruck2)
                {
                    trailer = veh.TowedVehicle;
                }
                else if ((VehicleHash)veh.Model.Hash == VehicleHash.Cargobob ||
                         (VehicleHash)veh.Model.Hash == VehicleHash.Cargobob2 ||
                         (VehicleHash)veh.Model.Hash == VehicleHash.Cargobob3 ||
                         (VehicleHash)veh.Model.Hash == VehicleHash.Cargobob4)
                {
                    trailer = SyncEventWatcher.GetVehicleCargobobVehicle(veh);
                }
                else
                {
                    trailer = SyncEventWatcher.GetVehicleTrailerVehicle(veh);
                }

                if (trailer != null && trailer.Exists())
                {
                    obj.Trailer = trailer.Position.ToLVector();
                }

                if (Util.Util.GetResponsiblePed(veh) == player)
                {
                    obj.DamageModel = veh.GetVehicleDamageModel();
                }

                lock (Lock)
                {
                    LastSyncPacket = obj;
                }
            }
            else
            {
                bool aiming   = player.IsSubtaskActive(ESubtask.AIMED_SHOOTING_ON_FOOT) || player.IsSubtaskActive(ESubtask.AIMING_THROWABLE); // Game.IsControlPressed(0, GTA.Control.Aim);
                bool shooting = Function.Call <bool>(Hash.IS_PED_SHOOTING, player.Handle);

                GTA.Math.Vector3 aimCoord = new Vector3();
                if (aiming || shooting)
                {
                    aimCoord = Main.RaycastEverything(new Vector2(0, 0));
                }

                var obj = new PedData();
                obj.AimCoords    = aimCoord.ToLVector();
                obj.Position     = player.Position.ToLVector();
                obj.Quaternion   = player.Rotation.ToLVector();
                obj.PedArmor     = (byte)player.Armor;
                obj.PedModelHash = player.Model.Hash;
                obj.WeaponHash   = (int)player.Weapons.Current.Hash;
                obj.WeaponAmmo   = player.Weapons.Current.Ammo;
                obj.PlayerHealth = (byte)Util.Util.Clamp(0, player.Health, 255);
                obj.Velocity     = player.Velocity.ToLVector();

                obj.Flag = 0;

                if (player.IsRagdoll)
                {
                    obj.Flag |= (int)PedDataFlags.Ragdoll;
                }
                if (Function.Call <int>(Hash.GET_PED_PARACHUTE_STATE, Game.Player.Character.Handle) == 0 &&
                    Game.Player.Character.IsInAir)
                {
                    obj.Flag |= (int)PedDataFlags.InFreefall;
                }
                if (player.IsInMeleeCombat)
                {
                    obj.Flag |= (int)PedDataFlags.InMeleeCombat;
                }
                if (aiming || shooting)
                {
                    obj.Flag |= (int)PedDataFlags.Aiming;
                }
                if ((player.IsInMeleeCombat && Game.IsControlJustPressed(0, Control.Attack)))
                {
                    obj.Flag |= (int)PedDataFlags.Shooting;
                }
                if (Function.Call <bool>(Hash.IS_PED_JUMPING, player.Handle))
                {
                    obj.Flag |= (int)PedDataFlags.Jumping;
                }
                if (Function.Call <int>(Hash.GET_PED_PARACHUTE_STATE, Game.Player.Character.Handle) == 2)
                {
                    obj.Flag |= (int)PedDataFlags.ParachuteOpen;
                }
                if (player.IsInCover())
                {
                    obj.Flag |= (int)PedDataFlags.IsInCover;
                }
                if (!Function.Call <bool>((Hash)0x6A03BF943D767C93, player))
                {
                    obj.Flag |= (int)PedDataFlags.IsInLowerCover;
                }
                if (player.IsInCoverFacingLeft)
                {
                    obj.Flag |= (int)PedDataFlags.IsInCoverFacingLeft;
                }
                if (player.IsReloading)
                {
                    obj.Flag |= (int)PedDataFlags.IsReloading;
                }
                if (ForceAimData)
                {
                    obj.Flag |= (int)PedDataFlags.HasAimData;
                }
                if (player.IsSubtaskActive(ESubtask.USING_LADDER))
                {
                    obj.Flag |= (int)PedDataFlags.IsOnLadder;
                }
                if (Function.Call <bool>(Hash.IS_PED_CLIMBING, player) && !player.IsSubtaskActive(ESubtask.USING_LADDER))
                {
                    obj.Flag |= (int)PedDataFlags.IsVaulting;
                }
                if (Function.Call <bool>(Hash.IS_ENTITY_ON_FIRE, player))
                {
                    obj.Flag |= (int)PedDataFlags.OnFire;
                }
                if (player.IsDead)
                {
                    obj.Flag |= (int)PedDataFlags.PlayerDead;
                }

                if (player.IsSubtaskActive(168))
                {
                    obj.Flag |= (int)PedDataFlags.ClosingVehicleDoor;
                }

                if (player.IsSubtaskActive(161) || player.IsSubtaskActive(162) || player.IsSubtaskActive(163) ||
                    player.IsSubtaskActive(164))
                {
                    obj.Flag |= (int)PedDataFlags.EnteringVehicle;

                    obj.VehicleTryingToEnter =
                        Main.NetEntityHandler.EntityToNet(Function.Call <int>(Hash.GET_VEHICLE_PED_IS_TRYING_TO_ENTER,
                                                                              Game.Player.Character));

                    obj.SeatTryingToEnter = (sbyte)
                                            Function.Call <int>(Hash.GET_SEAT_PED_IS_TRYING_TO_ENTER,
                                                                Game.Player.Character);
                }

                obj.Speed = Main.GetPedWalkingSpeed(player);

                lock (Lock)
                {
                    LastSyncPacket = obj;
                }

                bool sendShootingPacket;

                if (!WeaponDataProvider.IsWeaponAutomatic(unchecked ((GTANetworkShared.WeaponHash)obj.WeaponHash.Value)))
                {
                    sendShootingPacket = (shooting && !player.IsSubtaskActive(ESubtask.AIMING_PREVENTED_BY_OBSTACLE) &&
                                          !player.IsSubtaskActive(ESubtask.MELEE_COMBAT));
                }
                else
                {
                    if (!_lastShooting && !player.IsSubtaskActive(ESubtask.MELEE_COMBAT))
                    {
                        sendShootingPacket = (shooting && !player.IsSubtaskActive(ESubtask.AIMING_PREVENTED_BY_OBSTACLE) &&
                                              !player.IsSubtaskActive(ESubtask.MELEE_COMBAT)) ||
                                             ((player.IsInMeleeCombat || player.IsSubtaskActive(ESubtask.MELEE_COMBAT)) &&
                                              Game.IsEnabledControlPressed(0, Control.Attack));
                    }
                    else
                    {
                        sendShootingPacket = (!player.IsSubtaskActive(ESubtask.AIMING_PREVENTED_BY_OBSTACLE) &&
                                              !player.IsSubtaskActive(ESubtask.MELEE_COMBAT) &&
                                              !player.IsReloading &&
                                              player.Weapons.Current.AmmoInClip > 0 &&
                                              Game.IsEnabledControlPressed(0, Control.Attack)) ||
                                             ((player.IsInMeleeCombat || player.IsSubtaskActive(ESubtask.MELEE_COMBAT)) &&
                                              Game.IsEnabledControlPressed(0, Control.Attack));
                    }

                    if (!sendShootingPacket && _lastShooting && !_lastBullet)
                    {
                        _lastBullet = true;
                        return;
                    }
                }

                _lastBullet = false;

                if (Game.Player.Character.IsRagdoll)
                {
                    sendShootingPacket = false;
                }

                if (!player.IsSubtaskActive(ESubtask.MELEE_COMBAT) && player.Weapons.Current.Ammo == 0)
                {
                    sendShootingPacket = false;
                }


                if (sendShootingPacket && !_lastShooting)
                {
                    _lastShooting = true;

                    _lastShot = DateTime.Now;

                    var     msg        = Main.Client.CreateMessage();
                    byte[]  bin        = null;
                    SyncPed syncPlayer = null;

                    if (Main.OnShootingLagCompensation)
                    {
                        syncPlayer = Main.GetPedDamagedByPlayer();
                    }

                    if (syncPlayer != null)
                    {
                        bin = PacketOptimization.WriteBulletSync(0, true, syncPlayer.RemoteHandle);
                        msg.Write((byte)PacketType.BulletPlayerSync);
                    }
                    else
                    {
                        bin = PacketOptimization.WriteBulletSync(0, true, aimCoord.ToLVector());
                        msg.Write((byte)PacketType.BulletSync);
                    }

                    msg.Write(bin.Length);
                    msg.Write(bin);

                    Main.Client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.BulletSync);

                    Main._bytesSent += bin.Length;
                    Main._messagesSent++;
                }
                else if (!sendShootingPacket && _lastShooting && DateTime.Now.Subtract(_lastShot).TotalMilliseconds > 50)
                {
                    _lastShooting = false;

                    var     msg        = Main.Client.CreateMessage();
                    byte[]  bin        = null;
                    SyncPed syncPlayer = null;
                    if (Main.OnShootingLagCompensation)
                    {
                        syncPlayer = Main.GetPedDamagedByPlayer();
                    }
                    if (syncPlayer != null)
                    {
                        bin = PacketOptimization.WriteBulletSync(0, false, syncPlayer.RemoteHandle);
                        msg.Write((byte)PacketType.BulletPlayerSync);
                    }
                    else
                    {
                        bin = PacketOptimization.WriteBulletSync(0, false, aimCoord.ToLVector());
                        msg.Write((byte)PacketType.BulletSync);
                    }
                    msg.Write(bin.Length);
                    msg.Write(bin);

                    Main.Client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.BulletSync);

                    Main._bytesSent += bin.Length;
                    Main._messagesSent++;
                }
            }
        }
Esempio n. 4
0
        private void UpdateVehicleMountedWeapon()
        {
            if (WeaponDataProvider.DoesVehicleSeatHaveGunPosition((VehicleHash)VehicleHash, VehicleSeat))
            {
                var delay = 30;
                //if ((VehicleHash) VehicleHash == GTA.Native.VehicleHash.Rhino) delay = 300;

                if (Game.GameTime - _lastVehicleAimUpdate > delay)
                {
                    Function.Call(Hash.TASK_VEHICLE_AIM_AT_COORD, Character, AimCoords.X, AimCoords.Y,
                                  AimCoords.Z);
                    _lastVehicleAimUpdate = Game.GameTime;
                }

                if (IsShooting)
                {
                    if (((VehicleHash)VehicleHash == GTA.VehicleHash.Rhino &&
                         DateTime.Now.Subtract(_lastRocketshot).TotalMilliseconds > 1000) ||
                        ((VehicleHash)VehicleHash != GTA.VehicleHash.Rhino))
                    {
                        _lastRocketshot = DateTime.Now;

                        var baseTurretPos =
                            MainVehicle.GetOffsetInWorldCoords(
                                WeaponDataProvider.GetVehicleWeaponMuzzle((VehicleHash)VehicleHash, false));
                        var doesBaseTurretDiffer =
                            WeaponDataProvider.DoesVehiclesMuzzleDifferFromVehicleGunPos(
                                (VehicleHash)VehicleHash);
                        var barrellLength = WeaponDataProvider.GetVehicleTurretLength((VehicleHash)VehicleHash);

                        var speed = 0xbf800000;
                        var hash  = WeaponHash.CombatPDW;
                        if ((VehicleHash)VehicleHash == GTA.VehicleHash.Rhino)
                        {
                            hash = (WeaponHash)1945616459;
                        }

                        Vector3 tPos = baseTurretPos;
                        if (
                            WeaponDataProvider.DoesVehicleHaveParallelWeapon((VehicleHash)VehicleHash, false) &&
                            VehicleSeat == 1)
                        {
                            var muzzle = WeaponDataProvider.GetVehicleWeaponMuzzle((VehicleHash)VehicleHash,
                                                                                   false);
                            tPos =
                                MainVehicle.GetOffsetInWorldCoords(new Vector3(muzzle.X * -1f, muzzle.Y, muzzle.Z));
                        }

                        if (doesBaseTurretDiffer)
                        {
                            var kekDir = (AimCoords - tPos);
                            kekDir.Normalize();
                            var rot    = Main.DirectionToRotation(kekDir);
                            var newDir = Main.RotationToDirection(new Vector3(0, 0, rot.Z));
                            newDir.Normalize();
                            tPos = tPos +
                                   newDir *
                                   WeaponDataProvider.GetVehicleWeaponMuzzle((VehicleHash)VehicleHash, true)
                                   .Length();
                        }


                        var turretDir = (AimCoords - tPos);
                        turretDir.Normalize();
                        var start = tPos + turretDir * barrellLength;
                        var end   = start + turretDir * 100f;

                        _lastStart = start;
                        _lastEnd   = end;

                        var damage = WeaponDataProvider.GetWeaponDamage(WeaponHash.Minigun);
                        if ((VehicleHash)VehicleHash == GTA.VehicleHash.Rhino)
                        {
                            damage = 210;
                        }

                        if (IsFriend())
                        {
                            damage = 0;
                        }

                        Function.Call(Hash.SHOOT_SINGLE_BULLET_BETWEEN_COORDS, start.X, start.Y, start.Z, end.X,
                                      end.Y, end.Z, damage, true, (int)hash, Character, true, false, speed);
                    }
                }
            }
            else if (!WeaponDataProvider.DoesVehicleSeatHaveMountedGuns((VehicleHash)VehicleHash) || VehicleSeat != -1)
            {
                if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeapon)
                {
                    //Function.Call(Hash.GIVE_WEAPON_TO_PED, Character, CurrentWeapon, 999, true, true);
                    //Function.Call(Hash.SET_CURRENT_PED_WEAPON, Character, CurrentWeapon, true);
                    //Character.Weapons.Give((WeaponHash)CurrentWeapon, -1, true, true);
                    //Character.Weapons.Select((WeaponHash) CurrentWeapon);
                    Character.Weapons.RemoveAll();
                    Character.Weapons.Give((WeaponHash)CurrentWeapon, -1, true, true);
                }

                if (IsShooting || IsAiming)
                {
                    if (!_lastDrivebyShooting)
                    {
                        Function.Call(Hash.SET_PED_CURRENT_WEAPON_VISIBLE, Character, false, false, false, false);

                        Function.Call(Hash.TASK_DRIVE_BY, Character, 0, 0, AimCoords.X, AimCoords.Y, AimCoords.Z,
                                      0, 0, 0, unchecked ((int)FiringPattern.SingleShot));
                    }
                    else
                    {
                        Function.Call(Hash.SET_PED_CURRENT_WEAPON_VISIBLE, Character, true, false, false, false);

                        Function.Call(Hash.SET_DRIVEBY_TASK_TARGET, Character, 0, 0, AimCoords.X, AimCoords.Y, AimCoords.Z);
                    }

                    var rightSide = (VehicleSeat + 2) % 2 == 0;

                    if (WeaponDataProvider.NeedsFakeBullets(CurrentWeapon))
                    {
                        const string rightDict = "veh@driveby@first_person@passenger_right_handed@throw";
                        const string leftDict  = "veh@driveby@first_person@driver@throw";

                        string drivebyDict = rightSide ? rightDict : leftDict;

                        Function.Call(Hash.TASK_PLAY_ANIM_ADVANCED, Character, Util.Util.LoadDict(drivebyDict),
                                      "sweep_low", Character.Position.X, Character.Position.Y, Character.Position.Z, Character.Rotation.X,
                                      Character.Rotation.Y, Character.Rotation.Z, -8f, -8f, -1, 0, rightSide ? 0.6f : 0.3f, 0, 0);
                    }

                    if (IsShooting)
                    {
                        Function.Call(Hash.SET_PED_INFINITE_AMMO_CLIP, Character, true);
                        Function.Call(Hash.SET_PED_AMMO, Character, CurrentWeapon, 10);


                        if (AimPlayer != null && AimPlayer.Position != null)
                        {
                            AimCoords = AimPlayer.Position;
                            AimPlayer = null;
                        }

                        if (!WeaponDataProvider.NeedsFakeBullets(CurrentWeapon))
                        {
                            Function.Call(Hash.SET_PED_SHOOTS_AT_COORD, Character, AimCoords.X, AimCoords.Y, AimCoords.Z,
                                          true);
                        }
                        else if (DateTime.Now.Subtract(_lastRocketshot).TotalMilliseconds > 500)
                        {
                            _lastRocketshot = DateTime.Now;

                            var damage  = WeaponDataProvider.GetWeaponDamage((WeaponHash)CurrentWeapon);
                            var speed   = 0xbf800000;
                            var weaponH = (WeaponHash)CurrentWeapon;

                            if (IsFriend())
                            {
                                damage = 0;
                            }

                            var start = Character.GetBoneCoord(rightSide ? Bone.SKEL_R_Hand : Bone.SKEL_L_Hand);
                            var end   = AimCoords;

                            Function.Call(Hash.SHOOT_SINGLE_BULLET_BETWEEN_COORDS, start.X, start.Y, start.Z,
                                          end.X,
                                          end.Y, end.Z, damage, true, (int)weaponH, Character, false, true, speed);
                        }
                    }

                    _lastVehicleAimUpdate = Game.GameTime;
                    _lastDrivebyShooting  = IsShooting || IsAiming;
                    Ped PlayerChar = Game.Player.Character;
                    if (Function.Call <bool>(Hash.HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY, PlayerChar, Character, true))
                    {
                        int boneHit    = -1;
                        var boneHitArg = new OutputArgument();

                        if (Function.Call <bool>(Hash.GET_PED_LAST_DAMAGE_BONE, PlayerChar, boneHitArg))
                        {
                            boneHit = boneHitArg.GetResult <int>();
                        }

                        LocalHandle them = new LocalHandle(Character.Handle, HandleType.GameHandle);
                        JavascriptHook.InvokeCustomEvent(api =>
                                                         api.invokeonLocalPlayerDamaged(them, CurrentWeapon, boneHit /*, playerHealth, playerArmor*/));
                    }

                    Function.Call(Hash.CLEAR_ENTITY_LAST_DAMAGE_ENTITY, Character);
                    Function.Call(Hash.CLEAR_ENTITY_LAST_DAMAGE_ENTITY, PlayerChar);
                }

                if (!IsShooting && !IsAiming && _lastDrivebyShooting && Game.GameTime - _lastVehicleAimUpdate > 200)
                {
                    Tasks task = Character.Task;
                    task.ClearAll();
                    task.ClearSecondary();
                    Function.Call(Hash.CLEAR_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK, Character);
                    //Function.Call(Hash.TASK_DRIVE_BY, Character, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    //Function.Call(Hash.SET_DRIVEBY_TASK_TARGET, Character, 0, 0, 0, 0, 0);
                    task.ClearLookAt();
                    //GTA.UI.Screen.ShowNotification("Done shooting");
                    //GTA.UI.Screen.ShowSubtitle("Done Shooting1", 300);
                    _lastDrivebyShooting = false;
                }
            }
        }