public bool AbortCallout() { Game.LogTrivial("[FireyCallouts][Log] Abort 'Structural Fire' callout. Locations too far away (> 800)."); // Clean up if not accepted if (suspect.Exists()) { suspect.Delete(); } if (locationBlip.Exists()) { locationBlip.Delete(); } foreach (uint f in fireList) { NativeFunction.Natives.RemoveScriptFire(f); //NativeFunction.CallByName<uint>("REMOVE_SCRIPT_FIRE", f); } // Remove emergency services foreach (Vehicle ev in emergencyVehicles) { if (ev.Exists()) { ev.Delete(); } } Game.LogTrivial("[FireyCallouts][Log] Cleaned up 'Structural Fire' callout."); return(false); }
// If we don't accept the callout this will be called and we will clear anything that we have spawned to prevent it staying in the game. public override void OnCalloutNotAccepted() { base.OnCalloutNotAccepted(); if (Aggressor.Exists()) { Aggressor.Delete(); } if (Aggressor2.Exists()) { Aggressor2.Delete(); } if (Victim.Exists()) { Victim.Delete(); } if (PedoVan.Exists()) { PedoVan.Delete(); } if (ABlip.Exists()) { ABlip.Delete(); } if (ABlip2.Exists()) { ABlip2.Delete(); } if (B1.Exists()) { B1.Delete(); } }
public bool AbortCallout() { Game.LogTrivial("[FireyCallouts][Log] Abort 'Campfire' callout. Locations too far away (> 800)."); // Clean up if not accepted if (suspect.Exists()) { suspect.Delete(); } if (suspectVehicle.Exists()) { suspectVehicle.Delete(); } if (suspectBlip.Exists()) { suspectBlip.Delete(); } // Remove emergency services foreach (Vehicle ev in emergencyVehicles) { if (ev.Exists()) { ev.Delete(); } } Game.LogTrivial("[FireyCallouts][Log] Cleaned up 'Campfire' callout."); return(false); }
static internal void OnItemSelectHandler(UIMenu sender, UIMenuItem item, int index) { switch (item.Text) { case "~g~Add Dealer Location": if (Ped == null) { UIHelper.ShowNotification("Set a ped model and rotation"); } else { DevelopmentFunctions.SetDealerLocation(Ped.Position, Rotation, CurrentPedHash); } break; case "~r~Clear Ped": if (Ped != null) { Ped.Delete(); } break; case "~r~Remove Dealer Location": if (DatabaseHandler.dealerInRangeIndex == null) { UIHelper.ShowNotification("No dealer in range"); } else { DatabaseHandler.removeDealer = DatabaseHandler.dealerInRangeIndex; } break; } }
public override void End() { CalloutRunning = false; NativeFunction.Natives.RESET_AI_MELEE_WEAPON_DAMAGE_MODIFIER(); if (PlayerPed.Exists()) { if (PlayerPed.IsDead) { GameFiber.Wait(1500); Functions.PlayScannerAudio("OFFICER HAS_BEEN_FATALLY_SHOT NOISE_SHORT OFFICER_NEEDS_IMMEDIATE_ASSISTANCE"); GameFiber.Wait(3000); } } if (CalloutFinished) { if (Passenger.Exists()) { Passenger.Dismiss(); } } else { if (Passenger.Exists()) { Passenger.Delete(); } } base.End(); }
public static void Process() { foreach (var pedH in peds) { Ped ped = World.CreatePed(pedH, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 2.0f); if (ped != null) { Script.Wait(100); Style style = ped.Style; var pedData = Main.Storage.AddPed(pedH, new PedData { hash = pedH }); var components = style.GetAllComponents(); for (int i = 0; i < components.Length; i++) { var slotdata = new ClothSlotData(); pedData.slots.Add(i, slotdata); PedStyleSlotProcessor.Process(ped, i, components[i], slotdata); } ped.Delete(); } } }
public override void OnCalloutNotAccepted() { if (_AG1) { _AG1.Delete(); } if (_AG2) { _AG2.Delete(); } if (_V1) { _V1.Delete(); } if (_V2) { _V2.Delete(); } if (_V3) { _V3.Delete(); } if (_V4) { _V4.Delete(); } base.OnCalloutNotAccepted(); }
public override void OnCalloutNotAccepted() { if (_AG1.Exists()) { _AG1.Delete(); } if (_AG2.Exists()) { _AG2.Delete(); } if (_V1.Exists()) { _V1.Delete(); } if (_V2.Exists()) { _V2.Delete(); } if (_V3.Exists()) { _V3.Delete(); } if (_V4.Exists()) { _V4.Delete(); } base.OnCalloutNotAccepted(); }
public static void DeletePed(Ped currPed) { if (currPed.Exists()) { currPed.Delete(); } }
/// <summary> /// Test environment. /// </summary> public static void Main() { PedModels.BuildLookupDictionary(); while (true) { foreach (KeyValuePair <string, PedModelMeta> modelMeta in PedModels.PedModelMetaLookup) { Ped demoPed = new Ped(modelMeta.Key, Game.LocalPlayer.Character.GetOffsetPositionFront(1.5f), 0f); demoPed.Face(Game.LocalPlayer.Character); Game.DisplayNotification($"{demoPed.Model.Name}: {PedModels.GetTextDescription(demoPed, PedDescriptionPropertyType.Build | PedDescriptionPropertyType.Clothing | PedDescriptionPropertyType.Extras | PedDescriptionPropertyType.Hair | PedDescriptionPropertyType.RaceSex)}"); GameFiber.Sleep(8000); if (demoPed) { demoPed.Delete(); } } GameFiber.Yield(); } }
public void Remove() { while (Objects.Count > 0) { Prop p = Objects[Objects.Count - 1]; p.Delete(); Objects.RemoveAt(Objects.Count - 1); } while (Vehicles.Count > 0) { Vehicle v = Vehicles[Vehicles.Count - 1]; v.Delete(); Vehicles.RemoveAt(Vehicles.Count - 1); } while (Peds.Count > 0) { Ped p = Peds[Peds.Count - 1]; p.Delete(); Peds.RemoveAt(Peds.Count - 1); } if (Blip.Exists(CurrentBlip)) { CurrentBlip.Remove(); } }
protected override void Dispose(bool A_0) { if (A_0) { if (boss != null) { boss.Delete(); } if (maleStaff != null) { maleStaff.Delete(); } if (femaleStaff != null) { femaleStaff.Delete(); } if (pa != null) { pa.Delete(); } if (paChair != null) { paChair.Delete(); } } }
/// <summary> /// Clean up remnants of the heli. /// </summary> /// <param name="force">If <c>true</c>, all occupants (pilot & crew) will be deleted as well</param> public virtual void destructor(bool force = false) { _isActive = false; try { // delete the blip heli.AttachedBlip.Delete(); // if destroying by force if (force) { pilot.Delete(); foreach (Ped passenger in passengers) { passenger.Delete(); } heli.Delete(); } // if destroying gracefully, command the pilot to fly away. Mark the Heli and crew as no longer needed. else { pilot.Task.FleeFrom(_leader); pilot.MarkAsNoLongerNeeded(); foreach (Ped passenger in passengers) { passenger.MarkAsNoLongerNeeded(); } heli.MarkAsNoLongerNeeded(); } } catch { } }
/// <summary> /// Spawn an allied <c>Ped</c> into a seat of the Heli, and give the specified weapons /// </summary> /// <param name="seat">Seat to spawn Ped into</param> /// <param name="weaponArray">Array of <c>WeaponHash</c> to give the gunner</param> /// <param name="pedModel"><c>Model</c> of Ped to spawn</param> /// <returns><c>Ped</c> just spawned</returns> protected Ped spawnCrewGunner(VehicleSeat seat, WeaponHash[] weaponArray, Model pedModel) { // if seat is occupied, delete the NPC in the seat Ped seatOccupant = heli.GetPedOnSeat(seat); if (seatOccupant != null) { seatOccupant.Delete(); } // spawn the crew into the specified seat Ped gunner = heli.CreatePedOnSeat(seat, pedModel); // ally the crew to the player gunner.RelationshipGroup = _rg; // give crew weapons in weaponArray, plus a standard issue sidearm giveWeapons(gunner, weaponArray); // task crew with fighting any enemies gunner.FiringPattern = fp; gunner.Task.FightAgainstHatedTargets(9999f); gunner.AlwaysKeepTask = true; gunner.CanRagdoll = false; gunner.CanWrithe = false; return(gunner); }
public override void End() { CalloutRunning = false; if (Game.LocalPlayer.Character.Exists()) { if (Game.LocalPlayer.Character.IsDead) { GameFiber.Wait(1500); Functions.PlayScannerAudio("OFFICER HAS_BEEN_FATALLY_SHOT NOISE_SHORT OFFICER_NEEDS_IMMEDIATE_ASSISTANCE"); GameFiber.Wait(3000); } } else { GameFiber.Wait(1500); Functions.PlayScannerAudio("OFFICER HAS_BEEN_FATALLY_SHOT NOISE_SHORT OFFICER_NEEDS_IMMEDIATE_ASSISTANCE"); GameFiber.Wait(3000); } if (CalloutFinished) { if (Passenger.Exists()) { Passenger.Dismiss(); } } else { if (Passenger.Exists()) { Passenger.Delete(); } } base.End(); }
public override void OnCalloutNotAccepted() { if (_A1) { _A1.Delete(); } if (_A2) { _A2.Delete(); } if (_A3) { _A3.Delete(); } if (_Cop1) { _Cop1.Delete(); } if (_Cop2) { _Cop2.Delete(); } if (_CopCar1) { _CopCar1.Delete(); } if (_CopCar2) { _CopCar2.Delete(); } base.OnCalloutNotAccepted(); }
public static Ped ClonePed(this Ped oldPed) { Vector3 oldPedPosition = oldPed.Position; float oldPedHeading = oldPed.Heading; bool spawnInVehicle = false; Vehicle car = null; int seatindex = 0; int oldarmor = oldPed.Armor; int oldhealth = oldPed.Health; if (oldPed.IsInAnyVehicle(false)) { car = oldPed.CurrentVehicle; seatindex = oldPed.SeatIndex; spawnInVehicle = true; } Ped newPed = NativeFunction.Natives.ClonePed <Ped>(oldPed, oldPed.Heading, false, true); if (oldPed.Exists() && oldPed.IsValid()) { oldPed.Delete(); } newPed.Position = oldPedPosition; newPed.Heading = oldPedHeading; if (spawnInVehicle) { newPed.WarpIntoVehicle(car, seatindex); } newPed.Health = oldhealth; newPed.Armor = oldarmor; newPed.BlockPermanentEvents = true; newPed.IsPersistent = true; return(newPed); }
public override void OnCalloutNotAccepted() { base.OnCalloutNotAccepted(); if (driver.Exists()) { driver.Delete(); } if (passenger.Exists()) { passenger.Delete(); } if (car.Exists()) { car.Delete(); } }
public override void OnCalloutNotAccepted() { // If the player didn't accept the callout we cleanup this mess if (A1.Exists()) { A1.Delete(); } if (A2.Exists()) { A2.Delete(); } if (FastVehicle.Exists()) { FastVehicle.Delete(); } if (B1.Exists()) { B1.Delete(); } if (B2.Exists()) { B2.Delete(); } base.OnCalloutNotAccepted(); }
/// <summary> /// If you don't accept the callout this will be called, we clear anything we spawned here to prevent it staying in the game /// </summary> public override void OnCalloutNotAccepted() { base.OnCalloutNotAccepted(); if (myPed.Exists()) { myPed.Delete(); } if (myVehicle.Exists()) { myVehicle.Delete(); } if (myBlip.Exists()) { myBlip.Delete(); } }
public override void Destroy() { if (GameReference.Exists()) { GameReference.Delete(); } }
public static void Command_DeletePed([ConsoleCommandParameter(AutoCompleterType = typeof(ConsoleCommandAutoCompleterPed))] Ped ped) { if (ped) { ped.Delete(); } }
/// <summary> /// If you don't accept the callout this will be called, we clear anything we spawned here to prevent it staying in the game /// </summary> public override void OnCalloutNotAccepted() { state = EWantedFelonInVehicleState.End; if (ped.Exists()) { ped.Delete(); } if (pedVehicle.Exists()) { pedVehicle.Delete(); } if (searchZoneBlip.Exists()) { searchZoneBlip.Delete(); } if (notFleeBlip.Exists()) { notFleeBlip.Delete(); } if (heliPilot.Exists()) { heliPilot.CleanUpHeliPilot(); } base.OnCalloutNotAccepted(); }
protected override void Dispose(bool A_0) { if (A_0) { dispose_escape(); SimpleLog.Info("Prison Mod is Restarted"); Function.Call(Hash.ENABLE_ALL_CONTROL_ACTIONS, new InputArgument[] { 1 }); Game.Player.CanControlCharacter = true; Function.Call(Hash.SET_ENABLE_HANDCUFFS, new InputArgument[] { Game.Player.Character, 0 }); Function.Call(Hash.SET_ENABLE_BOUND_ANKLES, new InputArgument[] { Game.Player.Character, 0 }); Function.Call(Hash.SET_MAX_WANTED_LEVEL, new InputArgument[] { 5 }); if (police != null) { police.Delete(); } if (escape_Ped != null) { escape_Ped.Delete(); } if (policecar != null) { policecar.Delete(); } } }
protected override void RemoveFromWorld() { if (Ped != null && Ped.Exists()) { Ped.Delete(); } }
public void Tick() { if (!EntryInProgress) { return; } if (_plane.IsInRangeOf(_corridor, 10f)) { Function.Call(Hash.TASK_PLANE_LAND, _pilot.Handle, _plane.Handle, _runwayStart.X, _runwayStart.Y, _runwayStart.Z, _runwayEnd.X, _runwayEnd.Y, _runwayEnd.Z); UI.Notify("~b~ATC:~w~ Cleared to land, over."); disembarkStarted = true; } if (_plane.Speed < 1f && disembarkStarted) { var ped1 = _plane.GetPedOnSeat(VehicleSeat.Passenger); var ped2 = _plane.GetPedOnSeat(VehicleSeat.LeftRear); var ped3 = _plane.GetPedOnSeat(VehicleSeat.RightRear); var ped4 = _plane.GetPedOnSeat((VehicleSeat)3); ped1?.Task.LeaveVehicle(); ped2?.Task.LeaveVehicle(); ped3?.Task.LeaveVehicle(); ped4?.Task.LeaveVehicle(); EntryInProgress = false; } if (!_plane.IsInRangeOf(Game.Player.Character.Position, 200f) && disembarkStarted) { _pilot.Delete(); _plane.Delete(); disembarkStarted = false; EntryInProgress = false; return; } if (_pilot.IsDead || _plane.IsDead) { _pilot.Delete(); _plane.Delete(); disembarkStarted = false; EntryInProgress = false; return; } }
private static void Command_DespawnLastPed() { if (lastPed != null) { lastPed.Delete(); lastPed = null; } }
/// <summary> /// This method will respawn this PlayerPed /// </summary> public void Respawn() { if (Ped != null) { Ped.Delete(); } SetupPed(); }
public override void OnCalloutNotAccepted() { base.OnCalloutNotAccepted(); if (driver.Exists()) { driver.Delete(); } if (car.Exists()) { car.Delete(); } if (TrafficPolicerHandler.OtherUnitRespondingAudio) { Functions.PlayScannerAudio("OTHER_UNIT_TAKING_CALL"); } }
private async Task StartGathering(Ped target) { _canGather = false; _isGathering = true; _targetedPed = target; _gatherTimeLeft = _random.Next(GatherTimeMin, GatherTimeMax); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. mugTimeUI(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. async Task mugTimeUI() { while (_isGathering) { Utility.Instance.DrawTxt(0.5f, 0.1f, 0, 0, 1, "Skinning and gathering fromt the animal! " + _gatherTimeLeft + " Seconds Left!", 255, 255, 0, 255, true); await Delay(0); } } var amount = _gatherTimeLeft; for (int i = 0; i < amount; i++) { if (Game.IsControlPressed(0, Control.Context) && Utility.Instance.GetDistanceBetweenVector3s(Game.PlayerPed.Position, target.Position) < 8) { _gatherTimeLeft = _gatherTimeLeft - 1; await Delay(1000); } else { CancelGathering(); return; } } Debug.WriteLine(Convert.ToString(_gatherTimeLeft)); _isGathering = false; if (target.Model == PedHash.Boar) { TriggerServerEvent("HuntingReward"); TriggerServerEvent("HuntingReward"); } else if (target.Model == PedHash.MountainLion) { TriggerServerEvent("HuntingReward"); TriggerServerEvent("HuntingReward"); TriggerServerEvent("HuntingReward"); } else if (target.Model == PedHash.Rabbit) { TriggerServerEvent("HuntingReward"); } else if (target.Model == PedHash.Deer) { TriggerServerEvent("HuntingReward"); TriggerServerEvent("HuntingReward"); } target.IsPositionFrozen = false; target.Task.ClearAll(); target.Delete(); }
private void AdvanceStage() { TimerBars = new TimerBars(); CurrentStage++; CurrentObjectives.Clear(); foreach (var veh in CurrentMission.Vehicles.Where(v => v.SpawnAfter == CurrentStage)) { var newv = new Vehicle(Util.RequestModel(veh.ModelHash), veh.Position) { PrimaryColor = Color.FromArgb((int)veh.PrimaryColor.X, (int)veh.PrimaryColor.Y, (int)veh.PrimaryColor.Z), SecondaryColor = Color.FromArgb((int)veh.SecondaryColor.X, (int)veh.SecondaryColor.Y, (int)veh.SecondaryColor.Z), }; newv.Health = veh.Health; newv.Rotation = veh.Rotation; GameFiber.StartNew(delegate { while (IsMissionPlaying && (veh.RemoveAfter == 0 || veh.RemoveAfter > CurrentStage)) { if (veh.FailMissionOnDeath && newv.IsDead) { FailMission(reason: "The vehicle has been destroyed."); } GameFiber.Yield(); } if(newv.IsValid()) newv.Delete(); }); } foreach (var veh in CurrentMission.Objectives.OfType<SerializableVehicleObjective>().Where(v => v.SpawnAfter == CurrentStage)) { var newv = new Vehicle(Util.RequestModel(veh.ModelHash), veh.Position) { PrimaryColor = Color.FromArgb((int)veh.PrimaryColor.X, (int)veh.PrimaryColor.Y, (int)veh.PrimaryColor.Z), SecondaryColor = Color.FromArgb((int)veh.SecondaryColor.X, (int)veh.SecondaryColor.Y, (int)veh.SecondaryColor.Z), }; newv.Health = veh.Health; newv.Rotation = veh.Rotation; var hasActivated = false; if (veh.ActivateAfter == CurrentStage) { CurrentObjectives.Add(veh); hasActivated = true; } GameFiber.StartNew(delegate { if(!hasActivated) { while (CurrentStage != veh.ActivateAfter && IsMissionPlaying) { GameFiber.Yield(); } CurrentObjectives.Add(veh); } var blip = newv.AttachBlip(); if(veh.ObjectiveType == 0) { blip.Color = Color.DarkRed; while (!newv.IsDead && IsMissionPlaying) { if (veh.ShowHealthBar) { TimerBars.UpdateValue(newv.Handle.Value.ToString(), veh.Name, true, (100f*newv.Health / veh.Health).ToString("###") + "%"); } GameFiber.Yield(); } TimerBars.UpdateValue(newv.Handle.Value.ToString(), veh.Name, true, "0%"); } if (veh.ObjectiveType == 1) { blip.Color = Color.CornflowerBlue; while (!Game.LocalPlayer.Character.IsInVehicle(newv, false) && IsMissionPlaying) { GameFiber.Yield(); } } CurrentObjectives.Remove(veh); if(blip.IsValid()) blip.Delete(); while (IsMissionPlaying) GameFiber.Yield(); if (newv.IsValid()) newv.Delete(); }); } if (CurrentMission.Spawnpoints.Any(s => s.SpawnAfter == CurrentStage)) { var sp = CurrentMission.Spawnpoints.First(s => s.SpawnAfter == CurrentStage); Game.FadeScreenOut(100, true); Game.LocalPlayer.Character.Position = sp.Position - new Vector3(0,0,1); Game.LocalPlayer.Character.Rotation = sp.Rotation; Game.LocalPlayer.Model = Util.RequestModel(sp.ModelHash); if (sp.WeaponHash != 0) Game.LocalPlayer.Character.GiveNewWeapon(sp.WeaponHash, sp.WeaponAmmo, true); Game.LocalPlayer.Character.Health = sp.Health; Game.LocalPlayer.Character.Armor = sp.Armor; if (sp.SpawnInVehicle) { var vehList = Game.LocalPlayer.Character.GetNearbyVehicles(15).OrderBy(v => (Game.LocalPlayer.Character.Position - v.Position).Length()); Game.LocalPlayer.Character.WarpIntoVehicle(vehList.ToList()[0], sp.VehicleSeat); } Game.FadeScreenIn(500, false); } foreach (var actor in CurrentMission.Actors.Where(v => v.SpawnAfter == CurrentStage)) { GameFiber.StartNew(delegate { var ped = new Ped(Util.RequestModel(actor.ModelHash), actor.Position - new Vector3(0,0,1f), actor.Rotation.Yaw); ped.Rotation = actor.Rotation; ped.Accuracy = actor.Accuracy; var blip = ped.AttachBlip(); blip.Scale = 0.6f; if (actor.WeaponHash != 0) ped.GiveNewWeapon(actor.WeaponHash, actor.WeaponAmmo, true); ped.Health = actor.Health; ped.Armor = actor.Armor; if (actor.RelationshipGroup == 0) { ped.RelationshipGroup = StaticData.RelationshipGroups.Groups[1]; blip.Color = Color.DodgerBlue; NativeFunction.CallByName<uint>("REMOVE_PED_FROM_GROUP", ped.Handle.Value); NativeFunction.CallByName<uint>("SET_PED_AS_GROUP_MEMBER", ped.Handle.Value, NativeFunction.CallByName<int>("GET_PED_GROUP_INDEX", Game.LocalPlayer.Character.Handle.Value)); } else { ped.RelationshipGroup = StaticData.RelationshipGroups.Groups[actor.RelationshipGroup]; if(actor.RelationshipGroup == 4 || actor.RelationshipGroup == 5) blip.Color = Color.DarkRed; } if (actor.SpawnInVehicle) { var vehList = ped.GetNearbyVehicles(15).OrderBy(v => (ped.Position - v.Position).Length()); ped.WarpIntoVehicle(vehList.ToList()[0], actor.VehicleSeat); } ped.BlockPermanentEvents = false; NativeFunction.CallByName<uint>("SET_PED_FIRING_PATTERN", ped.Handle.Value, 0xC6EE6B4C); if (actor.Behaviour == 3) ped.Tasks.FightAgainstClosestHatedTarget(100f); else if (actor.Behaviour == 2) NativeFunction.CallByName<uint>("TASK_GUARD_CURRENT_POSITION", ped.Handle.Value, 15f, 10f, true); else if (actor.Behaviour == 0) ped.Tasks.Clear(); else if (actor.Behaviour == 4) { GameFiber.StartNew(delegate { var wpyList = new List<SerializableWaypoint>(actor.Waypoints); SerializableWaypoint currentWaypoint; if (wpyList.Count > 0) currentWaypoint = wpyList[0]; while (ped.IsValid() && ped.Exists() && ped.IsAlive && IsMissionPlaying && wpyList.Count > 0) { if (wpyList.Count == 0) break; currentWaypoint = wpyList[0]; Task pedTask = null; switch (currentWaypoint.Type) { case WaypointTypes.Drive: if (ped.IsInAnyVehicle(true)) { pedTask = ped.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.VehicleSpeed, (DriveToPositionFlags)currentWaypoint.DrivingStyle); } break; case WaypointTypes.Run: { var heading = 0f; if (wpyList.Count >= 2) { heading = Util.DirectionToRotation(wpyList[1].Position - currentWaypoint.Position) .Z; } pedTask = ped.Tasks.FollowNavigationMeshToPosition(currentWaypoint.Position, heading, 2f, 0.3f, currentWaypoint.Duration == 0 ? -1 : (int)currentWaypoint.Duration); } break; case WaypointTypes.Walk: { var heading = 0f; if (wpyList.Count >= 2) { heading = Util.DirectionToRotation(wpyList[1].Position - currentWaypoint.Position) .Z; } pedTask = ped.Tasks.FollowNavigationMeshToPosition(currentWaypoint.Position, heading, 1f, 0.3f, currentWaypoint.Duration == 0 ? -1 : (int)currentWaypoint.Duration); } break; case WaypointTypes.ExitVehicle: if (ped.IsInAnyVehicle(true)) pedTask = ped.Tasks.LeaveVehicle(LeaveVehicleFlags.None); break; case WaypointTypes.EnterVehicle: Vehicle[] vehs = World.GetAllVehicles().Where(v => { if (v != null && v.IsValid()) return v.Model.Hash == currentWaypoint.VehicleTargetModel; return false; }).OrderBy(v => (v.Position - ped.Position).Length()).ToArray(); if (vehs.Any()) { if ((vehs[0].Position - ped.Position).Length() > 10f) { pedTask = ped.Tasks.FollowNavigationMeshToPosition(vehs[0].Position, 0f, 3f, 5f); pedTask.WaitForCompletion(10000); } var seat = vehs[0].GetFreeSeatIndex(); if (seat.HasValue) pedTask = ped.Tasks.EnterVehicle(vehs[0], seat.Value); } break; case WaypointTypes.Wait: pedTask = ped.Tasks.StandStill(currentWaypoint.Duration); break; case WaypointTypes.Wander: pedTask = ped.Tasks.Wander(); break; case WaypointTypes.Shoot: pedTask = null; NativeFunction.CallByName<uint>("TASK_SHOOT_AT_COORD", ped.Handle.Value, currentWaypoint.Position.X, currentWaypoint.Position.Y, currentWaypoint.Position.Z, currentWaypoint.Duration, 0xC6EE6B4C); GameFiber.Sleep(currentWaypoint.Duration); break; case WaypointTypes.Animation: pedTask = ped.Tasks.PlayAnimation(currentWaypoint.AnimDict, currentWaypoint.AnimName, 8f, AnimationFlags.None); break; } pedTask?.WaitForCompletion(currentWaypoint.Duration == 0 ? -1 : currentWaypoint.Duration); if (wpyList.Count > 0) wpyList.RemoveAt(0); GameFiber.Yield(); } }); } while (IsMissionPlaying && (actor.RemoveAfter == 0 || actor.RemoveAfter > CurrentStage) && !ped.IsDead) { GameFiber.Yield(); } if (actor.FailMissionOnDeath && ped.IsDead) { FailMission(reason: "An ally has died."); } if (blip.IsValid()) blip.Delete(); while(IsMissionPlaying && (actor.RemoveAfter == 0 || actor.RemoveAfter > CurrentStage)) GameFiber.Yield(); if(ped.IsValid()) ped.Delete(); }); } foreach (var o in CurrentMission.Objects.Where(v => v.SpawnAfter == CurrentStage)) { GameFiber.StartNew(delegate { var prop = new Rage.Object(Util.RequestModel(o.ModelHash), o.Position); prop.Position = o.Position; prop.Rotation = o.Rotation; while (IsMissionPlaying && (o.RemoveAfter == 0 || o.RemoveAfter > CurrentStage)) { GameFiber.Yield(); } if(prop.IsValid()) prop.Delete(); }); } foreach (var pickup in CurrentMission.Pickups.Where(v => v.SpawnAfter == CurrentStage)) { GameFiber.StartNew(delegate { var obj = NativeFunction.CallByName<uint>("CREATE_PICKUP_ROTATE", pickup.PickupHash, pickup.Position.X, pickup.Position.Y, pickup.Position.Z, pickup.Rotation.Pitch, pickup.Rotation.Roll, pickup.Rotation.Yaw, 1, pickup.Ammo, 2, 1, 0); int counter = 0; while (IsMissionPlaying && (pickup.RemoveAfter == 0 || pickup.RemoveAfter > CurrentStage)) { var alpha = 40 * (Math.Sin(Util.DegToRad(counter % 180))); Util.DrawMarker(28, pickup.Position, new Vector3(), new Vector3(0.75f, 0.75f, 0.75f), Color.FromArgb((int)alpha, 10, 10, 230)); counter += 5; if (counter >= 360) counter = 0; if ((pickup.Position - Game.LocalPlayer.Character.Position).Length() < 1f && pickup.Respawn) { NativeFunction.CallByName<uint>("REMOVE_PICKUP", obj); while((pickup.Position - Game.LocalPlayer.Character.Position).Length() < 3f) { GameFiber.Yield();} obj = NativeFunction.CallByName<uint>("CREATE_PICKUP_ROTATE", pickup.PickupHash, pickup.Position.X, pickup.Position.Y, pickup.Position.Z, pickup.Rotation.Pitch, pickup.Rotation.Roll, pickup.Rotation.Yaw, 1, pickup.Ammo, 2, 1, 0); } else if ((pickup.Position - Game.LocalPlayer.Character.Position).Length() < 1f && !pickup.Respawn) break; GameFiber.Yield(); } NativeFunction.CallByName<uint>("REMOVE_PICKUP", obj); }); } foreach (var actor in CurrentMission.Objectives.OfType<SerializableActorObjective>().Where(v => v.SpawnAfter == CurrentStage)) { var ped = new Ped(Util.RequestModel(actor.ModelHash), actor.Position - new Vector3(0, 0, 1f), actor.Rotation.Yaw); ped.Rotation = actor.Rotation; ped.Accuracy = actor.Accuracy; if (actor.WeaponHash != 0) ped.GiveNewWeapon(actor.WeaponHash, actor.WeaponAmmo, true); NativeFunction.CallByName<uint>("SET_PED_FIRING_PATTERN", ped.Handle.Value, 0xC6EE6B4C); ped.Health = actor.Health; ped.MaxHealth = actor.Health; ped.Armor = actor.Armor; if (actor.RelationshipGroup == 0) { NativeFunction.CallByName<uint>("REMOVE_PED_FROM_GROUP", ped.Handle.Value); NativeFunction.CallByName<uint>("SET_PED_AS_GROUP_MEMBER", ped.Handle.Value, NativeFunction.CallByName<int>("GET_PED_GROUP_INDEX", Game.LocalPlayer.Character.Handle.Value)); ped.RelationshipGroup = StaticData.RelationshipGroups.Groups[1]; } else { ped.RelationshipGroup = StaticData.RelationshipGroups.Groups[actor.RelationshipGroup]; } if (actor.SpawnInVehicle) { var vehList = ped.GetNearbyVehicles(15).OrderBy(v => (ped.Position - v.Position).Length()); ped.WarpIntoVehicle(vehList.ToList()[0], actor.VehicleSeat); } var hasActivated = false; if (actor.ActivateAfter == CurrentStage) { CurrentObjectives.Add(actor); hasActivated = true; } GameFiber.StartNew(delegate { if(!hasActivated) { while (CurrentStage != actor.ActivateAfter && IsMissionPlaying) { GameFiber.Yield(); } CurrentObjectives.Add(actor); } var blip = ped.AttachBlip(); blip.Scale = 0.6f; blip.Color = Color.DarkRed; ped.BlockPermanentEvents = false; if (actor.Behaviour == 3) ped.Tasks.FightAgainstClosestHatedTarget(100f); else if (actor.Behaviour == 2) NativeFunction.CallByName<uint>("TASK_GUARD_CURRENT_POSITION", ped.Handle.Value, 15f, 10f, true); else if(actor.Behaviour == 0) ped.Tasks.Clear(); else if (actor.Behaviour == 4) { GameFiber.StartNew(delegate { var wpyList = new List<SerializableWaypoint>(actor.Waypoints); SerializableWaypoint currentWaypoint; if(wpyList.Count > 0) currentWaypoint = wpyList[0]; while (ped.IsValid() && ped.Exists() && ped.IsAlive && IsMissionPlaying && wpyList.Count > 0) { if (wpyList.Count == 0) break; currentWaypoint = wpyList[0]; Task pedTask = null; switch (currentWaypoint.Type) { case WaypointTypes.Drive: if (ped.IsInAnyVehicle(true)) { pedTask = ped.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.VehicleSpeed, (DriveToPositionFlags)currentWaypoint.DrivingStyle); } break; case WaypointTypes.Run: { var heading = 0f; if (wpyList.Count >= 2) { heading = Util.DirectionToRotation(wpyList[1].Position - currentWaypoint.Position) .Z; } pedTask = ped.Tasks.FollowNavigationMeshToPosition(currentWaypoint.Position, heading, 2f, 0.3f, currentWaypoint.Duration == 0 ? -1 : (int)currentWaypoint.Duration); } break; case WaypointTypes.Walk: { var heading = 0f; if (wpyList.Count >= 2) { heading = Util.DirectionToRotation(wpyList[1].Position - currentWaypoint.Position) .Z; } pedTask = ped.Tasks.FollowNavigationMeshToPosition(currentWaypoint.Position, heading, 1f, 0.3f, currentWaypoint.Duration == 0 ? -1 : (int)currentWaypoint.Duration); } break; case WaypointTypes.ExitVehicle: if (ped.IsInAnyVehicle(true)) pedTask = ped.Tasks.LeaveVehicle(LeaveVehicleFlags.None); break; case WaypointTypes.EnterVehicle: Vehicle[] vehs = World.GetAllVehicles().Where(v => { if (v != null && v.IsValid()) return v.Model.Hash == currentWaypoint.VehicleTargetModel; return false; }).OrderBy(v => (v.Position - ped.Position).Length()).ToArray(); if (vehs.Any()) { if ((vehs[0].Position - ped.Position).Length() > 10f) { pedTask = ped.Tasks.FollowNavigationMeshToPosition(vehs[0].Position, 0f, 3f, 5f); pedTask.WaitForCompletion(10000); } var seat = vehs[0].GetFreeSeatIndex(); if (seat.HasValue) pedTask = ped.Tasks.EnterVehicle(vehs[0], seat.Value); } break; case WaypointTypes.Wait: pedTask = ped.Tasks.StandStill(currentWaypoint.Duration); break; case WaypointTypes.Wander: pedTask = ped.Tasks.Wander(); break; case WaypointTypes.Shoot: pedTask = null; NativeFunction.CallByName<uint>("TASK_SHOOT_AT_COORD", ped.Handle.Value, currentWaypoint.Position.X, currentWaypoint.Position.Y, currentWaypoint.Position.Z, currentWaypoint.Duration, 0xC6EE6B4C); GameFiber.Sleep(currentWaypoint.Duration); break; case WaypointTypes.Animation: pedTask = ped.Tasks.PlayAnimation(currentWaypoint.AnimDict, currentWaypoint.AnimName, 8f, AnimationFlags.None); break; } pedTask?.WaitForCompletion(currentWaypoint.Duration == 0 ? -1 : currentWaypoint.Duration); if(wpyList.Count > 0) wpyList.RemoveAt(0); GameFiber.Yield(); } }); } while (!ped.IsDead && IsMissionPlaying) { if (actor.ShowHealthBar) { TimerBars.UpdateValue(ped.Handle.Value.ToString(), actor.Name, true, (100f*ped.Health/actor.Health).ToString("###") + "%"); } GameFiber.Yield(); } if (actor.ShowHealthBar) { TimerBars.UpdateValue(ped.Handle.Value.ToString(), actor.Name, true, "0%"); } CurrentObjectives.Remove(actor); if(blip.IsValid()) blip.Delete(); while(IsMissionPlaying) GameFiber.Yield(); if (ped.IsValid()) ped.Delete(); }); } foreach (var pickup in CurrentMission.Objectives.OfType<SerializablePickupObjective>().Where(v => v.ActivateAfter == CurrentStage)) { CurrentObjectives.Add(pickup); GameFiber.StartNew(delegate { var obj = NativeFunction.CallByName<uint>("CREATE_PICKUP_ROTATE", pickup.PickupHash, pickup.Position.X, pickup.Position.Y, pickup.Position.Z, pickup.Rotation.Pitch, pickup.Rotation.Roll, pickup.Rotation.Yaw, 1, pickup.Ammo, 2, 1, 0); var blip = new Blip(pickup.Position); blip.Scale = 0.7f; blip.Color = Color.DodgerBlue; var counter = 0; while ((pickup.Position - Game.LocalPlayer.Character.Position).Length() > 1f && IsMissionPlaying) { var alpha = 40 * (Math.Sin(Util.DegToRad(counter % 180))); Util.DrawMarker(28, pickup.Position, new Vector3(), new Vector3(0.75f, 0.75f, 0.75f), Color.FromArgb((int)alpha, 230, 10, 10)); counter += 5; if (counter >= 360) counter = 0; GameFiber.Yield(); } if(blip != null && blip.IsValid()) blip.Delete(); NativeFunction.CallByName<uint>("REMOVE_PICKUP", obj); CurrentObjectives.Remove(pickup); }); } foreach (var mark in CurrentMission.Objectives.OfType<SerializableMarker>().Where(v => v.ActivateAfter == CurrentStage)) { CurrentObjectives.Add(mark); GameFiber.StartNew(delegate { var bColor = Color.FromArgb(mark.Alpha, (int) mark.Color.X, (int) mark.Color.Y, (int) mark.Color.Z); var blip = new Blip(mark.Position); blip.Color = bColor; blip.EnableRoute(bColor); while ((mark.Position - Game.LocalPlayer.Character.Position).Length() > 1.5f && IsMissionPlaying) { Util.DrawMarker(mark.Type, mark.Position, new Vector3(mark.Rotation.Pitch, mark.Rotation.Roll, mark.Rotation.Yaw), mark.Scale, bColor); GameFiber.Yield(); } if(blip.IsValid()) blip.Delete(); CurrentObjectives.Remove(mark); }); } if (CurrentMission.Cutscenes.Any(c => c.PlayAt == CurrentStage)) { var origPos = Game.LocalPlayer.Character.Position; var origRot = Game.LocalPlayer.Character.Rotation; Game.FadeScreenIn(100, true); Game.LocalPlayer.Character.Opacity = 0f; Game.LocalPlayer.Character.IsPositionFrozen = true; var cutscene = CurrentMission.Cutscenes.First(c => c.PlayAt == CurrentStage); var camLeft = new List<SerializableCamera>(cutscene.Cameras); var subLeft = new List<SerializableSubtitle>(cutscene.Subtitles); var startTime = Game.GameTime; Camera mainCam = null; SerializableCamera currentCam = null; uint lerpStart = 0; while ((Game.GameTime - startTime) < cutscene.Length) { var ct = (Game.GameTime - startTime); if (camLeft.Any()) { if (camLeft[0].PositionInTime <= ct) { if (mainCam == null || !mainCam.IsValid()) { Camera.DeleteAllCameras(); mainCam = new Camera(true); } Game.LocalPlayer.HasControl = false; mainCam.Position = cutscene.Cameras[0].Position; mainCam.Rotation = cutscene.Cameras[0].Rotation; currentCam = camLeft[0]; camLeft.RemoveAt(0); lerpStart = Game.GameTime; Game.LocalPlayer.Character.Position = mainCam.Position; } else if (currentCam != null) { // Advance cam pos if (currentCam.InterpolationStyle == InterpolationStyle.Linear) { mainCam.Position = Util.LerpVector(currentCam.Position, camLeft[0].Position, Util.LinearLerp, Game.GameTime - lerpStart, camLeft[0].PositionInTime - currentCam.PositionInTime); mainCam.Rotation = Util.LerpVector(currentCam.Rotation.ToVector(), camLeft[0].Rotation.ToVector(), Util.LinearLerp, Game.GameTime - lerpStart, camLeft[0].PositionInTime - currentCam.PositionInTime).ToRotator(); Game.LocalPlayer.Character.Position = mainCam.Position; } else if (currentCam.InterpolationStyle == InterpolationStyle.Smooth) { mainCam.Position = Util.LerpVector(currentCam.Position, camLeft[0].Position, Util.QuadraticLerp, Game.GameTime - lerpStart, camLeft[0].PositionInTime - currentCam.PositionInTime); mainCam.Rotation = Util.LerpVector(currentCam.Rotation.ToVector(), camLeft[0].Rotation.ToVector(), Util.QuadraticLerp, Game.GameTime - lerpStart, camLeft[0].PositionInTime - currentCam.PositionInTime).ToRotator(); Game.LocalPlayer.Character.Position = mainCam.Position; } } } else if(currentCam != null && mainCam != null) { mainCam.Position = currentCam.Position; mainCam.Rotation = currentCam.Rotation; Game.LocalPlayer.Character.Position = mainCam.Position; } if (subLeft.Any()) { if (subLeft[0].PositionInTime <= ct) { Game.DisplaySubtitle(subLeft[0].Content, subLeft[0].DurationInMs); subLeft.RemoveAt(0); } } GameFiber.Yield(); } mainCam.Active = false; Game.LocalPlayer.HasControl = true; Game.LocalPlayer.Character.IsPositionFrozen = false; Game.LocalPlayer.Character.Position = origPos; Game.LocalPlayer.Character.Rotation = origRot; Game.LocalPlayer.Character.Opacity = 1f; Game.FadeScreenOut(100); } if (!string.IsNullOrEmpty(CurrentMission.ObjectiveNames[CurrentStage])) { Game.DisplaySubtitle(CurrentMission.ObjectiveNames[CurrentStage], 10000); } Game.FadeScreenIn(1); }