public static void SetHookRopeUnwinding(HookPair hook, bool unwinding) { if (hook != null && hook.IsValid()) { if (!hook.isUnwinding && unwinding && hook.rope.Length < MaxRopeLength) { Function.Call(Hash.START_ROPE_UNWINDING_FRONT, hook.rope); hook.isUnwinding = true; } else if (hook.isUnwinding && !unwinding) { Function.Call(Hash.STOP_ROPE_UNWINDING_FRONT, hook.rope); hook.isUnwinding = false; } if (hook.isUnwinding && RopeWindingSpeed > 0.0f) { if (hook.rope.Length + RopeWindingSpeed < MaxRopeLength) { hook.rope.Length += RopeWindingSpeed * Game.LastFrameTime * 100.0f; } else { hook.rope.Length = MaxRopeLength; Function.Call(Hash.STOP_ROPE_UNWINDING_FRONT, hook.rope); hook.isUnwinding = false; } } } }
private static void CreateTransportHookFrontBackMode(HookPair transHook) { Vehicle playerVehicle = Util.GetVehiclePlayerIsIn(); Vector3 entityDimensions = transHook.entity2.Model.GetDimensions(); HookPair hook1 = new HookPair(transHook); HookPair hook2 = new HookPair(transHook); Vector3 playerHookOffset = playerVehicle.ForwardVector * 1.9f; hook1.hookOffset1 = -playerHookOffset; hook2.hookOffset1 = playerHookOffset; Vector3 hookOffsetFront = (-transHook.entity2.ForwardVector * (entityDimensions.X / 1.9f)) + (transHook.entity2.UpVector * (entityDimensions.Z * 0.6f)); Vector3 hookOffsetBack = (transHook.entity2.ForwardVector * (entityDimensions.X / 1.9f)) + (transHook.entity2.UpVector * (entityDimensions.Z * 0.6f)); hook1.hookOffset2 = hookOffsetFront; hook2.hookOffset2 = hookOffsetBack; float rope1Length = (hook1.entity1.Position + hook1.hookOffset1).DistanceTo(hook1.entity2.Position + hook1.hookOffset2); float rope2Length = (hook2.entity1.Position + hook1.hookOffset1).DistanceTo(hook2.entity2.Position + hook1.hookOffset2); float greatestRopeLength = Math.Max(rope1Length, rope2Length); RopeModule.CreateHook(hook1, false, MinTransportRopeLength, greatestRopeLength); RopeModule.CreateHook(hook2, false, MinTransportRopeLength, greatestRopeLength); }
public static void SetHookRopeWinding(HookPair hook, bool winding) { if (hook != null && hook.IsValid()) { if (!hook.isWinding && winding && hook.rope.Length > MinRopeLength) { Function.Call(Hash.START_ROPE_WINDING, hook.rope); hook.isWinding = true; //hook.isUnwinding = false; } else if (hook.isWinding && !winding) { Function.Call(Hash.STOP_ROPE_WINDING, hook.rope); hook.isWinding = false; } if (hook.isWinding && RopeWindingSpeed > 0.0f) { if (hook.rope.Length - RopeWindingSpeed > MinRopeLength) { hook.rope.Length -= RopeWindingSpeed * Game.LastFrameTime * 100.0f;// * Game.GameTime; } else { hook.rope.Length = MinRopeLength; Function.Call(Hash.STOP_ROPE_WINDING, hook.rope); hook.isWinding = false; } } } }
private static void CreateTransportHookCenterMode(HookPair transHook, bool copyHook = true) { float minRopeLength = (!Util.IsPed(transHook.entity2) ? MinTransportRopeLength : MinTransportPedRopeLength); Vector3 entityDimensions = transHook.entity2.Model.GetDimensions(); if (!Util.IsPed(transHook.entity2)) { transHook.hookOffset2 += transHook.entity2.UpVector * entityDimensions.Z * 0.5f; } RopeModule.CreateHook(transHook, copyHook, minRopeLength); }
private static void CreateTransportHookLeftRightMode(HookPair transHook) { Vehicle playerVehicle = Util.GetVehiclePlayerIsIn(); Vector3 entityDimensions = transHook.entity2.Model.GetDimensions(); HookPair hook1 = new HookPair(transHook); HookPair hook2 = new HookPair(transHook); Vector3 playerHookOffset = playerVehicle.RightVector * 1.2f; hook1.hookOffset1 = -playerHookOffset; hook2.hookOffset1 = playerHookOffset; Vector3 raySourceLeft = transHook.entity2.Position + (-transHook.entity2.RightVector * (entityDimensions.Y / 5.0f)); Vector3 raySourceRight = transHook.entity2.Position + (transHook.entity2.RightVector * (entityDimensions.Y / 5.0f)); RaycastResult rayLeft = World.Raycast(raySourceLeft, transHook.entity2.RightVector, 7.0f, IntersectOptions.Everything, playerVehicle); RaycastResult rayRight = World.Raycast(raySourceRight, -transHook.entity2.RightVector, 7.0f, IntersectOptions.Everything, playerVehicle); Vector3 heightOffset = (transHook.entity2.UpVector * entityDimensions.Z * 0.5f); if (rayLeft.DitHitEntity && rayLeft.HitEntity == transHook.entity2 && rayRight.DitHitEntity && rayRight.HitEntity == transHook.entity2) { hook1.hookOffset2 = rayLeft.HitCoords - transHook.entity2.Position + heightOffset; hook2.hookOffset2 = rayRight.HitCoords - transHook.entity2.Position + heightOffset; } else { if (DebugMode) { UI.Notify("Failed L/R Raycast Hook"); } hook1.hookOffset2 = (-transHook.entity2.RightVector * (entityDimensions.Y / 5.0f)) + heightOffset; hook2.hookOffset2 = (transHook.entity2.RightVector * (entityDimensions.Y / 5.0f)) + heightOffset; } float rope1Length = (hook1.entity1.Position + hook1.hookOffset1).DistanceTo(hook1.entity2.Position + hook1.hookOffset2); float rope2Length = (hook2.entity1.Position + hook1.hookOffset1).DistanceTo(hook2.entity2.Position + hook1.hookOffset2); float greatestRopeLength = Math.Max(rope1Length, rope2Length); RopeModule.CreateHook(hook1, false, MinTransportRopeLength, greatestRopeLength); RopeModule.CreateHook(hook2, false, MinTransportRopeLength, greatestRopeLength); }
public static void CreateHook(HookPair source, bool copyHook = true, float minRopeLength = MIN_MIN_ROPE_LENGTH, float customRopeLength = 0.0f) { if (!CheckHookPermission(source)) { return; } HookPair resultHook = CreateEntityHook(source, copyHook, HookPedsAtBonesCoords, minRopeLength, customRopeLength); if (resultHook != null) { Hooks.Add(resultHook); } }
public bool Equals(HookPair other) { if (other == null) { return(false); } return(this.isEntity2AMapPosition == other.isEntity2AMapPosition && this.isEntity1ABalloon == other.isEntity1ABalloon && this.isTransportHook == other.isTransportHook && this.entity1 == other.entity1 && this.entity2 == other.entity2 && Util.Truncate(this.hookPoint1) == Util.Truncate(other.hookPoint1) && Util.Truncate(this.hookPoint2) == Util.Truncate(other.hookPoint2) && Util.Truncate(this.hookOffset1) == Util.Truncate(other.hookOffset1) && Util.Truncate(this.hookOffset2) == Util.Truncate(other.hookOffset2)); }
public void CopyFrom(HookPair other) { this.rope = other.rope; this.entity1 = other.entity1; this.entity2 = other.entity2; this.ropeType = other.ropeType; this.isEntity2AMapPosition = other.isEntity2AMapPosition; this.isEntity1ABalloon = other.isEntity1ABalloon; this.isEntity2ABalloon = other.isEntity2ABalloon; this.isWinding = other.isWinding; this.isUnwinding = other.isUnwinding; this.hookPoint1 = other.hookPoint1; this.hookPoint2 = other.hookPoint2; this.ropeType = other.ropeType; this.hookOffset1 = other.hookOffset1; this.hookOffset2 = other.hookOffset2; this.isTransportHook = other.isTransportHook; }
public static Ped GetNPCPedInHook(HookPair hook) { if (hook == null) { return(null); } if (Util.IsNPCPed(hook.entity1)) { return((Ped)hook.entity1); } else if (Util.IsNPCPed(hook.entity2)) { return((Ped)hook.entity2); } else { return(null); } }
//public static void ToggleSolidRopesProc() //{ // SolidRopes = !SolidRopes; // SubQueue.AddSubtitle("VRope Solid Ropes: " + (SolidRopes ? "[ON]" : "(OFF)"), 24); //} //public static void IncrementMinRopeLength(bool negativeIncrement = false, bool halfIncrement = false) //{ // float lengthIncrement = (halfIncrement ? 0.5f : 1.0f); // if (!negativeIncrement && MIN_ROPE_LENGTH < MAX_MIN_ROPE_LENGTH) // { // MIN_ROPE_LENGTH += lengthIncrement; // } // else if (negativeIncrement && MIN_ROPE_LENGTH > (MIN_MIN_ROPE_LENGTH + lengthIncrement)) // { // MIN_ROPE_LENGTH -= lengthIncrement; // } // SubQueue.AddSubtitle(166, "VRope Minimum Rope Length: " + MIN_ROPE_LENGTH.ToString("0.00"), 17); //} public static void MultipleObjectSelectionProc() { if (Game.Player.Exists() && !Game.Player.IsDead && Game.Player.CanControlCharacter && Game.Player.IsAiming && SelectedHooks.Count < MAX_SELECTED_HOOKS) { RaycastResult rayResult = Util.CameraRaycastForward(); HookPair selectedHook = new HookPair(RopeHook); Entity targetEntity = null; if (Util.GetEntityPlayerIsAimingAt(ref targetEntity) && targetEntity != null) { selectedHook.entity1 = targetEntity; selectedHook.hookPoint1 = rayResult.HitCoords; selectedHook.hookOffset1 = (selectedHook.hookPoint1 != Vector3.Zero ? (selectedHook.hookPoint1 - selectedHook.entity1.Position) : Vector3.Zero); SelectedHooks.Add(selectedHook); } } }
public static bool CheckHookPermission(HookPair hook) { if (hook == null || hook.entity1 == null) { return(false); } if (Hooks.Count >= MAX_HOOK_COUNT) { return(false); } if (hook.entity2 == null && !hook.isEntity2AMapPosition) { return(false); } if (Util.IsPed(hook.entity1) && !Util.IsPlayer(hook.entity1)) { if (HookedPedCount >= MAX_HOOKED_PEDS || ((Ped)hook.entity1).IsDead || Util.IsPed(hook.entity2) || IsEntityHooked(hook.entity1)) { return(false); } } if (Util.IsPed(hook.entity2)) { if (HookedPedCount >= MAX_HOOKED_PEDS || ((Ped)hook.entity2).IsDead || IsEntityHooked(hook.entity2)) { return(false); } } return(true); }
public static void ApplyForce(HookPair hook, Vector3 entity1HookPosition, Vector3 entity2HookPosition) { if (hook == null || hook.entity1 == null) { return; } float scaleFactor = ForceScaleFactor; Vector3 distanceVector = entity2HookPosition - entity1HookPosition; Vector3 lookAtDirection = distanceVector.Normalized; if (Util.IsPed(hook.entity1) && !Util.IsPlayer(hook.entity1)) { scaleFactor *= 2.2f; if (!Util.IsPlayer(hook.entity1)) { Util.MakePedRagdoll((Ped)hook.entity1, PED_RAGDOLL_DURATION); } } hook.entity1.ApplyForce((lookAtDirection * ForceMagnitude * scaleFactor)); }
public static void RecreateEntityHook(int hookIndex, bool calcNewRopeLength = true) { if (hookIndex >= 0 && hookIndex < Hooks.Count) { if (DebugMode) { UI.Notify("Recreating Entity Hook i:" + hookIndex); } HookPair copyHook = new HookPair(Hooks[hookIndex]); float customRopeLength = (!calcNewRopeLength ? Hooks[hookIndex].rope.Length : 0.0f); DeleteHookByIndex(hookIndex, false); Hooks[hookIndex] = CreateEntityHook(copyHook, false, true, MinRopeLength, customRopeLength); Ped ped = GetNPCPedInHook(Hooks[hookIndex]); ped.Velocity = Vector3.Zero; } }
//public static void CreateLandVehicleTransportHooks(TransportHookType hookType) //{ // try // { // //if (HookFilter.DefaultFilters[CurrentTransportHookFilterIndex].filterValue.Contains("GTA.Ped")) // // hookType = TransportHookType.SINGLE; // List<Entity> transportEntities = GetTransportHookEntities(hookType); // Entity playerFlyingVehicle = Util.GetVehiclePlayerIsIn(); // for (int i = 0; i < transportEntities.Count; i++) // { // Entity entity = transportEntities[i]; // if (!CheckTransportHookPermission(entity)) // continue; // Entity hookEntity1 = (!Util.IsPed(entity) ? Game.Player.Character : playerFlyingVehicle); // HookPair transHook = new HookPair(); // TransportHookMode hookMode = TransportHookMode.CENTER; // transHook.isTransportHook = true; // transHook.ropeType = TransportHooksRopeType; // transHook.entity1 = hookEntity1; // transHook.entity2 = entity; // if (!Util.IsPed(entity) && hookType == TransportHookType.SINGLE) // { // hookMode = AllTransportHookModes[CurrentTransportHookModeIndex].first; // } // else if (hookType == TransportHookType.MULTIPLE) // { // transHook.hookOffset1 = Util.GetRandom2DPositionAround(Vector3.Zero, 0.31f); // } // switch (hookMode) // { // case TransportHookMode.CENTER: // CreateTransportHookCenterMode(transHook); break; // case TransportHookMode.LEFT_RIGHT: // CreateTransportHookLeftRightMode(transHook); break; // } // } // } // catch (Exception exc) // { // UI.Notify("VRope CreateAirVehicleTransportHooks() Error: " + GetErrorMessage(exc)); // } //} public static void CreateAirVehicleTransportHooks(TransportHookType hookType) { try { List <Entity> transportEntities = GetTransportHookEntities(hookType); Entity playerFlyingVehicle = Util.GetVehiclePlayerIsIn(); for (int i = 0; i < transportEntities.Count; i++) { Entity entity = transportEntities[i]; if (!CheckTransportHookPermission(entity)) { continue; } Entity hookEntity1 = (!Util.IsPed(entity) ? Game.Player.Character : playerFlyingVehicle); HookPair transHook = new HookPair(); TransportHookMode hookMode = TransportHookMode.CENTER; transHook.isTransportHook = true; transHook.ropeType = TransportHooksRopeType; transHook.entity1 = hookEntity1; transHook.entity2 = entity; //if (!Util.IsPed(entity) && hookType == TransportHookType.SINGLE) if (hookType == TransportHookType.SINGLE) { hookMode = AllTransportHookModes[CurrentTransportHookModeIndex].first; } else if (hookType == TransportHookType.MULTIPLE) { transHook.hookOffset1 = Util.GetRandom2DPositionAround(Vector3.Zero, 0.31f); } if (Util.IsPed(entity)) { hookMode = TransportHookMode.CENTER; } switch (hookMode) { case TransportHookMode.CENTER: CreateTransportHookCenterMode(transHook); break; case TransportHookMode.LEFT_RIGHT: CreateTransportHookLeftRightMode(transHook); break; case TransportHookMode.FRONT_BACK: CreateTransportHookFrontBackMode(transHook); break; //case TransportHookMode.CROSS: // CreateTransportHookCrossMode(transHook); break; } } } catch (Exception exc) { UI.Notify("VRope CreateAirVehicleTransportHooks() Error: " + GetErrorMessage(exc)); } }
//public static void DeleteHook(HookPair hook, bool removeFromHooks = true) //{ // if (hook != null) // { // hook.Delete(); // hook = null; // } // else // { // UI.Notify("DeleteHook(): Attempted to delete NULL hook."); // } // if (removeFromHooks) // Hooks.Remove(hook); //} public static HookPair CreateEntityHook(HookPair hook, bool copyHook = true, bool hookAtBonePositions = true, float minRopeLength = MIN_MIN_ROPE_LENGTH, float customRopeLength = 0.0f) { try { if (hook.entity1 == null || (hook.entity2 == null && !hook.isEntity2AMapPosition)) { return(null); } if (Hooks.Count >= MAX_HOOK_COUNT || (hook.HasNPCPed() && HookedPedCount >= MAX_HOOKED_PEDS)) { return(null); } Vector3 entity1HookPosition = hook.entity1.Position + hook.hookOffset1; Vector3 entity2HookPosition = Vector3.Zero; bool makePedsRagdoll = false; if (hook.isEntity2AMapPosition) { hook.entity2 = CreateTargetProp(hook.hookPoint2, false, true, ShowHookRopeProp, true, false); entity2HookPosition = hook.entity2.Position; } else { entity2HookPosition = hook.entity2.Position + hook.hookOffset2; } if (Util.IsPed(hook.entity1) && !Util.IsPlayer(hook.entity1)) { if (hookAtBonePositions) { entity1HookPosition = Util.GetNearestBonePosition((Ped)hook.entity1, entity1HookPosition); } if (makePedsRagdoll) { Util.MakePedRagdoll((Ped)hook.entity1, PED_RAGDOLL_DURATION); } } if (Util.IsPed(hook.entity2)) { if (hookAtBonePositions) { entity2HookPosition = Util.GetNearestBonePosition((Ped)hook.entity2, entity2HookPosition); } if (makePedsRagdoll) { Util.MakePedRagdoll((Ped)hook.entity2, PED_RAGDOLL_DURATION); } } float ropeLength = (customRopeLength > 0.0f ? customRopeLength : World.GetDistance(entity1HookPosition, entity2HookPosition)); //TRY1 if (ropeLength < minRopeLength) { ropeLength = minRopeLength; } hook.rope = World.AddRope(hook.ropeType, entity1HookPosition, Vector3.Zero, ropeLength, minRopeLength, false); //ORIGINAL hook.rope.ActivatePhysics(); hook.rope.AttachEntities(hook.entity1, entity1HookPosition, hook.entity2, entity2HookPosition, ropeLength); if (Util.IsVehicle(hook.entity1)) { hook.entity1.ApplyForce(new Vector3(0, 1, 0)); } if (Util.IsVehicle(hook.entity2)) { hook.entity2.ApplyForce(new Vector3(1, 0, 0)); } hook.isEntity1ABalloon = BalloonHookMode; if (hook.HasNPCPed()) { HookedPedCount++; } if (copyHook) { return(new HookPair(hook)); } else { return(hook); } } catch (Exception exc) { UI.Notify("VRope CreateEntityHook Error:\n" + GetErrorMessage(exc)); return(hook); } }
private static void CreateTransportHookCrossMode(HookPair transHook) { CreateTransportHookFrontBackMode(transHook); CreateTransportHookLeftRightMode(transHook); }
public HookPair(HookPair other) { CopyFrom(other); }