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); }
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; } } }