public static void SetEngineRunning(VehicleHandle v, bool value) { if (v != 0) { Call(SET_VEHICLE_ENGINE_ON, v, value, true); } }
public override State OnTick() { if (CanControlCharacter()) { VehicleHandle target = Target(); if (target == VehicleHandle.Invalid) { return(Fail); } Vector3 targetPos = Position(target); if (targetPos == Vector3.Zero) { return(Fail); } Vector3 pos = Position(PlayerVehicle); if (pos == Vector3.Zero) { return(Fail); } float maxSpeed = Speed(target) * ((targetPos - pos).Length() / Distance); SteerToward(targetPos, maxSpeed: maxSpeed); } return(this); }
public static Dictionary <VehicleSeat, PedHandle> GetSeatMap(VehicleHandle veh) { var ret = new Dictionary <VehicleSeat, PedHandle>(); Enum.GetValues(typeof(VehicleSeat)).Each <VehicleSeat>(seat => { PedHandle ped = GetPedInSeat(veh, seat); ret[seat] = IsAlive(ped) ? ped : PedHandle.Invalid; }); return(ret); }
public static PedHandle CreatePedInsideVehicle(VehicleHandle veh, PedType type, ModelHash model, VehicleSeat seat) { switch (RequestModel(model)) { case AssetStatus.Invalid: return(PedHandle.ModelInvalid); case AssetStatus.Loading: return(PedHandle.ModelLoading); default: return(Call <PedHandle>(CREATE_PED_INSIDE_VEHICLE, veh, type, model, seat, true, true)); } }
public static bool TryGetVehicle(BlipHUDColor color, out VehicleHandle vehicle) { foreach (var p in NearbyVehicles()) { if (GetBlipHUDColor(GetBlip(p)) == color) { vehicle = p; return(true); } } vehicle = default; return(false); }
public override State OnTick() { if (Started == 0) { Started = GameTime; return(Series( new Teleport(NodeHandle.DesertAirfield), new Delay(1000), new ClearArea(), this )); } else { PedHandle cop = First(NearbyHumans().Where(p => GetModel(p) == PedHash.Cop01SFY)); if (cop == PedHandle.Invalid) { return(new SpawnPed(PedType.Cop, PedHash.Cop01SFY, this)); } VehicleHandle heli = First(NearbyVehicles().Where(v => GetModel(v) == VehicleHash.Buzzard)); if (heli == VehicleHandle.Invalid) { return(new SpawnVehicle(VehicleHash.Buzzard) { Location = (Location * .2f) + (PlayerPosition * .8f), Next = this }); } if (CurrentVehicle(cop) == VehicleHandle.Invalid) { AddStateOnce(cop, new EnterVehicle(heli)); return(new WaitForMessage("EnterVehicle", from: cop, next: this)); } else { AddStateOnce(cop, new HeliMission() { Heli = () => heli, TargetLocation = () => Location, LandingRadius = 10f, Heading = Heading(PlayerPosition - Location), Next = new LeaveVehicle(null) }); return(new WaitForMessage("LeaveVehicle", from: cop, next: this)); } } }
private bool UpdateTargets() { bool acted = false; if (TargetVehicle != null) { VehicleHandle newVehicle = TargetVehicle(); if (lastTargetVehicle == VehicleHandle.Invalid || lastTargetVehicle != newVehicle) { lastTargetVehicle = newVehicle; acted = true; } } if (TargetPed != null) { PedHandle newPed = TargetPed(); if (lastTargetPed == PedHandle.Invalid || lastTargetPed != newPed) { lastTargetPed = newPed; acted = true; } } if (TargetLocation != null) { Vector3 newLocation = TargetLocation(); if (lastTargetLocation == Vector3.Zero || lastTargetLocation != newLocation) { lastTargetLocation = newLocation; acted = true; } } if (Heli != null) { VehicleHandle newHeli = Heli(); if (lastHeli == VehicleHandle.Invalid || lastHeli != newHeli) { lastHeli = newHeli; acted = true; } } return(acted); }
public override State OnTick() { if (GamePaused) { return(this); } if (!CanControlCharacter()) { return(Next); } VehicleHandle ActorVehicle = CurrentVehicle(Actor); if (ActorVehicle == VehicleHandle.Invalid) { return(Next); } if (!IsTaskActive(Actor, TaskID.EnterVehicle)) { Call(TASK_LEAVE_VEHICLE, Actor, ActorVehicle, 0); } return(this); }
/// <summary> /// Return the position around this vehicle that provides the best cover from danger. /// </summary> public static Vector3 FindCoverBehindVehicle(VehicleHandle v, Vector3 danger, bool debug = false) { if (IsSeatFree(v, VehicleSeat.Driver) && Speed(v) == 0f) { Matrix4x4 m = Matrix(v); Vector3 pos = Global.Position(m); Vector3 delta = danger - pos; float heading = AbsHeading(Heading(m) - Rad2Deg(Math.Atan2(delta.Y, delta.X)) - 45); int slot = (int)(6 * (heading / 360f)); if (debug) { int line = 0; DrawLine(pos, danger, Color.Red); UI.DrawTextInWorldWithOffset(pos, 0f, (line++ *.02f), $"Heading: {heading:F2} Slot: {slot}"); } if (slot >= 0 && slot < vehicleCoverOffset.Length) { return(GetVehicleOffset(v, vehicleCoverOffset[slot], m)); } } return(Vector3.Zero); }
public static MoveResult FlyToward(Vector3 pos, float maxSpeed, float minHeight = 20f) { VehicleHandle heli = PlayerVehicle; if (heli != VehicleHandle.Invalid) { VehicleHash model = GetModel(heli); if (IsHeli(model)) { var ground = GetGroundZ(PlayerPosition); var elevation = PlayerPosition.Z - ground; if (elevation < minHeight) { SetControlValue(1, Control.VehicleFlyThrottleUp, 1f); return(MoveResult.Continue); } // TODO: check a capsule ray around our velocity Vector3 Vh = Velocity(heli); Matrix4x4 Mh = Matrix(heli); Vector3 Ph = Position(Mh); Vector3 Fh = Forward(Mh); // the heli's current movement heading float Hh = Heading(Vh); // Rad2Deg(Atan2(Vh.Y, Vh.X)); Vector3 Dv = pos - Ph; // the heading to the target float Hv = Heading(Dv); // Rad2Deg(Atan2(Dv.Y, Dv.X)); YawToward(Mh, Hv); float pitch = ((Speed(Self) / (maxSpeed * 3f)) - 1f) / 2f; SetControlValue(0, Control.VehicleFlyPitchUpDown, pitch); float throttle = -Vh.Z; SetControlValue(0, Control.VehicleFlyThrottleUp, throttle); return(MoveResult.Continue); } } return(MoveResult.Failed); }
public static void DebugVehicle() { VehicleHandle v = NearbyVehicles().FirstOrDefault(); if (Exists(v)) { Matrix4x4 m = Matrix(v); VehicleHash model = GetModel(v); GetModelDimensions(model, out Vector3 backLeft, out Vector3 frontRight); var sw = new Stopwatch(); sw.Start(); var blocked = new ConcurrentSet <NodeHandle>(); NavMesh.GetAllHandlesInBox(m, backLeft, frontRight, blocked); DrawBox(m, backLeft, frontRight); UI.DrawText($"GetAllHandlesInBox: {blocked.Count} in {sw.ElapsedTicks} ticks"); foreach (Vector3 n in blocked.Select(NavMesh.Position)) { if (random.NextDouble() < .2) { DrawSphere(n, .05f, Color.Red); } } } }
public static IEnumerable <ModelBox> GetBlockingVehicles(int limit = 20, bool debug = false) { VehicleHandle ignore = VehicleHandle.Invalid; if (IsOnVehicle(Self)) { RaycastResult result = Raycast(PlayerPosition, PlayerPosition - (2 * Up), .3f, IntersectOptions.Vehicles, Self); if (result.DidHit) { ignore = (VehicleHandle)result.Entity; } } foreach (VehicleHandle v in NearbyVehicles().Take(limit)) { if (v == PlayerVehicle || v == ignore) { continue; } if (!IsSeatFree(v, VehicleSeat.Driver)) { // cars with drivers need a different solution (avoidance not blocking) continue; } VehicleHash model = GetModel(v); GetModelDimensions(model, out Vector3 backLeft, out Vector3 frontRight); Matrix4x4 m = Matrix(v); if (debug) { DrawBox(m, backLeft, frontRight); } yield return(new ModelBox() { Model = (ModelHash)model, Entity = (EntHandle)v, M = m, Front = frontRight, Back = backLeft }); } }
public EnterVehicle(VehicleHandle veh, State next = null) : base(next) => Target = () => veh;
public FollowCar(VehicleHandle target) : this(() => target, () => false) { }
public static void Oil(VehicleHandle ent, float value) => Write(Address(ent), 0x7E8, value);
public static float Gravity(VehicleHandle ent) => Read <float>(Address(ent), 0xBCC);
public static float MaxOil(VehicleHandle ent) => Read <float>(Address(ent), 0x104);
public static void Turbo(VehicleHandle ent, float value) => Write(Address(ent), 0x888, value);
public static PedHandle CreatePedInsideVehicle(VehicleHandle veh, PedType type, PedHash model, VehicleSeat seat) => CreatePedInsideVehicle(veh, type, (ModelHash)model, seat);
public bool Contains(VehicleHandle ent) => Contains((ulong)ent);
public static void YawToward(VehicleHandle v, float heading) => YawToward(Matrix(v), heading);
/// <summary> /// Blacklist a Vehicle. /// </summary> public void Add(VehicleHandle veh, uint duration) => Add((ulong)veh, duration);
public void Remove(VehicleHandle handle) => data.Remove((ulong)handle);
public static float CurrentRPM(VehicleHandle ent) => Read <float>(Address(ent), 0x864);
public static void CurrentRPM(VehicleHandle ent, float value) => Write(Address(ent), 0x864, value);
public static uint WheelCount(VehicleHandle ent) => Read <uint>(Address(ent), 0xB18);
public static float Oil(VehicleHandle ent) => Read <float>(Address(ent), 0x7E8);
public static void Gravity(VehicleHandle ent, float value) => Write(Address(ent), 0xBCC, value);
public static bool TryCreateVehicle(VehicleHash model, Vector3 pos, float heading, out VehicleHandle vehicle) { if (!IsValid(model)) { vehicle = VehicleHandle.ModelInvalid; return(false); } if (!IsLoaded(model)) { vehicle = VehicleHandle.ModelLoading; RequestModel(model); return(false); } vehicle = Call <VehicleHandle>(CREATE_VEHICLE, model, pos.X, pos.Y, pos.Z, heading, true, true); UI.DrawHeadline($"CREATE_VEHICLE returned = {vehicle}"); return(true); }
public static float Turbo(VehicleHandle ent) => Read <float>(Address(ent), 0x888);