public VehicleDoorOpenRatioChangedArgs(Vehicle vehicle, VehicleDoor door, float ratio, uint time) { this.Vehicle = vehicle; this.Door = door; this.Ratio = ratio; this.Time = time; }
private static void OpenRandomDoor(Vehicle veh) { VehicleDoor[] doors = veh.GetDoors(); VehicleDoor vehicleDoor = (VehicleDoor)(int)doors[Database.Random.Next(doors.Length)]; veh.OpenDoor(vehicleDoor, false, true); }
private static void OpenRandomDoor(Vehicle veh) { VehicleDoor[] values = veh.GetDoors(); VehicleDoor rand = values[Database.Random.Next(values.Length)]; veh.OpenDoor(rand, false, true); }
private void CreateScene(Vector3 spawnPoint) { Random rand = new Random(); int index = rand.Next(VehiclesToSelectFrom.Length); string randomModelName = VehiclesToSelectFrom[index]; brokenVehicle = new Vehicle(randomModelName, spawnPoint); brokenVehicle.IsPersistent = true; VehicleDoor hood = brokenVehicle.Doors[4]; hood.IsOpen = true; vehicleBlip = brokenVehicle.AttachBlip(); vehicleBlip.IsFriendly = true; /// Finds a point on the side of the road and moves the vehicle to that point. Using this method: /// BOOL _GET_ROAD_SIDE_POINT_WITH_HEADING(float x, float y, float z, float heading, Vector3* outPosition); NativeFunction.Natives.xA0F8A7517A273C05 <bool>( spawnPoint.X + 20.0f, spawnPoint.Y + 20.0f, spawnPoint.Z, brokenVehicle.Heading, out Vector3 outPosition); vehicleDesiredPosition = outPosition; driver = brokenVehicle.CreateRandomDriver(); driverBlip = driver.AttachBlip(); driverBlip.IsFriendly = true; driver.IsPersistent = true; driver.BlockPermanentEvents = true; driver.Tasks.DriveToPosition(vehicleDesiredPosition, 30.0f, VehicleDrivingFlags.FollowTraffic); brokenVehicle.EngineHealth = 100.0f; }
public VehicleDoorStateChangedArgs(Vehicle vehicle, VehicleDoor door, VehicleDoorState state, bool spawnFlyingComponent) { this.Vehicle = vehicle; this.Door = door; this.State = state; this.SpawnFlyingComponent = spawnFlyingComponent; }
private async void OnEnterVehicle(int vehHandle, int seat) { var veh = new Vehicle(vehHandle); if (await Input.WaitForKeyRelease(Control.VehicleExit, ControlModifier.None, 500)) { Log.Debug($"Enter vehicle key was long pressed. Aborting closest door enter"); return; } if (veh.Handle != 0 && doorToSeat.Values.Contains((VehicleSeat)seat)) { Log.Verbose($"Entering vehicle with handle {vehHandle}"); var playerPos = Cache.PlayerPed.Position; var vehDoors = veh.Doors.GetAll(); var closestDoorDistance = 10000.0f; VehicleDoor closestDoor = null; foreach (var door in vehDoors) { if (doorIndexBones.ContainsKey(door.Index)) { var doorBone = doorIndexBones[door.Index]; var bonePos = veh.Bones[doorBone].Position; var distToBone = playerPos.DistanceToSquared(bonePos); if (distToBone < closestDoorDistance) { closestDoorDistance = distToBone; closestDoor = door; } } } if (closestDoor != null) { Log.Verbose($"Found a close door ({closestDoor.Index})"); if (!veh.IsSeatFree(doorToSeat[closestDoor.Index])) { return; } Log.Verbose($"Close door ({closestDoor.Index}) was free. Entering"); Cache.PlayerPed.Task.ClearAll(); Cache.PlayerPed.Task.EnterVehicle(veh, doorToSeat[closestDoor.Index]); } } }
public void VehicleSpawn(Vector3 position, float heading) { int maxVehicles = Population.maxVehicles; if (IsCityZone(Game.Player.Character.Position)) { maxVehicles = Population.maxVehicles * 2; } if (((this.vehicleCount < maxVehicles) && ((position != Vector3.Zero) && (Extensions.DistanceBetweenV3(position, this.startingLoc) >= minSpawnDistance))) && (Extensions.DistanceBetweenV3(position, Game.Player.Character.Position) >= minSpawnDistance)) { Vehicle vehicle = Extensions.SpawnVehicle(GetRandomVehicleModel(), position, heading); vehicle.EngineHealth = (RandoMath.CachedRandom.Next(0, 100) > 10) ? 0f : 1000f; vehicle.DirtLevel = 14f; VehicleDoor[] doors = vehicle.GetDoors(); int num3 = 0; while (true) { if (num3 >= 5) { int item = 0; while (true) { if (item >= 3) { break; } List <int> theList = new List <int>(); InputArgument[] arguments = new InputArgument[] { vehicle.Handle, item }; if (Function.Call <bool>(Hash._0x46E571A0E20D01F1, arguments)) { theList.Add(item); } if (theList.Count > 0) { int randomElementFromList = RandoMath.GetRandomElementFromList <int>(theList); InputArgument[] argumentArray2 = new InputArgument[] { vehicle.Handle, randomElementFromList }; Function.Call(Hash._0x9E5B5E4D2CCD2259, argumentArray2); } item++; } break; } VehicleDoor randomElementFromArray = RandoMath.GetRandomElementFromArray <VehicleDoor>(doors); vehicle.OpenDoor(randomElementFromArray, false, true); num3++; } } }
public static string GetVehicleDoorBoneName(VehicleDoor door) => GetVehicleDoorBoneName(door.Index);
public static Task SetDoorStateAsync(this IVehicle vehicle, VehicleDoor door, VehicleDoorState state) => AltVAsync.Schedule(() => vehicle.SetDoorStateExt(door, state));
public static Task <VehicleDoorState> GetDoorStateAsync(this IVehicle vehicle, VehicleDoor door) => AltVAsync.Schedule(() => vehicle.GetDoorStateExt(door));
/// <summary> /// Sets a vehicles door to a state /// </summary> /// <param name="vehicle">The vehicle</param> /// <param name="door">The door</param> /// <param name="state">The state</param> public static void SetDoorState(this IVehicle vehicle, VehicleDoor door, VehicleDoorState state) => vehicle.SetDoorState((byte)door, (byte)state);
/// <summary> /// Returns the current door state of a vehicles door /// </summary> /// <param name="vehicle">The vehicle</param> /// <param name="door">The door</param> /// <returns>The door state</returns> public static VehicleDoorState GetDoorState(this IVehicle vehicle, VehicleDoor door) => (VehicleDoorState)vehicle.GetDoorState((byte)door);
public static void CallVehicleDrop(string VehicleModel) { // Drop setup if (PlaySound) { AudioManager.PlaySound(DropSound.call); } Model VModel = new Model(VehicleModel); Model CModel = new Model(Config.PlaneModel); if (!VModel.IsValid || !CModel.IsValid) { AudioManager.StopSound(DropSound.call); return; } // Drop continuation. This is only reached if the models were valid Vector3 PlanePos = Game.Player.Character.Position + Game.Player.Character.UpVector * 80f + Game.Player.Character.ForwardVector * -35f; Vector3 ContainerPos = Game.Player.Character.Position + Game.Player.Character.UpVector * 75f + Game.Player.Character.ForwardVector * 10f; // Vehicle spawning and adjustments Vehicle CargoPlane = World.CreateVehicle(CModel, PlanePos); CargoPlane.Heading = (Game.Player.Character.Position - CargoPlane.Position).ToHeading(); VehicleDoor CargoDoor = CargoPlane.Doors.ToArray().FirstOrDefault(x => x.Index == VehicleDoorIndex.Trunk); VehicleDoor CargoDoor2 = CargoPlane.Doors.ToArray().FirstOrDefault(x => x.Index == VehicleDoorIndex.BackLeftDoor); if (CargoDoor != null) { CargoDoor.Open(true, true); } if (CargoDoor2 != null) { CargoDoor2.Open(true, true); } // Cargoplane pilot Vector3 FlyTo = Util.LerpByDistance(CargoPlane.Position, Game.Player.Character.Position, 5000f); Ped CargoPilot = CargoPlane.CreatePedOnSeat(VehicleSeat.Driver, new Model("s_m_m_pilot_02")); // Cargoplane AI Function.Call(Hash.SET_VEHICLE_FORWARD_SPEED, CargoPlane, 50f); Wait(500); Function.Call(Hash.TASK_PLANE_MISSION, CargoPilot, CargoPlane, 0, 0, FlyTo.X, FlyTo.Y, FlyTo.Z, 4, 100f, 0f, 90f, 0, 200f); // Container drop Prop Container = World.CreateProp(Globals.ContainerModel, ContainerPos, true, false); Container.HasGravity = true; Container.ApplyForce(new Vector3(0f, 0f, -35f)); while (!Container.HasCollided) { Wait(0); } // Hit sound if (PlaySound) { AudioManager.StopSound(DropSound.call); AudioManager.PlaySound(DropSound.hit); } // Ensure the container is fully stopped Vector3 ContainerLastPos; do { ContainerLastPos = Container.Position; Wait(250); }while (Container.Position.DistanceTo(ContainerLastPos) > 0.1f); // Container opening Function.Call(Hash.REQUEST_NAMED_PTFX_ASSET, "proj_indep_firework_v2"); Function.Call(Hash.USE_PARTICLE_FX_ASSET, "proj_indep_firework_v2"); int ptfx = Function.Call <int>(Hash.START_PARTICLE_FX_NON_LOOPED_ON_ENTITY, "scr_firework_indep_ring_burst_rwb", Container, 0f, 0f, Container.Model.Dimensions.rearBottomLeft.X * 1f, 0f, 0f, 0f, 2f, true, true, true); Function.Call(Hash.SET_PARTICLE_FX_LOOPED_ALPHA, ptfx, 0.5f); Function.Call(Hash.SET_PARTICLE_FX_LOOPED_COLOUR, ptfx, 0.2f, 0.2f, 1f, true); Script.Wait(250); Vector3 SpawnPos = Container.Position; Container.Delete(); // Vehicle moving Vehicle NewVehicle = World.CreateVehicle(VModel, SpawnPos); NewVehicle.PlaceOnGround(); NewVehicle.IsPersistent = false; // Cleanup Wait(2500); if (!Config.FunMode) { CargoPilot.Task.ClearAll(); CargoPlane.MarkAsNoLongerNeeded(); } if (PlaySound) { AudioManager.StopSound(DropSound.hit); } }
public void OnActiveUpdate() { if (controller.IsPlayer) { for (int i = 0; i < ControlsToDisable.Length; i++) { NativeFunction.Natives.DisableControlAction(0, (int)ControlsToDisable[i]); } if (NativeFunction.Natives.IsDisabledControlPressed <bool>(0, (int)GameControl.Attack)) { // TODO: extract code to method, and allow AI peds to use the saw Vector3 start = saw.LeftPosition + saw.RightVector * 0.2f; Vector3 end = start - saw.RightVector * 0.25f; HitResult hitResult = World.TraceCapsule(start, end, 0.15f, TraceFlags.IntersectEverything, controller.Ped, saw); #if DEBUG Util.DrawLine(start, end, System.Drawing.Color.Red); Util.DrawMarker(28, start, Vector3.Zero, Rotator.Zero, new Vector3(0.05f), System.Drawing.Color.Red); #endif if (hitResult.Hit && hitResult.HitEntity) { if (hitResult.HitEntity != currentEntity) { currentEntity = hitResult.HitEntity; isVehicle = currentEntity is Vehicle; isPed = !isVehicle && currentEntity is Ped; isObject = !isVehicle && !isPed; vehicleDoors = isVehicle ? ((Vehicle)currentEntity).GetDoors() : null; closestVehicleDoorBoneName = null; closestVehicleDoorIndex = -1; vehicleDoorDetachedPercentage = 0.0f; if (breakingPercentageBar != null) { breakingPercentageBar.Delete(); breakingPercentageBar = null; } } #if DEBUG Util.DrawMarker(2, currentEntity.AbovePosition + currentEntity.UpVector * 1.25f, Vector3.Zero, new Rotator(180f, 0f, 0f), new Vector3(0.5f), System.Drawing.Color.Red, true); #endif if ((Game.GameTime - lastParticleStartGameTime) > gameTimeForNextParticleStart) { if (isVehicle) { Util.StartParticleFxNonLoopedOnEntity("des_fib_floor", "ent_ray_fbi5a_ramp_metal_imp", saw, new Vector3(-0.715f, 0.005f, 0f), new Rotator(0f, 0f, 25f), 0.75f); Util.StartParticleFxNonLoopedOnEntity("des_fib_floor", "ent_ray_fbi5a_ramp_metal_imp", saw, new Vector3(-0.715f, 0.005f, 0f), new Rotator(0f, 0f, 155f), 0.75f); } else if (isPed) { // "cut_solomon5", "cs_sol5_blood_head_shot" // "cut_michael2", "liquid_splash_blood" Util.StartParticleFxNonLoopedOnEntity("cut_solomon5", "cs_sol5_blood_head_shot", saw, new Vector3(-0.715f, 0.005f, 0f), new Rotator(0f, 0f, 25f), MathHelper.GetRandomSingle(2.0f, 4.25f)); Util.StartParticleFxNonLoopedOnEntity("cut_solomon5", "cs_sol5_blood_head_shot", saw, new Vector3(-0.715f, 0.005f, 0f), new Rotator(0f, 0f, 155f), MathHelper.GetRandomSingle(2.0f, 4.25f)); NativeFunction.Natives.PlayPain(currentEntity, MathHelper.GetRandomInteger(6, 7), 0, 0); } else if (isObject) { // TODO Util.StartParticleFxNonLoopedOnEntity("des_fib_floor", "ent_ray_fbi5a_ramp_metal_imp", saw, new Vector3(-0.715f, 0.005f, 0f), new Rotator(0f, 0f, 25f), 0.75f); Util.StartParticleFxNonLoopedOnEntity("des_fib_floor", "ent_ray_fbi5a_ramp_metal_imp", saw, new Vector3(-0.715f, 0.005f, 0f), new Rotator(0f, 0f, 155f), 0.75f); } lastParticleStartGameTime = Game.GameTime; gameTimeForNextParticleStart = (uint)MathHelper.GetRandomInteger(100, 275); } if (isVehicle) { Vehicle v = (Vehicle)currentEntity; string closestBoneName = null; int closestIndex = 0; float closestDistSqr = 999999f * 999999f; Vector3 sawPos = saw.LeftPosition; for (int i = 0; i < vehicleDoors.Length; i++) { VehicleDoor d = vehicleDoors[i]; if (!d.IsDamaged) { string boneName = Util.GetVehicleDoorBoneName(d); Vector3 pos = v.GetBonePosition(boneName); float distSqr = Vector3.DistanceSquared(sawPos, pos); if (distSqr < closestDistSqr) { closestDistSqr = distSqr; closestBoneName = boneName; closestIndex = d.Index; } } } #if DEBUG Game.DisplayHelp($"Closest:{closestBoneName}~n~DistSqr:{closestDistSqr}~n~Dist:{System.Math.Sqrt(closestDistSqr)}"); #endif if (closestBoneName != null && closestDistSqr < 1.5f * 1.5f) { if (closestVehicleDoorBoneName != closestBoneName) { closestVehicleDoorBoneName = closestBoneName; closestVehicleDoorIndex = closestIndex; vehicleDoorDetachedPercentage = 0.0f; } if (breakingPercentageBar == null) { breakingPercentageBar = new PercentageBar(closestVehicleDoorBoneName); } vehicleDoorDetachedPercentage += 0.0825f * Game.FrameTime; breakingPercentageBar.Percentage = vehicleDoorDetachedPercentage; #if DEBUG Game.DisplaySubtitle("~b~" + vehicleDoorDetachedPercentage); #endif if (vehicleDoorDetachedPercentage >= 1f) { v.Doors[closestVehicleDoorIndex].BreakOff(); breakingPercentageBar.Delete(); breakingPercentageBar = null; API.Functions.OnVehicleDoorRemovedWithSaw(v, closestVehicleDoorIndex, Game.LocalPlayer.Character, true); } } else { if (breakingPercentageBar != null) { breakingPercentageBar.Delete(); breakingPercentageBar = null; } } } else if (isPed) { Ped p = (Ped)currentEntity; if (p.IsAlive) { p.Health -= 3; } } else if (isObject) { // TODO // idea: when cutting a garage door, teleport player to a mp garage; would be cool for extinguishing fires in interiors } } else { CleanCurrentEntity(); } } else { CleanCurrentEntity(); } if ((Game.GameTime - gameTimeSincePedStartedAnimation) > 2000 && !NativeFunction.Natives.IsEntityPlayingAnim <bool>(controller.Ped, "weapons@heavy@minigun", "idle_2_aim_right_med", 3)) // TODO: change animation { controller.Ped.Tasks.PlayAnimation("weapons@heavy@minigun", "idle_2_aim_right_med", 1.0f, AnimationFlags.SecondaryTask | AnimationFlags.StayInEndFrame | AnimationFlags.UpperBodyOnly); gameTimeSincePedStartedAnimation = Game.GameTime; } } }