public static Task OnTick() { if (!ControlHelper.IsControlJustPressed(Control.CinematicSlowMo)) { return(Task.FromResult(0)); } if (Game.PlayerPed.IsInVehicle() && Game.PlayerPed.CurrentVehicle.Driver == Game.PlayerPed && !TrainManager.TrainLocomotiveModels.Contains(Game.PlayerPed.CurrentVehicle.Model)) { var vehicle = Game.PlayerPed.CurrentVehicle; var isLocked = Function.Call <bool>(Hash.DECOR_EXIST_ON, vehicle.Handle, "Vehicle.Locked") && Function.Call <bool>(Hash.DECOR_GET_BOOL, vehicle.Handle, "Vehicle.Locked"); if (isLocked) { SetVehicleLocks(vehicle, LockState.Unlocked); Log.ToChat("Vehicle unlocked!"); } else { SetVehicleLocks(vehicle, LockState.Locked); Log.ToChat("Vehicle locked!"); } } else { var vehicle = WorldProbe.GetVehicleInFrontOfPlayer(3f); if (vehicle == null) { var closeVehicles = new VehicleList().Select(v => new CitizenFX.Core.Vehicle(v)) .Where(v => v.Position.DistanceToSquared(Game.PlayerPed.Position) < Math.Pow(UnlockDistance, 2)) .OrderBy(v => v.Position.DistanceToSquared(Game.PlayerPed.Position)); if (closeVehicles.Any()) { vehicle = closeVehicles.First(); } } if (vehicle == null || TrainManager.TrainLocomotiveModels.Contains(vehicle.Model)) { return(Task.FromResult(0)); } var isLocked = Function.Call <bool>(Hash.DECOR_EXIST_ON, vehicle.Handle, "Vehicle.Locked") && Function.Call <bool>(Hash.DECOR_GET_BOOL, vehicle.Handle, "Vehicle.Locked"); if (isLocked) { SetVehicleLocks(vehicle, LockState.Unlocked); Log.ToChat("Vehicle unlocked!"); // TODO: Make all other players in the vehicle do this same thing to be extra-sure it unlocks properly Game.PlayerPed.Task.ClearAll(); } else { SetVehicleLocks(vehicle, LockState.Locked); Log.ToChat("Vehicle locked!"); } } return(Task.FromResult(0)); }
/// <summary> /// Get's a scan result from the building scan check. /// </summary> /// <param name="distance">The distance of the scan.</param> /// <param name="vSteep">The vertical steepness (up direction) of the scan.</param> /// <param name="f">The scan's angle from the player's forward direction.</param> /// <returns></returns> private ShapeTestResult GetScanResult(float distance, Vector3 vSteep, float f) { // The rotation of the angle relative to the player. var rotation = Quaternion.Euler(0, 0, f); // Get the camera direction. var cameraDirection = Profile.GetCameraDirection(); // Project the camera direction onto the world up vector. var cameraDirProject = Vector3.ProjectOnPlane(cameraDirection, Vector3.WorldUp); // The direction of the ray. var direction = rotation * cameraDirProject + vSteep; direction.Normalize(); // Draw a line to help us visualize this. //GameGraphics.DrawLine(PlayerCharacter.Position, PlayerCharacter.Position + direction * distance, Color.Red); // Start the ray. var ray = WorldProbe.StartShapeTestRay(Profile.LocalUser.Position, Profile.LocalUser.Position + direction * distance, ShapeTestFlags.IntersectMap, Profile.LocalUser); // Get the ray's result. var result = ray.GetResult(); return(result); }
private static void Move(/*Camera cam, */ Vector3 surfaceNormal, Entity attachmentObject, ref Vector3 camDirection, ref Vector3 moveDirection, Vector3 movement, bool lerp = true) { if (movement != Vector3.Zero) { var targetDir = /*attachmentObject.Position - */ /*cam*/ /*GameplayCamera.Position*/ GameplayCamera.Direction + Vector3.WorldUp * 0.5f; targetDir.Normalize(); var targetCamDir = Vector3.ProjectOnPlane(targetDir, surfaceNormal); targetCamDir.Normalize(); camDirection = targetCamDir; var targetMovementDir = Maths.LookRotation(camDirection, surfaceNormal) * movement; targetMovementDir.Normalize(); moveDirection = lerp ? Vector3.Lerp(moveDirection, targetMovementDir, Time.UnscaledDeltaTime * 5f) : targetMovementDir; var lookRotation = Maths.LookRotation(moveDirection, surfaceNormal); attachmentObject.Quaternion = lookRotation; var startCoords = attachmentObject.Position + surfaceNormal; var endCoords = startCoords + attachmentObject.ForwardVector * 0.5f; var ray = WorldProbe.StartShapeTestRay(startCoords, endCoords, ShapeTestFlags.IntersectMap, null); var res = ray.GetResult(); if (!res.Hit) { attachmentObject.PositionNoOffset = attachmentObject.Position + attachmentObject.ForwardVector * Time.DeltaTime * 5f * (Game.IsDisabledControlPressed(2, Control.Sprint) ? 2f : 1f); } } }
/// <summary> /// Shoot's a ray from the camera position in the /// direction of the camera, for the specified distance. /// </summary> /// <param name="distance">The shape test distance.</param> /// <param name="flags">The shapetest flags.</param> /// <param name="ignoreEntity">The entity to be ignored by the shapetest ray.</param> /// <returns></returns> public static ShapeTestResult GetCameraRay(float distance, ShapeTestFlags flags, Entity ignoreEntity = null) { var gameCamPos = GameplayCamera.Position; var dir = GameplayCamera.Direction * distance; var ray = WorldProbe.StartShapeTestRay(gameCamPos, gameCamPos + dir, flags, ignoreEntity); var result = ray.GetResult(); return(result); }
/// <summary> /// Shoot's a ray from the player position in the /// direction of the player, for the specified distance. /// </summary> /// <param name="distance">The shape test distance.</param> /// <param name="flags">The shapetest flags.</param> /// <param name="ignoreEntity">The entity to be ignored by the shapetest ray.</param> /// <returns></returns> public static ShapeTestResult GetPlayerRay(float distance, ShapeTestFlags flags, Entity ignoreEntity = null) { var player = Game.Player.Character; var gameCamPos = player.Position; var dir = player.ForwardVector * distance; var ray = WorldProbe.StartShapeTestRay(gameCamPos, gameCamPos + dir, flags, ignoreEntity); var result = ray.GetResult(); return(result); }
static public async Task Draw() { if (CinematicMode.DoHideHud) { return; } if (CitizenFX.Core.Game.PlayerPed.IsInVehicle()) { if (ControlHelper.IsControlJustPressed(Control.MpTextChatTeam, true, ControlModifier.Ctrl)) { locked = !locked; (menuItemLock as MenuItemCheckbox).state = locked; } System.Drawing.Color textColor = System.Drawing.Color.FromArgb(160, 255, 255, 255); CitizenFX.Core.Vehicle vehicle = WorldProbe.GetVehicleInFrontOfPlayer(60.0f); if (!ReferenceEquals(vehicle, null) && !locked) { textColor = System.Drawing.Color.FromArgb(255, 255, 255, 255); modelName = Game.GetGXTEntry(Function.Call <string>(Hash.GET_DISPLAY_NAME_FROM_VEHICLE_MODEL, vehicle.Model)); modelClassName = Game.GetGXTEntry(CitizenFX.Core.Vehicle.GetClassDisplayName((VehicleClass)Function.Call <int>(Hash.GET_VEHICLE_CLASS, vehicle.Handle))); vehiclePlate = Function.Call <string>(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, vehicle.Handle); vehicleColor = Enum.GetName(typeof(VehicleColor), vehicle.Mods.PrimaryColor).AddSpacesToCamelCase(); vehicleNumOccupants = Function.Call <int>(Hash.GET_VEHICLE_NUMBER_OF_PASSENGERS, vehicle.Handle) + (Function.Call <bool>(Hash.IS_VEHICLE_SEAT_FREE, vehicle.Handle, -1) ? 0 : 1); vehicleSpeed = vehicle.Speed; initialized = true; } if (initialized) { float x = 0.18f; float y = 0.79f; FamilyRP.Roleplay.Client.UI.DrawText($"Speed: {2.24 * vehicleSpeed:0.0} mph / {3.60 * vehicleSpeed:0.0} kph", new Vector2(x, y), textColor, 0.25f); y += 0.02f; FamilyRP.Roleplay.Client.UI.DrawText($"Model: {modelName} ({modelClassName})", new Vector2(x, y), textColor, 0.25f); y += 0.02f; FamilyRP.Roleplay.Client.UI.DrawText($"Color: {vehicleColor}", new Vector2(x, y), textColor, 0.25f); y += 0.02f; FamilyRP.Roleplay.Client.UI.DrawText($"Plate: {vehiclePlate}", new Vector2(x, y), textColor, 0.25f); y += 0.02f; FamilyRP.Roleplay.Client.UI.DrawText($"{unitsMap[vehicleNumOccupants].FirstLetterToUpper()} occupant{(vehicleNumOccupants != 1 ? "s" : "")}", new Vector2(x, y), textColor, 0.25f); y += 0.02f; if (locked) { FamilyRP.Roleplay.Client.UI.DrawText($"RADAR LOCK", new Vector2(x, y), Color.FromArgb(255, 180, 180, 0), 0.25f); } } else { float x = 0.18f; float y = 0.79f; FamilyRP.Roleplay.Client.UI.DrawText($"RADAR ACTIVE", new Vector2(x, y), textColor, 0.25f); } } await Task.FromResult(0); }
static internal async void CreateObject(ObjectHash objectHash) { var raycast = WorldProbe.CrosshairRaycast(); CurrentObject = await World.CreatePropNoOffset(new Model((int)objectHash), raycast.HitPosition, NormalVectorToRotation(raycast.SurfaceNormal), true); RaycastPickupOffset = raycast.HitPosition - CurrentObject.Position; ManipulationDistance = (float)Math.Sqrt(CitizenFX.Core.GameplayCamera.Position.DistanceToSquared(raycast.HitPosition)); NativeWrappers.SetPedCanSwitchWeapon(Game.PlayerPed, false); CurrentObject.Opacity = 180; }
private ShapeTestResult DoCameraRay(float distance) { // Do our raycast in front of us. var ray = WorldProbe.StartShapeTestRay(GameplayCamera.Position, GameplayCamera.Position + GameplayCamera.Direction * distance, ShapeTestFlags.Everything, Profile.LocalUser); // Get the ray's result. var result = ray.GetResult(); return(result); }
static private async void Lockpick(Command command) { try { var vehicle = WorldProbe.GetVehicleInFrontOfPlayer(3f); if (vehicle != null && vehicle != default(CitizenFX.Core.Vehicle)) { bool locked = Function.Call <bool>(Hash.DECOR_GET_BOOL, vehicle.Handle, "Vehicle.Locked") || vehicle.LockStatus == VehicleLockStatus.Locked || vehicle.LockStatus == VehicleLockStatus.LockedForPlayer; if (locked) { Log.Verbose("Attempting to lockpick vehicle..."); await BaseScript.Delay(3000); if (random.NextBool(30) || WorldProbe.GetVehicleInFrontOfPlayer() != vehicle) // Chance lockpicking is successful { BaseScript.TriggerEvent("Chat.Message", "[Lockpick]", "#ffffff", $@"Picked lock successfully!"); Function.Call(Hash.DECOR_SET_BOOL, vehicle.Handle, "Vehicle.Locked", false); Function.Call(Hash.SET_VEHICLE_DOORS_LOCKED_FOR_ALL_PLAYERS, vehicle.Handle, false); vehicle.LockStatus = VehicleLockStatus.Unlocked; } else { BaseScript.TriggerEvent("Chat.Message", "[Lockpick]", "#ffffff", $@"Lockpick failed!"); int i = 30; while (i > 0) { vehicle.SoundHorn(125); Function.Call(Hash.SET_VEHICLE_LIGHTS, vehicle.Handle, 2); await BaseScript.Delay(125); Function.Call(Hash.SET_VEHICLE_LIGHTS, vehicle.Handle, 1); await BaseScript.Delay(125); i--; } Function.Call(Hash.SET_VEHICLE_LIGHTS, vehicle.Handle, 0); } } else { Log.Verbose($"Unable to lockpick: Vehicle does not appear to be locked"); } } } catch (Exception ex) { Log.Error($"Lockpicking Lockpick Error: {ex.Message}"); } }
/// <summary> /// Finds a thing / point that the player is aimining at. /// Returns null if nothing was found. /// </summary> /// <param name="rayMaxDist">The max distance of the raycast.</param> /// <param name="endCoords">The end coordinates if any.</param> /// <param name="entityType">The entity type.</param> /// <returns></returns> public static Entity GetAimedEntity(float rayMaxDist, out Vector3 endCoords, out EntityType entityType) { // Get the gameplay camera direction, and position // and shoot a raycast out to get the position that was hit. var gameCameraPos = GameplayCamera.Position; var distToPlayer = Vector3.Distance(gameCameraPos, Game.Player.Character.Position) + 0.5f; var gameCameraDir = GameplayCamera.Direction; // This is the end point of the ray. var rayEndPos = gameCameraPos + gameCameraDir * rayMaxDist; // Shoot the ray and get it's result, ignoring the player. var ray = WorldProbe.StartShapeTestRay(gameCameraPos + gameCameraDir * distToPlayer, rayEndPos, ShapeTestFlags.Everything, Game.Player.Character); var result = ray.GetResult(); // get the result. // Make sure the result hit something we want before performing any // other operations. if (result.Hit) { // Return the hit point. endCoords = result.EndCoords; // Also return the entity type. entityType = result.EntityType; // Return the new vehicle. return(result.EntityHit); } // Make sure that the point is empty. endCoords = Vector3.Zero; // Make sure the entity type is none. entityType = EntityType.None; // Return null if nothing was found. return(null); }
static public Task OnTick() { int CurrentTime = Function.Call <int>(Hash.GET_GAME_TIMER); int TickTime = (CurrentTime - LastTickTime); LastTickTime = CurrentTime; if (CurrentObject != null) { if (!CurrentObject.Exists()) { Log.ToChat($"[OBJECTMANIP] Removing invalid object reference"); NativeWrappers.SetPedCanSwitchWeapon(Game.PlayerPed, true); CurrentObject = null; Task.Factory.StartNew(async() => { await BaseScript.Delay(2000); FamilyRP.Roleplay.Client.UI.disableEntityUI = false; }); return(Task.FromResult(0)); } else { var raycast = WorldProbe.CrosshairRaycast(CurrentObject); float RaycastDistance = raycast.HitPosition.DistanceToSquared(CitizenFX.Core.GameplayCamera.Position); // Uncomment if you want objects to snap to ground // Similar to GTAs own version but with different logic (different snapping) //CurrentObject.Position = raycast.HitPosition - RaycastPickupOffset; //CurrentObject.Rotation = NormalVectorToRotation(raycast.SurfaceNormal); // Replace Position with PositionNoOffset if you don't want objects to snap to surfaces CurrentObject.Position = CitizenFX.Core.GameplayCamera.Position + (float)ManipulationDistance * WorldProbe.GameplayCamForwardVector(); if (NoClip.DevToolsBindEnabled && ControlHelper.IsControlJustPressed(Control.PhoneCameraSelfie, true, Enums.Controls.ControlModifier.Ctrl)) { CurrentObject.Opacity = 255; Function.Call(Hash.SET_ENTITY_DYNAMIC, CurrentObject.Handle, true); CurrentObject = null; NativeWrappers.SetPedCanSwitchWeapon(Game.PlayerPed, true); Task.Factory.StartNew(async() => { await BaseScript.Delay(2000); FamilyRP.Roleplay.Client.UI.disableEntityUI = false; }); } else if (ControlHelper.IsControlPressed(Control.CursorCancel, true, Enums.Controls.ControlModifier.Shift)) { CurrentObject.Rotation = CurrentObject.Rotation + TickTime * GetRotationVector(RotationAxis); } else if (ControlHelper.IsControlPressed(Control.CursorCancel, true, Enums.Controls.ControlModifier.Ctrl)) { CurrentObject.Rotation = CurrentObject.Rotation - TickTime * GetRotationVector(RotationAxis); } else if (ControlHelper.IsControlJustPressed(Control.CursorCancel, true, Enums.Controls.ControlModifier.Alt)) { RotationAxis = (RotationAxis + 1) % 3; Log.ToChat($"Rotating along axis {RotationAxis}"); } else if (ControlHelper.IsControlJustPressed(Control.NextWeapon)) { ManipulationDistance -= TickTime * ZoomSpeed; Log.ToChat($"Manipulation distance: {ManipulationDistance:0.0}"); } else if (ControlHelper.IsControlJustPressed(Control.PrevWeapon)) { ManipulationDistance += TickTime * ZoomSpeed; Log.ToChat($"Manipulation distance: {ManipulationDistance:0.0}"); } } } else { if (NoClip.DevToolsBindEnabled && ControlHelper.IsControlJustPressed(Control.PhoneCameraSelfie, true, Enums.Controls.ControlModifier.Ctrl)) { var raycast = WorldProbe.CrosshairRaycast(); if (!raycast.DitHitEntity || !Function.Call <bool>(Hash.DOES_ENTITY_EXIST, raycast.HitEntity.Handle)) { return(Task.FromResult(0)); } CurrentObject = raycast.HitEntity; Log.ToChat($"Entity handle {CurrentObject.Handle}"); RaycastPickupOffset = raycast.HitPosition - CurrentObject.Position; ManipulationDistance = (float)Math.Sqrt(CitizenFX.Core.GameplayCamera.Position.DistanceToSquared(raycast.HitPosition)); NativeWrappers.SetPedCanSwitchWeapon(Game.PlayerPed, false); FamilyRP.Roleplay.Client.UI.disableEntityUI = true; CurrentObject.Opacity = 180; } } return(Task.FromResult(0)); }
private void UpdateClimbing(Vector3 surfacePosition, Vector3 surfaceNormal) { // Create the attachmentObject. var attachmentObject = World.CreateProp("w_pi_pistol", surfacePosition, false, false); attachmentObject.PositionNoOffset = surfacePosition; attachmentObject.HasCollision = false; attachmentObject.FreezePosition = true; attachmentObject.Quaternion = Maths.LookRotation(Vector3.WorldUp, surfaceNormal); attachmentObject.Alpha = 0; // attachmentObject.Alpha = 0; // Attach the player to the attachment object. Profile.LocalUser.Task.ClearAllImmediately(); Profile.LocalUser.AttachTo(attachmentObject, 0, new Vector3(0, 0, 1), Vector3.Zero); Profile.LocalUser.Task.PlayAnimation("move_crouch_proto", "idle_intro", 8.0f, -1, AnimationFlags.Loop); // Delay for the control. GameWaiter.Wait(10); // Create camera. var camDirection = Vector3.Zero; var moveDirection = Vector3.Zero; //var camSpawn = attachmentObject.GetOffsetInWorldCoords(new Vector3(0, -2, 1)); //var cam = World.CreateCamera(camSpawn, Vector3.Zero, 60); //cam.Direction = attachmentObject.Position - cam.Position; //cam.TransitionIn(100); //var pivot = World.CreateProp("w_pi_pistol", attachmentObject.Position, false, false); //pivot.FreezePosition = true; //pivot.IsVisible = false; //pivot.Quaternion = attachmentObject.Quaternion; //// Camera rotation. //var xRotation = 0f; //var yRotation = 45f; // flags. var cancelClimb = false; var idleTimer = 0f; while (!cancelClimb) { // Override the enabled controls. SetActiveControls(); GameplayCamera.ClampPitch(-90, 90); // Rotate the wall cam. //RotateCam(cam, pivot, attachmentObject, ref xRotation, ref yRotation); // Get the movement vector. var movement = GetMovementVector(); // Move the player attachment. Move(/*cam, */ surfaceNormal, attachmentObject, ref camDirection, ref moveDirection, movement); // Play the player movement animations. DoMovementAnimations(attachmentObject, movement.Length(), ref idleTimer); // Start a new surface ray. var surfaceRay = WorldProbe.StartShapeTestRay(attachmentObject.Position + attachmentObject.UpVector, attachmentObject.Position - attachmentObject.UpVector, ShapeTestFlags.IntersectMap, attachmentObject); // Handle the ejection keys. HandleEject(ref cancelClimb, attachmentObject); // Make sure the result is not empty. var result = surfaceRay.GetResult(); if (!result.Hit) { DetachPlayer(attachmentObject); GameWaiter.Wait(10); if (Game.IsDisabledControlPressed(2, Control.Sprint)) { Profile.LocalUser.HasCollision = false; Profile.LocalUser.IsCollisionProof = true; Profile.LocalUser.SetConfigFlag(60, false); Profile.LocalUser.Task.Skydive(); Profile.LocalUser.Task.PlayAnimation("swimming@swim", "recover_back_to_idle", 2.0f, -2.0f, 1150, AnimationFlags.AllowRotation, 0.0f); Profile.LocalUser.Velocity = Vector3.WorldUp * 25f; WebZip.OverrideFallHeight(float.MaxValue); var t = 0.1f; while (t > 0f) { t -= Game.LastFrameTime; Profile.LocalUser.HasCollision = false; Script.Yield(); } Profile.LocalUser.HasCollision = true; Profile.LocalUser.IsCollisionProof = false; } else { Profile.LocalUser.Task.Climb(); WebZip.OverrideFallHeight(0f); } break; } // Set the surface position. surfacePosition = result.EndCoords; // Check the surface normal. if (surfaceNormal != result.SurfaceNormal) { // If the surface normal has changed, then change immediately rotation the player // to match the normal. surfaceNormal = result.SurfaceNormal; Move(/*cam, */ surfaceNormal, attachmentObject, ref camDirection, ref moveDirection, movement, false); } attachmentObject.PositionNoOffset = surfacePosition; Script.Yield(); } // Destroy the camera. //Utilities.DestroyAllCameras(); // Delte the camera pivot. //pivot.Delete(); }
public static void Render() { if (CinematicMode.DoHideHud) { return; } float row = 0.027f; if (DevCommands.IsDevEntityUIEnabled && !disableEntityUI) { row += 0.04f; _RaycastResult raycast = WorldProbe.CrosshairRaycast(); if (!ReferenceEquals(raycast, null) && !ReferenceEquals(raycast.DitHit, null) && raycast.DitHit) { World.DrawLine(CitizenFX.Core.GameplayCamera.Position, raycast.HitPosition, System.Drawing.Color.FromArgb(255, 0, 0)); World.DrawLine(raycast.HitPosition, raycast.HitPosition + 1000 * raycast.SurfaceNormal, System.Drawing.Color.FromArgb(0, 255, 0)); DrawText($"Pos: {String.Join(" ", raycast.HitPosition.ToArray().Select(f => $"{f,6:0.000}"))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"Normal: {String.Join(" ", raycast.SurfaceNormal.ToArray().Select(f => $"{f,6:0.000}")).ToString()}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); } else { DrawText($"Hit: false", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); World.DrawLine(CitizenFX.Core.GameplayCamera.Position, CitizenFX.Core.GameplayCamera.Position + 1000 * WorldProbe.GameplayCamForwardVector(), System.Drawing.Color.FromArgb(255, 0, 0)); } row += 0.02f; if (!ReferenceEquals(raycast, null) && !ReferenceEquals(raycast.DitHitEntity, null) && !ReferenceEquals(raycast.HitEntity, null) && !ReferenceEquals(raycast.HitEntity.Handle, null) && raycast.DitHitEntity) { DrawText($"Ent ID: {raycast.HitEntity.Handle}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); string type = WorldProbe.GetEntityType(raycast.HitEntity.Handle); DrawText($"Type: {type}", 0, false, 0.84f, row, 0.25f, 255, 255, 255, 255); DrawText($"MISSION: {Function.Call<bool>(Hash.IS_ENTITY_A_MISSION_ENTITY, raycast.HitEntity.Handle)}", 0, false, 0.89f, row, 0.25f, 255, 255, 255, 255); DrawText($"isNet: {Function.Call<bool>(Hash.NETWORK_GET_ENTITY_IS_NETWORKED, raycast.HitEntity.Handle)}", 0, false, 0.95f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"hasNETID: {Function.Call<bool>(Hash.NETWORK_GET_NETWORK_ID_FROM_ENTITY, raycast.HitEntity.Handle)}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"NETID: {Function.Call<int>(Hash.NETWORK_GET_NETWORK_ID_FROM_ENTITY, raycast.HitEntity.Handle)}", 0, false, 0.84f, row, 0.25f, 255, 255, 255, 255); DrawText($"EntCtr: {Function.Call<bool>(Hash.NETWORK_HAS_CONTROL_OF_ENTITY, raycast.HitEntity.Handle)}", 0, false, 0.90f, row, 0.25f, 255, 255, 255, 255); DrawText($"isLoc: {Function.Call<bool>(Hash.NETWORK_GET_ENTITY_IS_LOCAL, raycast.HitEntity.Handle)}", 0, false, 0.95f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"NETID to ENTID: {Function.Call<int>(Hash.NETWORK_GET_ENTITY_FROM_NETWORK_ID, Function.Call<int>(Hash.NETWORK_GET_NETWORK_ID_FROM_ENTITY, raycast.HitEntity.Handle))} (Broken)", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"NETIDCtr: {Function.Call<bool>(Hash.NETWORK_HAS_CONTROL_OF_NETWORK_ID, Function.Call<int>(Hash.NETWORK_GET_NETWORK_ID_FROM_ENTITY, raycast.HitEntity.Handle))}", 0, false, 0.88f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; bool decorTestExists = Function.Call <bool>(Hash.DECOR_EXIST_ON, raycast.HitEntity.Handle, "TEST"); DrawText($"Decor TEST exists: {decorTestExists}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); if (decorTestExists) { DrawText($"TEST: {Function.Call<int>(Hash.DECOR_GET_INT, raycast.HitEntity.Handle, "TEST")}", 0, false, 0.90f, row, 0.25f, 255, 255, 255, 255); } row += 0.02f; Vector3 coords = Function.Call <Vector3>(Hash.GET_ENTITY_COORDS, raycast.HitEntity.Handle); DrawText($"x: {coords.X:0.000}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"y: {coords.Y:0.000}", 0, false, 0.85f, row, 0.25f, 255, 255, 255, 255); DrawText($"z: {coords.Z:0.000}", 0, false, 0.90f, row, 0.25f, 255, 255, 255, 255); DrawText($"h: {Function.Call<float>(Hash.GET_ENTITY_HEADING, raycast.HitEntity.Handle):0.000}", 0, false, 0.95f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; Vector3 rot = Function.Call <Vector3>(Hash.GET_ENTITY_ROTATION, raycast.HitEntity.Handle, 2); DrawText($"Rot x: {rot.X:0.000}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"y: {rot.Y:0.000}", 0, false, 0.85f, row, 0.25f, 255, 255, 255, 255); DrawText($"z: {rot.Z:0.000}", 0, false, 0.90f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; OutputArgument max = new OutputArgument(); OutputArgument min = new OutputArgument(); int modelHash = Function.Call <int>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle); Function.Call(Hash.GET_MODEL_DIMENSIONS, modelHash, max, min); Vector3 dim = max.GetResult <Vector3>() - min.GetResult <Vector3>(); DrawText($"x: {dim.X:0.000}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"y: {dim.Y:0.000}", 0, false, 0.85f, row, 0.25f, 255, 255, 255, 255); DrawText($"z: {dim.Z:0.000}", 0, false, 0.90f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"Model hash (int): {Function.Call<int>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle)}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"Model hash (uint): {Function.Call<uint>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle)}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"Model hash (hex): {Function.Call<uint>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle):X}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; if (type == "VEH") { // This commented version is not going to work for custom vehicles //DrawText($"Model name: {Enum.GetName(typeof(VehicleHash), Function.Call<uint>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); //row += 0.02f; //DrawText($"Class name: {Enum.GetName(typeof(VehicleClass), Function.Call<uint>(Hash.GET_VEHICLE_CLASS, raycast.HitEntity.Handle))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"Model name: {Game.GetGXTEntry(Function.Call<string>(Hash.GET_DISPLAY_NAME_FROM_VEHICLE_MODEL, raycast.HitEntity.Model))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"Class name: {Game.GetGXTEntry(CitizenFX.Core.Vehicle.GetClassDisplayName((VehicleClass)Function.Call<int>(Hash.GET_VEHICLE_CLASS, raycast.HitEntity.Handle)))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; DrawText($"Plate: {Function.Call<string>(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, raycast.HitEntity.Handle)}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); } else if (type == "PED") { DrawText($"Model name: {Enum.GetName(typeof(PedHash), Function.Call<uint>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); } else if (type == "OBJ") { DrawText($"Model name: {Enum.GetName(typeof(ObjectHash), Function.Call<int>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle))}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); } row += 0.02f; if (Function.Call <bool>(Hash.IS_ENTITY_A_VEHICLE, raycast.HitEntity.Handle)) { DrawText($"LOCKS: {Function.Call<int>(Hash.GET_VEHICLE_DOOR_LOCK_STATUS, raycast.HitEntity.Handle)}", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); DrawText($"LK4ME: {Function.Call<bool>(Hash.GET_VEHICLE_DOORS_LOCKED_FOR_PLAYER, raycast.HitEntity.Handle, CitizenFX.Core.Game.Player.Handle)}", 0, false, 0.85f, row, 0.25f, 255, 255, 255, 255); DrawText($"SPED: {Function.Call<float>(Hash._GET_VEHICLE_MODEL_MAX_SPEED, Function.Call<uint>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle)):0.00}", 0, false, 0.90f, row, 0.25f, 255, 255, 255, 255); DrawText($"ACCL: {Function.Call<float>(Hash.GET_VEHICLE_MODEL_ACCELERATION, Function.Call<uint>(Hash.GET_ENTITY_MODEL, raycast.HitEntity.Handle)):0.00}", 0, false, 0.95f, row, 0.25f, 255, 255, 255, 255); row += 0.02f; } } } else if (disableEntityUI) { DrawText($"Entity UI temporarily disabled while manipulating objects (native errors occur)", 0, false, 0.78f, row, 0.25f, 255, 255, 255, 255); } // TODO: Draw debug information for the developer when desired }
private void ProcessRopeAttachment() { while (Attached) { Controls.DisableControlsKeepRecording(2); Game.EnableControlThisFrame(2, Control.ReplayStartStopRecording); Game.EnableControlThisFrame(2, Control.LookLeftRight); Game.EnableControlThisFrame(2, Control.LookBehind); Game.EnableControlThisFrame(2, Control.LookUpDown); Game.EnableControlThisFrame(2, Control.MoveLeftRight); Game.EnableControlThisFrame(2, Control.MoveUpDown); Game.EnableControlThisFrame(2, Control.NextCamera); Game.EnableControlThisFrame(2, Control.Sprint); Game.EnableControlThisFrame(2, Control.FrontendPause); Game.EnableControlThisFrame(2, Control.FrontendPauseAlternate); UI.ShowHudComponentThisFrame(HudComponent.Reticle); // If the entity died then end to prevent crashing. if (_ropeAttachedEntity.IsDead) { EndAttachment(); break; } // Cancel the web. if (Game.IsDisabledControlJustPressed(2, Control.Aim)) { EndAttachment(); break; } var entityType = _ropeAttachedEntity.GetEntityType(); var isPed = entityType == EntityType.Ped; var isVeh = entityType == EntityType.Vehicle; var headingDirection = Profile.LocalUser.ForwardVector; var directionToEntity = _ropeAttachedEntity.Position - Profile.LocalUser.Position; directionToEntity.Normalize(); var distance = Vector3.Distance(Profile.LocalUser.Position, _ropeAttachedEntity.Position); var reverse = Vector3.Angle(headingDirection, directionToEntity) < 45; if (Game.IsDisabledControlJustPressed(2, Control.Attack)) { var flip = false; if (reverse) { headingDirection = -directionToEntity; if (distance < 25 && isVeh) { flip = true; } else { Profile.LocalUser.PlayGrappleAnim(-1f); } } else { Profile.LocalUser.PlayGrappleAnim(1f); } if (isPed) { var ped = new Ped(_ropeAttachedEntity.Handle); ped.Task.ClearAllImmediately(); ped.SetToRagdoll(500); ped.Velocity = headingDirection * distance; } _ropeAttachedEntity.Velocity = headingDirection * 25; EndAttachment(); if (flip) { FrontFlip(); } GameWaiter.Wait(150); break; } if (Game.IsDisabledControlJustPressed(2, Control.Enter) && isVeh) { var veh = new Vehicle(_ropeAttachedEntity.Handle); var driver = veh.Driver; if (Entity.Exists(driver)) { driver.Task.ClearAllImmediately(); driver.SetToRagdoll(500); driver.Velocity += veh.Velocity; veh.BreakDoor(VehicleDoor.FrontLeftDoor); if (reverse) { Profile.LocalUser.PlayGrappleAnim(-1f); } else { Profile.LocalUser.PlayGrappleAnim(1f); } EndAttachment(); break; } } if (Game.IsDisabledControlJustPressed(2, Control.Jump)) { Profile.LocalUser.Task.PlayAnimation("move_crouch_proto", "idle_intro", 8.0f, -8.0f, -1, AnimationFlags.Loop, 0.0f); Profile.LocalUser.Task.PlayAnimation("amb@code_human_wander_texting@male@base", "static", 8.0f, -8.0f, -1, AnimationFlags.UpperBodyOnly | AnimationFlags.Loop | AnimationFlags.AllowRotation, 0.0f); } if (Game.IsDisabledControlPressed(2, Control.Jump)) { var velocityDir = Profile.LocalUser.RightVector; _ropeAttachedEntity.ApplyForce(velocityDir); Profile.LocalUser.Heading = directionToEntity.ToHeading(); Profile.LocalUser.SetIKTarget(IKIndex.LeftArm, Profile.LocalUser.Position + directionToEntity, 0, 0); Profile.LocalUser.SetIKTarget(IKIndex.RightArm, Profile.LocalUser.Position + directionToEntity, 0, 0); Profile.LocalUser.SetIKTarget(IKIndex.Head, _ropeAttachedEntity.Position + Vector3.WorldUp * 5f, 0, 0); } if (Game.IsDisabledControlJustReleased(2, Control.Jump)) { Profile.LocalUser.Task.ClearAll(); EndAttachment(); break; } if (Game.IsDisabledControlJustPressed(2, Control.ParachuteSmoke)) { var ray = WorldProbe.StartShapeTestRay(GameplayCamera.Position, GameplayCamera.Position + GameplayCamera.Direction * 100f, ShapeTestFlags.Everything, Profile.LocalUser); var res = ray.GetResult(); if (res.Hit) { var entity = GetEntityFromRayResult(res); SetAttachedEntityToRagdollIfPed(); var rope = AttachRopeAttachedEntityToEntity(entity); AddAttachment(entity, _ropeAttachedEntity, rope); EndAttachment(); break; } } Script.Yield(); } }
public override void Process() { Game.DisableControlThisFrame(2, Control.ParachuteSmoke); var camRay = WorldProbe.StartShapeTestRay(GameplayCamera.Position, GameplayCamera.Position + GameplayCamera.Direction * 100f, ShapeTestFlags.IntersectPeds | ShapeTestFlags.IntersectVehicles, PlayerCharacter).GetResult(); if (camRay.Hit) { var bounds = camRay.EntityHit.Model.GetDimensions(); var z = bounds.Z / 2; World.DrawMarker(MarkerType.UpsideDownCone, camRay.EntityHit.Position + Vector3.WorldUp * z * 1.5f, Vector3.Zero, Vector3.Zero, new Vector3(0.3f, 0.3f, 0.3f), Color.White); if (Game.IsDisabledControlJustPressed(2, Control.ParachuteSmoke)) { var directionToEntity = camRay.EntityHit.Position - PlayerCharacter.Position; var distance = directionToEntity.Length(); directionToEntity.Normalize(); // Set the player's heading towards the target. PlayerCharacter.Heading = directionToEntity.ToHeading(); // Play the web shoot animation. PlayerCharacter.Task.PlayAnimation("guard_reactions", "1hand_aiming_to_idle", 8.0f, -8.0f, -1, (AnimationFlags)40, 0.0f); var playerBone = PlayerCharacter.GetBoneCoord(Bone.SKEL_R_Hand); var rope = Rope.AddRope(playerBone, distance, GTARopeType.ThickRope, 0.2f, 0.1f, true, false); var timer = 2.0f; var counter = 0; while (timer > 0) { PlayerCharacter.SetAnimationSpeed("guard_reactions", "1hand_aiming_to_idle", 0f); playerBone = PlayerCharacter.GetBoneCoord(Bone.SKEL_R_Hand); rope.PinVertex(0, playerBone); rope.PinVertex(rope.VertexCount - 1, camRay.EntityHit.Position); timer -= Time.DeltaTime; directionToEntity = camRay.EntityHit.Position - PlayerCharacter.Position; PlayerCharacter.Heading = directionToEntity.ToHeading(); if (counter % 10 == 0) { if (camRay.EntityType == EntityType.Ped) { var ped = new Ped(camRay.EntityHit.Handle); Utilities.ShockPed(ped, 15); } Utilities.CreateParticleChain(playerBone, camRay.EntityHit.Position, Vector3.Zero, nodeSize: 0.5f, noiseMultiplier: 0.0f); } counter++; Script.Yield(); } if (camRay.EntityType == EntityType.Vehicle) { var veh = new Vehicle(camRay.EntityHit.Handle); veh.Explode(); } PlayerCharacter.Task.ClearAll(); rope.Delete(); } } }
static private async Task OnTick() { try { CitizenFX.Core.Vehicle vehicle; if (ControlHelper.IsControlJustPressed(Control.Enter) && !Game.PlayerPed.IsInVehicle() && (vehicle = WorldProbe.GetVehicleInFrontOfPlayer()).Exists() && TrainLocomotiveModels.Contains((VehicleHash)vehicle.Model.Hash)) { train = (VehicleHash)vehicle.Model.Hash == VehicleHash.Freight ? new Train(Game.PlayerPed.CurrentVehicle) : new MetroTrain(Game.PlayerPed.CurrentVehicle); train.Enter(!train.TrainHandle.Driver.Exists()); return; } if (train != null) { if (!Game.PlayerPed.IsInVehicle() && !hasTrainJustSpawned || Game.PlayerPed.IsInVehicle() && !TrainLocomotiveModels.Contains(Game.PlayerPed.CurrentVehicle.Model)) { train = null; return; } train.UpdateTime(); if (train.IsMetroTrain) { ((MetroTrain)train).RefreshDoors(); } if (ControlHelper.IsControlJustPressed(Control.Enter)) { if (train.Exit()) { train = null; } } else if (train.IsPlayerDriver) { if (ControlHelper.IsControlPressed(Control.VehicleAccelerate)) { train.Accelerate(); } else if (ControlHelper.IsControlPressed(Control.VehicleBrake)) { train.Deccelerate(); } else if (ControlHelper.IsControlPressed(Control.Context, true, Enums.Controls.ControlModifier.Alt)) { await train.Derail(); } else if (ControlHelper.IsControlPressed(Control.VehicleHandbrake)) { train.Brake(); } else if (train.IsMetroTrain && ControlHelper.IsControlJustPressed(Control.CinematicSlowMo)) { ((MetroTrain)train).ToggleDoors(); } train.ApplyFriction(); } } } catch (Exception ex) { Log.Error($"Train OnTick Error: {ex.Message}"); } return; }
public override void Process() { if (Game.IsDisabledControlJustPressed(2, Control.Cover)) { var peds = World.GetNearbyPeds(PlayerCharacter.Position, 20f); if (peds.Length <= 0) { return; } var playerForward = Vector3.ProjectOnPlane(GameplayCamera.Direction, Vector3.WorldUp); var playerPosition = PlayerCharacter.Position; var pList = new List <Ped>(); for (var i = 0; i < peds.Length; i++) { var ped = peds[i]; if (ped.IsPlayer) { continue; } if (ped.IsInVehicle()) { continue; } if (ped.IsDead) { continue; } var dir = ped.Position - playerPosition; dir.Normalize(); var angle = Vector3.Angle(playerForward.Normalized, dir); if (angle < 90f) { var ray = WorldProbe.StartShapeTestRay(playerPosition, ped.Position, ShapeTestFlags.IntersectMap, PlayerCharacter); var result = ray.GetResult(); if (result.Hit) { continue; } if (ped.Weapons.Current == null) { continue; } if (ped.Weapons.Current.Hash == WeaponHash.Unarmed) { continue; } pList.Add(ped); } } if (pList.Count <= 0) { return; } var boneCoord = PlayerCharacter.GetBoneCoord(Bone.SKEL_R_Hand); var helperObj = World.CreateVehicle("bmx", boneCoord); helperObj.Alpha = 0; helperObj.AttachTo(PlayerCharacter, PlayerCharacter.GetBoneIndex(Bone.SKEL_R_Hand)); var center = Vector3.Zero; var rList = new List <Rope>(); foreach (var p in pList) { center += p.Position; var d = Vector3.Distance(helperObj.Position, p.Position); var r = Rope.AddRope(helperObj.Position, d, GTARopeType.ThickRope, d, 0.1f, true, false); r.AttachEntities(helperObj, Vector3.Zero, p, Vector3.Zero, d); r.ActivatePhysics(); rList.Add(r); } center /= pList.Count; PlayerCharacter.PlayAimAnim(center); GameWaiter.Wait(300); PlayerCharacter.PlayGrappleAnim(-1f); foreach (var r in rList) { r.Delete(); } foreach (var p in pList) { DisarmPed(p); } helperObj.Delete(); } }