public static Vector3 GetNextPositionOnStreet(Vector3 position, bool unoccupied = false) { var outPos = new OutputArgument(); if (unoccupied) { for (int i = 1; i < 40; i++) { Function.Call(Hash.GET_NTH_CLOSEST_VEHICLE_NODE, position.X, position.Y, position.Z, i, outPos, 1, 0x40400000, 0); position = outPos.GetResult<Vector3>(); if (!Function.Call<bool>(Hash.IS_POINT_OBSCURED_BY_A_MISSION_ENTITY, position.X, position.Y, position.Z, 5.0f, 5.0f, 5.0f, 0)) { return position; } } } else if (Function.Call<bool>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE, position.X, position.Y, position.Z, 1, outPos, 1, 0x40400000, 0)) { return outPos.GetResult<Vector3>(); } return Vector3.Zero; }
public IEnumerator <int> GetEnumerator() { OutputArgument OutArgEntity = new OutputArgument(); int handle = Function.Call <int>((CitizenFX.Core.Native.Hash)((uint)CitizenFX.Core.Game.GenerateHash("FIND_FIRST_OBJECT")), OutArgEntity); yield return(OutArgEntity.GetResult <int>()); while (Function.Call <bool>((CitizenFX.Core.Native.Hash)((uint)CitizenFX.Core.Game.GenerateHash("FIND_NEXT_OBJECT")), handle, OutArgEntity)) { yield return(OutArgEntity.GetResult <int>()); } Function.Call((CitizenFX.Core.Native.Hash)((uint)CitizenFX.Core.Game.GenerateHash("END_FIND_OBJECT")), handle); }
public IEnumerator <int> GetEnumerator() { try { OutputArgument OutArgEntity = new OutputArgument(); currentHandle = Function.Call <int>((CitizenFX.Core.Native.Hash)((uint)CitizenFX.Core.Game.GenerateHash("FIND_FIRST_VEHICLE")), OutArgEntity); yield return(OutArgEntity.GetResult <int>()); while (Function.Call <bool>((CitizenFX.Core.Native.Hash)((uint)CitizenFX.Core.Game.GenerateHash("FIND_NEXT_VEHICLE")), currentHandle, OutArgEntity)) { yield return(OutArgEntity.GetResult <int>()); } } finally { } Function.Call((CitizenFX.Core.Native.Hash)((uint)CitizenFX.Core.Game.GenerateHash("END_FIND_VEHICLE")), currentHandle); }
public static Vector3 GetNextPositionOnSidewalk(Vector3 position) { var outPos = new OutputArgument(); if (Function.Call<bool>(Hash.GET_SAFE_COORD_FOR_PED, position.X, position.Y, position.Z, true, outPos, 0)) { return outPos.GetResult<Vector3>(); } else if (Function.Call<bool>(Hash.GET_SAFE_COORD_FOR_PED, position.X, position.Y, position.Z, false, outPos, 0)) { return outPos.GetResult<Vector3>(); } return Vector3.Zero; }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// An enumerator that can be used to iterate through the collection. /// </returns> public IEnumerator <Vehicle> GetEnumerator() { OutputArgument output = new OutputArgument(); int handle = Function.Call <int>((Hash)(uint)Game.GenerateHash("FIND_FIRST_VEHICLE"), output); yield return(new Vehicle(output.GetResult <int>())); while (Function.Call <bool>((Hash)(uint)Game.GenerateHash("FIND_NEXT_VEHICLE"), handle, output)) { yield return(new Vehicle(output.GetResult <int>())); } Function.Call((Hash)(uint)Game.GenerateHash("END_FIND_VEHICLE"), handle); }
void SetWeaponNoReload() { if (PlayerExists() && weaponNoReload) { var playerPed = Game.Player.Character.Handle; var o = new OutputArgument(); if (Function.Call <bool>(Hash.GET_CURRENT_PED_WEAPON, playerPed, o, 1)) { var cur = o.GetResult <uint>(); if (Function.Call <bool>(Hash.IS_WEAPON_VALID, cur)) { o = new OutputArgument(); if (Function.Call <bool>(Hash.GET_MAX_AMMO, playerPed, cur, o)) { int maxAmmo = o.GetResult <int>(); Function.Call(Hash.SET_PED_AMMO, playerPed, cur, maxAmmo); maxAmmo = Function.Call <int>(Hash.GET_MAX_AMMO_IN_CLIP, playerPed, cur, 1); if (maxAmmo > 0) { Function.Call(Hash.SET_AMMO_IN_CLIP, playerPed, cur, maxAmmo); } } } } } }
/// Bad results public static (int resultStatus, bool didHit, Vector3 hitPosition, Vector3 surfaceNormal) GetShapeTestResult(int rayHandle) { var didHitOutputArgument = new OutputArgument(); var endPositionOutputArgument = new OutputArgument(); var surfaceNormalOutputArgument = new OutputArgument(); var entityHitOutputArgument = new OutputArgument(); var resultStatus = Function.Call <int>( Hash.GET_SHAPE_TEST_RESULT, rayHandle, didHitOutputArgument, endPositionOutputArgument, surfaceNormalOutputArgument, entityHitOutputArgument ); var didHit = didHitOutputArgument.GetResult <bool>(); if (didHit) { return( resultStatus, true, endPositionOutputArgument.GetResult <Vector3>(), surfaceNormalOutputArgument.GetResult <Vector3>() ); } return( resultStatus, false, new Vector3(), new Vector3() ); }
private static string GetIntersectingStreetName(Vector3 position) { var areaHash = new OutputArgument(); Function.Call(Hash.GET_STREET_NAME_AT_COORD, position.X, position.Y, position.Z, new OutputArgument(), areaHash); return(API.GetStreetNameFromHashKey(areaHash.GetResult <uint>())); }
/// <summary> /// Get's the shape test result of this ray. /// </summary> /// <returns></returns> public ShapeTestResult GetResult() { if (Handle == 0) { return(default(ShapeTestResult)); } ShapeTestResult ss; var hit = new OutputArgument(); var endCoords = new OutputArgument(); var surfaceNormal = new OutputArgument(); var entityHit = new OutputArgument(); var handle = Function.Call <int>(Hash._0x3D87450E15D98694, Handle, hit, endCoords, surfaceNormal, entityHit); var entity = entityHit.GetResult <Entity>(); var entityType = entity?.GetEntityType() ?? EntityType.None; ss = new ShapeTestResult(handle, hit.GetResult <bool>(), endCoords.GetResult <Vector3>(), surfaceNormal.GetResult <Vector3>(), entity, entityType); return(ss); }
private static bool ParkPersonalVehicleNearby(bool inProgress) { Logger.Log("ParkPersonalVehicleNearby()"); if (inProgress) { Vector3 playerPos = Game.Player.Character.Position; Vector3 streetNode = World.GetNextPositionOnStreet(Game.Player.Character.Position); Vector3 sidewalkNode = World.GetNextPositionOnSidewalk(Game.Player.Character.Position); OutputArgument outArgA = new OutputArgument(); OutputArgument outArgB = new OutputArgument(); if (Function.Call <bool>(Hash.GET_CLOSEST_VEHICLE_NODE_WITH_HEADING, sidewalkNode.X, sidewalkNode.Y, sidewalkNode.Z, outArgA, outArgB, 1, 3, 0)) { Vector3 pos = outArgA.GetResult <Vector3>(); float heading = outArgB.GetResult <float>(); Function.Call(Hash.TASK_VEHICLE_PARK, 0, _personalVehicle, sidewalkNode.X, sidewalkNode.Y, sidewalkNode.Z, heading, 0, 30.0f, true); return(true); } else { Logger.Log("GET_CLOSEST_VEHICLE_NODE_WITH_HEADING failed, can't park!"); _personalDriver.Delete(); _personalDriver = null; _personalVehicle.PreviouslyOwnedByPlayer = true; return(false); } } else { _personalDriver.Delete(); _personalDriver = null; Logger.Log("UpdateHandler(): Finished parking, deleting driver."); return(false); } }
public static void GetGroundZfor3DCoord(Vector3 coord, out Vector3 result) { OutputArgument zcoord = new OutputArgument(); Function.Call <bool>(Hash.GET_GROUND_Z_FOR_3D_COORD, coord.X, coord.Y, coord.Z, zcoord); result = new Vector3(coord.X, coord.Y, zcoord.GetResult <float>()); }
/// <summary> /// Because HitPosition and SurfaceNormal are currently broken in platform function /// </summary> /// <returns></returns> public static _RaycastResult CrosshairRaycast(Entity ignore, float distance = 1000f) { try { // Uncomment these to potentially save on raycasts (don't think they're ridiculously costly, but there's a # limit per tick) //if(CrosshairRaycastThisTick != null && distance == 1000f) return (_RaycastResult) CrosshairRaycastThisTick; Vector3 start = CitizenFX.Core.GameplayCamera.Position; Vector3 end = CitizenFX.Core.GameplayCamera.Position + distance * GameplayCamForwardVector(); int raycastHandle = Function.Call <int>(Hash._START_SHAPE_TEST_RAY, start.X, start.Y, start.Z, end.X, end.Y, end.Z, IntersectOptions.Everything, ignore.Handle, 0); OutputArgument DitHit = new OutputArgument(); OutputArgument HitPosition = new OutputArgument(); OutputArgument SurfaceNormal = new OutputArgument(); OutputArgument HitEntity = new OutputArgument(); Function.Call <int>(Hash.GET_SHAPE_TEST_RESULT, raycastHandle, DitHit, HitPosition, SurfaceNormal, HitEntity); var result = new _RaycastResult(DitHit.GetResult <bool>(), HitPosition.GetResult <Vector3>(), SurfaceNormal.GetResult <Vector3>(), HitEntity.GetResult <int>(), raycastHandle); //if(distance == 1000f) CrosshairRaycastThisTick = result; return(result); } catch (Exception ex) { Log.Error(ex); } return(default(_RaycastResult)); }
/// <summary> /// Checks if the cursor is at the specified location. /// </summary> /// <param name="x">The absolute X position.</param> /// <param name="y">The absolute Y position.</param> /// <param name="width">The absolute Width from X.</param> /// <param name="height">The absolute Height from Y.</param> /// <returns>True if the mouse is in the specified location, False otherwise.</returns> public static bool IsCursorInBounds(float x, float y, float width, float height) { // Get the location where the cursor is #if FIVEM float cursorX = API.GetControlNormal(0, (int)Control.CursorX); float cursorY = API.GetControlNormal(0, (int)Control.CursorY); #else float cursorX = Function.Call <float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorX); float cursorY = Function.Call <float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorY); #endif // Convert the values received to relative ToRelative(x, y, out float startX, out float startY); ToRelative(width, height, out float realWidth, out float realHeight); // And get the correct positions of them float realX = 0, realY = 0; #if FIVEM API.GetScriptGfxPosition(startX, startY, ref realX, ref realY); #else OutputArgument argX = new OutputArgument(); OutputArgument argY = new OutputArgument(); Function.Call((Hash)0x6DD8F5AA635EB4B2, startX, startY, argX, argY); realX = argX.GetResult <float>(); realY = argY.GetResult <float>(); #endif // Check if the values are in the correct positions bool isX = cursorX >= realX && cursorX <= realX + realWidth; bool isY = cursorY > realY && cursorY < realY + realHeight; // And return the result of the checks return(isX && isY); }
/// <summary> /// Converts the specified position into one that is aware of <see cref="SetElementAlignment(GFXAlignment, GFXAlignment)"/>. /// </summary> /// <param name="x">The 1080p based X position.</param> /// <param name="y">The 1080p based Y position.</param> /// <returns>A new 1080p based position that is aware of the the Alignment.</returns> public static PointF GetRealPosition(float x, float y) { // Convert the resolution to relative ToRelative(x, y, out float relativeX, out float relativeY); // Request the real location of the position float realX = 0, realY = 0; #if FIVEM API.GetScriptGfxPosition(relativeX, relativeY, ref realX, ref realY); #elif RPH using (NativePointer argX = new NativePointer()) using (NativePointer argY = new NativePointer()) { NativeFunction.CallByHash <int>(0x6DD8F5AA635EB4B2, relativeX, relativeY, argX, argY); realX = argX.GetValue <float>(); realY = argY.GetValue <float>(); } #elif (SHVDN2 || SHVDN3) OutputArgument argX = new OutputArgument(); OutputArgument argY = new OutputArgument(); Function.Call((Hash)0x6DD8F5AA635EB4B2, relativeX, relativeY, argX, argY); // _GET_SCRIPT_GFX_POSITION realX = argX.GetResult <float>(); realY = argY.GetResult <float>(); #endif // And return it converted to absolute ToAbsolute(realX, realY, out float absoluteX, out float absoluteY); return(new PointF(absoluteX, absoluteY)); }
public IEnumerator <T> GetEnumerator() { var foundEntity = new OutputArgument(); int handle = Function.Call <int>(FindFirst, foundEntity); if (handle == -1) { yield break; } int entityHandle; var hasMore = true; while (hasMore) { entityHandle = foundEntity.GetResult <int>(); if (entityHandle == -1) { continue; } if (CastSilently(entityHandle, out T entity)) { yield return(entity); } hasMore = Function.Call <bool>(FindNext, handle, foundEntity); } Function.Call(EndFind, handle); }
public static RelationshipGroup AddRelationshipGroup(string name) { var resultArg = new OutputArgument(); Function.Call(Hash.ADD_RELATIONSHIP_GROUP, name, resultArg); return new RelationshipGroup(resultArg.GetResult<int>()); }
public static int GetVehicleNodeTrafficDensity(Vector3 pos) { OutputArgument densityOut = new OutputArgument(); Function.Call(Hash.GET_VEHICLE_NODE_PROPERTIES, pos.X, pos.Y, pos.Z, densityOut, null); return(densityOut.GetResult <int>()); }
//[SecurityCritical] static public string GetCrossingName(Vector3 position) { OutputArgument crossingHash = new OutputArgument(); Function.Call(Hash.GET_STREET_NAME_AT_COORD, position.X, position.Y, position.Z, new OutputArgument(), crossingHash); return(Function.Call <string>(Hash.GET_STREET_NAME_FROM_HASH_KEY, crossingHash.GetResult <int>())); }
public static float GetWaterHeight(Vector3 position) { var resultArg = new OutputArgument(); Function.Call(Hash.GET_WATER_HEIGHT, position.X, position.Y, position.Z, resultArg); return(resultArg.GetResult <float>()); }
public static Vector2 WorldToScreen(Vector3 pos) { var x2dp = new OutputArgument(); var y2dp = new OutputArgument(); Function.Call <bool>(Hash._WORLD3D_TO_SCREEN2D, pos.X, pos.Y, pos.Z, x2dp, y2dp); return(new Vector2(x2dp.GetResult <float>(), y2dp.GetResult <float>())); }
public static Vector2 World3DToScreen2D(Vector3 pos) { var x2dp = new OutputArgument(); var y2dp = new OutputArgument(); Function.Call <bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD, pos.X, pos.Y, pos.Z, x2dp, y2dp); return(new Vector2(x2dp.GetResult <float>(), y2dp.GetResult <float>())); }
public static Vector3 GetClosestSafeCoords(Vector3 pos, bool onGround) { OutputArgument resultPos = new OutputArgument(); Function.Call(Hash.GET_SAFE_COORD_FOR_PED, pos.X, pos.Y, pos.Z, onGround, resultPos, 0); return(resultPos.GetResult <Vector3>()); }
public static float GetGroundZ(Vector3 pos, out bool groundFound) //thanks Jitnaught! { OutputArgument outArg = new OutputArgument(); groundFound = Function.Call <bool>(Hash.GET_GROUND_Z_FOR_3D_COORD, pos.X, pos.Y, pos.Z, outArg, false); return(outArg.GetResult <float>()); }
private static string GetCrossingName(Vector3 position) { OutputArgument crossingHash = new OutputArgument(); Function.Call(Hash.GET_STREET_NAME_AT_COORD, position.X, position.Y, position.Z, new OutputArgument(), crossingHash); return(API.GetStreetNameFromHashKey(crossingHash.GetResult <uint>())); }
public static Vector2 Convert3dTo2d(Vector3 pos) { OutputArgument resX = new OutputArgument(); OutputArgument resY = new OutputArgument(); Function.Call <bool>(Hash._GET_SCREEN_COORD_FROM_WORLD_COORD, pos.X, pos.Y, pos.Z, resX, resY); return(new Vector2(resX.GetResult <float>(), resY.GetResult <float>())); }
/// <summary> /// Gets the height of the ground at a given position. /// </summary> /// <param name="position">The position.</param> /// <returns>The height measured in meters</returns> public static float GetGroundHeight(Vector2 position) { var resultArg = new OutputArgument(); Function.Call(Hash.GET_GROUND_Z_FOR_3D_COORD, position.X, position.Y, 1000f, resultArg); return resultArg.GetResult<float>(); }
public static Vector3 GetLastWeaponImpact(Ped ped) { var coord = new OutputArgument(); if (!Function.Call<bool>(Hash.GET_PED_LAST_WEAPON_IMPACT_COORD, ped.Handle, coord)) { return new Vector3(); } return coord.GetResult<Vector3>(); }
public static string GetStreetName(Vector3 position) { var streetHash = new OutputArgument(); var crossingHash = new OutputArgument(); Function.Call(Hash.GET_STREET_NAME_AT_COORD, position.X, position.Y, position.Z, streetHash, crossingHash); return Function.Call<string>(Hash.GET_STREET_NAME_FROM_HASH_KEY, streetHash.GetResult<int>()); }
RelationshipGroup(string name) : this() { var hashArg = new OutputArgument(); Function.Call(Native.Hash.ADD_RELATIONSHIP_GROUP, name, hashArg); Hash = hashArg.GetResult <int>(); }
public static void DrawBriefing(CustomMission currentMission) { UI.ShowSubtitle("Choose an entry point.", 10); if (currentMission.EntryPoints.Length - 1 < SelectedEntry) { SelectedEntry = 0; } Function.Call(Hash._SHOW_CURSOR_THIS_FRAME); DisEnableControls(false, true); currentMission.DrawBriefingMap(); Game.Player.Character.Position = currentMission.CameraPosition + new Vector3(0, 0, 10f); Function.Call(Hash.FREEZE_ENTITY_POSITION, Game.Player.Character.Handle, true); if (_mainCamera == null || (_mainCamera.Position != currentMission.CameraPosition)) { World.DestroyAllCameras(); _mainCamera = World.CreateCamera(currentMission.CameraPosition, new Vector3(0, 0, 0), 60f); } _mainCamera.PointAt(currentMission.CameraPosition - new Vector3(0, 0, 30f)); World.RenderingCamera = _mainCamera; SizeF res = UIMenu.GetScreenResolutionMantainRatio(); for (int i = 0; i < currentMission.EntryPoints.Length; i++) { Vector3 entryPoint = currentMission.EntryPoints[i]; var xPointer = new OutputArgument(); var yPointer = new OutputArgument(); bool successful = Function.Call <bool>(Hash._WORLD3D_TO_SCREEN2D, entryPoint.X, entryPoint.Y, entryPoint.Z, xPointer, yPointer); var x = xPointer.GetResult <float>() * res.Width; var y = yPointer.GetResult <float>() * res.Height; if (!successful) { x = 64f; y = res.Height - 64f - 64 * i; } bool hovering = UIMenu.IsMouseInBounds(new Point(Convert.ToInt32(x) - 32, Convert.ToInt32(y) - 32), new Size(64, 64)); new Sprite("trafficcam", SelectedEntry == i ? "traffic_junction_box" : "cursor", new Point(Convert.ToInt32(x) - 32, Convert.ToInt32(y) - 32), new Size(64, 64), 0f, SelectedEntry == i ? Color.DarkGreen : Color.DarkRed) .Draw(); if (Game.IsControlPressed(0, GTA.Control.Attack) && hovering) { SelectedEntry = i; } new UIResText(currentMission.EntryNames[i], new Point(Convert.ToInt32(x) + 32, Convert.ToInt32(y) - 32), 1f, Color.White, Font.Monospace, UIResText.Alignment.Left).Draw(); } new UIResText(currentMission.MissionName, new Point(Convert.ToInt32(res.Width), 20), 3f, Color.White, GTA.Font.Pricedown, UIResText.Alignment.Right).Draw(); DrawScaleform(); Function.Call(Hash.FREEZE_ENTITY_POSITION, Game.Player.Character.Handle, false); }
private void UpdateMarkers() { // Update the peds if is time to do so if (nextMarkerUpdate <= Game.GameTime) { peds = World.GetAllPeds(); nextMarkerUpdate = Game.GameTime + 1000; } // Iterate over the peds in the list foreach (Ped ped in peds) { // If the ped is alive or no longer exists and is on the list, remove it if ((ped.IsAlive || !ped.Exists()) && markers.ContainsKey(ped)) { markers.Remove(ped); } // If the ped is dead and is not part of the markers, add it else if (ped.IsDead && !markers.ContainsKey(ped)) { markers.Add(ped, new ScaledTexture(PointF.Empty, new SizeF(220 * 0.75f, 124 * 0.75f), "ggo", "marker_dead")); } } // Iterate over the existing items foreach (KeyValuePair <Ped, ScaledTexture> marker in markers) { Ped ped = marker.Key; // If the ped is not on the screen, skip it if (!ped.IsOnScreen) { continue; } // Get the position of the ped head Vector3 headPos = ped.Bones[Bone.SkelHead].Position; // And then conver it to screen coordinates OutputArgument originalX = new OutputArgument(); OutputArgument originalY = new OutputArgument(); bool ok = Function.Call <bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD, headPos.X, headPos.Y, headPos.Z, originalX, originalY); // If it was unable to get the position, continue if (!ok) { continue; } // Otherwise, convert the position from relative to absolute PointF screenPos = new PointF(originalX.GetResult <float>(), originalY.GetResult <float>()).ToAbsolute(); // And set it for the correct marker.Value.Position = new PointF(screenPos.X - (marker.Value.Size.Width * 0.5f), screenPos.Y - marker.Value.Size.Height); // Finally, draw it marker.Value.Draw(); } }
void AddCash(int amount) { string statNameFull = string.Format("SP{0}_TOTAL_CASH", (Game.Player.Character.Model.Hash == new Model("player_zero").Hash) ? 0 : //Michael (Game.Player.Character.Model.Hash == new Model("player_one").Hash) ? 1 : //Franklin (Game.Player.Character.Model.Hash == new Model("player_two").Hash) ? 2 : 0); //Trevor var hash = Function.Call<int>(Hash.GET_HASH_KEY, statNameFull); OutputArgument outArg = new OutputArgument(); Function.Call<bool>(Hash.STAT_GET_INT, hash, outArg, -1); var val = outArg.GetResult<int>() + amount; Function.Call(Hash.STAT_SET_INT, hash, val, true); }
public static Quaternion GetEntityQuaternion(Entity e) { var xg = new OutputArgument(); var yg = new OutputArgument(); var zg = new OutputArgument(); var wg = new OutputArgument(); Function.Call(Hash.GET_ENTITY_QUATERNION, e.Handle, xg, yg, zg, wg); return new Quaternion() { X = xg.GetResult<float>(), Y = yg.GetResult<float>(), Z = zg.GetResult<float>(), W = wg.GetResult<float>() }; }
/// <summary> /// Setup fighter for the AI player. /// </summary> public void Setup() { var vehModel = new Model(VehicleHash.Blimp); OutputArgument outVec = new OutputArgument(), outFlt = new OutputArgument(); var pos = TeamManager.CenterMap; Function.Call(Hash.GET_RANDOM_VEHICLE_NODE, pos.X, pos.Y, pos.Z, 1200f, 1, 1, 1, outVec, outFlt); var spawnPos = Scripts.GetValidSpawnPos(outVec.GetResult<Vector3>() + new Vector3(0, 0, 400f)); if (!vehModel.IsLoaded) vehModel.Request(1000); var vehicle = new ManageableVehicle(World.CreateVehicle(vehModel, spawnPos)); vehicle.LodDistance = 2000; vehicle.Heading = outFlt.GetResult<float>(); vehicle.Vehicle.EngineRunning = true; Function.Call(Hash.SET_VEHICLE_EXPLODES_ON_HIGH_EXPLOSION_DAMAGE, vehicle.Handle, true); vehicle.Vehicle.BodyHealth = 1000; vehicle.MaxHealth = 1000; vehicle.MaxSpeed = 0; var blip = vehicle.AddBlip(); blip.Sprite = BlipSprite.Blimp; blip.Scale = 0.8f; blip.Alpha = 220; var cl = TeamManager.GetColorFromTeamIndex(Team.Index); Function.Call(Hash.SET_BLIP_SECONDARY_COLOUR, blip.Handle, cl.R, cl.G, cl.B); Function.Call((Hash)0xB81656BC81FE24D1, blip.Handle, 1); ManagedVehicle = vehicle; }
Vector3 GetSafeRoadPos(Vector3 originalPos) { OutputArgument outArg = new OutputArgument(); Function.Call<int>(Hash.GET_CLOSEST_VEHICLE_NODE, originalPos.X, originalPos.Y, originalPos.Z, outArg, 1, 1077936128, 0); Vector3 output = outArg.GetResult<Vector3>(); return output; }
private void OnTick(object sender, EventArgs e) { fireController.Update(); var player = Game.Player.Character; if (!player.IsInVehicle() && Function.Call<int>(Hash.GET_WEAPONTYPE_GROUP, (int)player.Weapons.Current.Hash) != new Model("group_melee").Hash && player.Weapons.Current.Hash != WeaponHash.Unarmed) { if (player.Weapons.Current != currentWeapon) { fireTrail1.Remove(); fireTrail1A.Remove(); var outArg = new OutputArgument(); var outArg1 = new OutputArgument(); Function.Call(Hash.GET_MODEL_DIMENSIONS, (int)player.Weapons.Current.Hash, outArg, outArg1); dimensionsA = outArg1.GetResult<Vector3>(); dimensionsB = outArg1.GetResult<Vector3>(); currentWeapon = player.Weapons.Current; Wait(255); } else { var pWeapon = Function.Call<Entity>((Hash)0x3B390A939AF0B5FC, player); var wCoord = new Vector3(((dimensionsA.X - dimensionsB.X) / 2.0f) + 0.7f, (dimensionsA.Y - dimensionsB.Y) / 2.0f, 0.0f); if (!fireTrail1.Exists) { if (!fireTrail1.IsLoaded) { fireTrail1.Load(); fireTrail1A.Load(); } var bone = (Bone)Function.Call<int>(Hash._GET_ENTITY_BONE_INDEX, pWeapon, "Gun_Nuzzle"); fireTrail1.Start(pWeapon, 0.0f, wCoord + new Vector3(0.0f, 0.0f, 0.04f), new Vector3(89.5f, 0f, 0f), bone); fireTrail1A.Start(pWeapon, 0.0f, wCoord + new Vector3(0.0f, 0.0f, 0.04f), new Vector3(89.5f, 0f, 0f), bone); } else { if (Function.Call<bool>(Hash.IS_PLAYER_FREE_AIMING, Game.Player) && scriptEnabled) { if (!soundEmitter.Active) soundEmitter.Play(pWeapon); if (scaleFactor < 1.6f) { scaleFactor += 0.0525f; fireTrail1.Scale = scaleFactor; fireTrail1A.Scale = scaleFactor; } if (vecFactor < 3.8) { vecFactor += 0.3f; fireTrail1.SetOffsets(wCoord + new Vector3(vecFactor, 0.0f, 0.04f), new Vector3(89.5f, 0f, 0f)); fireTrail1A.SetOffsets(wCoord + new Vector3(vecFactor, 0.0f, 0.04f), new Vector3(89.5f, 0f, 0f)); } var castPos = pWeapon.GetOffsetInWorldCoords(wCoord + new Vector3(0.0f, 0.0f, 0.04f)); var wCast = World.Raycast(GameplayCamera.Position, GameplayCamera.Position + Utils.RotationToDirection(GameplayCamera.Rotation)/*castPos + Utils.RotationToDirection(pWeapon.Rotation + new Vector3(0, 90f, -90f))*/ * 18f, IntersectOptions.Everything); if (wCast.DitHitEntity && wCast.HitEntity != player) { fireController.AddTimedEntityFire(wCast.HitEntity, 15000); } else if (wCast.DitHitAnything && wCast.Result == 2) { fireController.AddTimedScriptFire(wCast.HitCoords, 15000); } } else { if (scaleFactor > 0.0f) { scaleFactor -= 0.015f; fireTrail1.Scale = scaleFactor; fireTrail1A.Scale = scaleFactor; } if (vecFactor > 0.0f) { vecFactor -= 0.0350f; fireTrail1.SetOffsets(wCoord + new Vector3(vecFactor, 0.0f, 0.04f), new Vector3(89.5f, 0f, 0f)); fireTrail1A.SetOffsets(wCoord + new Vector3(vecFactor, 0.0f, 0.04f), new Vector3(89.5f, 0f, 0f)); } } } } } else { if (fireTrail1.Exists) fireTrail1.Remove(); if (fireTrail1A.Exists) fireTrail1A.Remove(); } }
private void CheckNpcs() { foreach(var npc in NpcDatas) { var dist = npc.Position.DistanceTo(Game.Player.Character.Position); var npcStatus = npc.GetNpcStatus(); var npcBlip = WorldData.Blips.FirstOrDefault(b => b.Name == "Blip_" + npc.Name); if(npcBlip != null) { var blipPos = npcBlip.Blip.Position; if(string.IsNullOrEmpty(npcStatus)) { if (npcBlip.Blip.Sprite != npc.BlipSprite) { npcBlip.Blip.Remove(); npcBlip.Blip = World.CreateBlip(blipPos); npcBlip.Blip.Sprite = npc.BlipSprite; } } else { var importantMarker = npcStatus[0]; switch(importantMarker) { case '!': if (npcBlip.Blip.Sprite != BlipSprite.Information) { npcBlip.Blip.Remove(); npcBlip.Blip = World.CreateBlip(blipPos); npcBlip.Blip.Sprite = BlipSprite.Information; } break; case '?': if (npcBlip.Blip.Sprite != BlipSprite.GTAOMission) { npcBlip.Blip.Remove(); npcBlip.Blip = World.CreateBlip(blipPos); npcBlip.Blip.Sprite = BlipSprite.GTAOMission; } break; case '*': if (npcBlip.Blip.Sprite != BlipSprite.ChatBubble) { npcBlip.Blip.Remove(); npcBlip.Blip = World.CreateBlip(blipPos); npcBlip.Blip.Sprite = BlipSprite.ChatBubble; } break; case '$': if (npcBlip.Blip.Sprite != BlipSprite.Store) { npcBlip.Blip.Remove(); npcBlip.Blip = World.CreateBlip(blipPos); npcBlip.Blip.Sprite = BlipSprite.Store; } break; } } } if (RPGSettings.ShowUI && RPG.UIHandler.CurrentDialog == null) { if (npc.IsQuestNpc && dist < 20) { var pos = npc.Ped != null ? npc.Ped.Position : npc.Position; pos.Z += 1.0f; OutputArgument xArg = new OutputArgument(); OutputArgument yArg = new OutputArgument(); Function.Call(Hash._WORLD3D_TO_SCREEN2D, pos.X, pos.Y, pos.Z, xArg, yArg); var x = xArg.GetResult<float>(); var y = yArg.GetResult<float>(); new UIRectangle(new Point((int) (UI.WIDTH*x) - 50, (int) (UI.HEIGHT*y) + 12), new Size(100, 2), Color.DodgerBlue).Draw(); new UIText(npc.Name, new Point((int) (UI.WIDTH*x), (int) (UI.HEIGHT*y)), 0.21f, Color.White, 0, true).Draw(); if(!string.IsNullOrEmpty(npcStatus)) new UIText(npcStatus, new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y) - 35), 0.8f, Color.Gold, 0, true).Draw(); } } if(npc.IsQuestNpc && !npc.Spawned) { //RPGLog.Log("Found unspawned NPC"); if (dist < 100) { RPGLog.Log("Spawning NPC"); var model = new Model(npc.ModelName); model.Request(1000); var ped = World.CreatePed(model, npc.Position, npc.Heading); try { ped.RelationshipGroup = Game.Player.Character.RelationshipGroup; ped.IsInvincible = true; EventHandler.Do(o => { EventHandler.Wait(1000); ped.FreezePosition = true; }); Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, ped.Handle); Function.Call(Hash.SET_PED_CAN_BE_TARGETTED, ped.Handle, false); Function.Call(Hash.SET_PED_CAN_BE_TARGETTED_BY_PLAYER, ped.Handle, false); } catch { RPGLog.Log("Error setting npc and player friendliness."); } npc.SetPed(ped); npc.Spawned = true; } } } }
public static void DrawBriefing(CustomMission currentMission) { UI.ShowSubtitle("Choose an entry point.", 10); if (currentMission.EntryPoints.Length - 1 < SelectedEntry) SelectedEntry = 0; Function.Call(Hash._SHOW_CURSOR_THIS_FRAME); DisEnableControls(false, true); currentMission.DrawBriefingMap(); Game.Player.Character.Position = currentMission.CameraPosition + new Vector3(0, 0, 10f); Function.Call(Hash.FREEZE_ENTITY_POSITION, Game.Player.Character.Handle, true); if (_mainCamera == null || (_mainCamera.Position != currentMission.CameraPosition)) { World.DestroyAllCameras(); _mainCamera = World.CreateCamera(currentMission.CameraPosition, new Vector3(0, 0, 0), 60f); } _mainCamera.PointAt(currentMission.CameraPosition - new Vector3(0,0, 30f)); World.RenderingCamera = _mainCamera; SizeF res = UIMenu.GetScreenResolutionMantainRatio(); for (int i = 0; i < currentMission.EntryPoints.Length; i++) { Vector3 entryPoint = currentMission.EntryPoints[i]; var xPointer = new OutputArgument(); var yPointer = new OutputArgument(); bool successful = Function.Call<bool>(Hash._WORLD3D_TO_SCREEN2D, entryPoint.X, entryPoint.Y, entryPoint.Z, xPointer, yPointer); var x = xPointer.GetResult<float>()*res.Width; var y = yPointer.GetResult<float>()*res.Height; if (!successful) { x = 64f; y = res.Height - 64f - 64*i; } bool hovering = UIMenu.IsMouseInBounds(new Point(Convert.ToInt32(x) - 32, Convert.ToInt32(y) - 32), new Size(64, 64)); new Sprite("trafficcam", SelectedEntry == i ? "traffic_junction_box" : "cursor", new Point(Convert.ToInt32(x) - 32, Convert.ToInt32(y) - 32), new Size(64, 64), 0f, SelectedEntry == i ? Color.DarkGreen : Color.DarkRed) .Draw(); if (Game.IsControlPressed(0, GTA.Control.Attack) && hovering) SelectedEntry = i; new UIResText(currentMission.EntryNames[i], new Point(Convert.ToInt32(x) + 32, Convert.ToInt32(y) - 32), 1f, Color.White, Font.Monospace, UIResText.Alignment.Left).Draw(); } new UIResText(currentMission.MissionName, new Point(Convert.ToInt32(res.Width), 20), 3f, Color.White, GTA.Font.Pricedown, UIResText.Alignment.Right).Draw(); DrawScaleform(); Function.Call(Hash.FREEZE_ENTITY_POSITION, Game.Player.Character.Handle, false); }
private void CheckNpcs() { foreach(var npc in NpcDatas) { var dist = npc.Position.DistanceTo(Game.Player.Character.Position); if (dist < 20) { var pos = npc.Ped != null ? npc.Ped.Position : npc.Position; pos.Z += 1.0f; OutputArgument xArg = new OutputArgument(); OutputArgument yArg = new OutputArgument(); Function.Call(Hash._WORLD3D_TO_SCREEN2D, pos.X, pos.Y, pos.Z, xArg, yArg); var x = xArg.GetResult<float>(); var y = yArg.GetResult<float>(); new UIRectangle(new Point((int)(UI.WIDTH * x) - 50, (int)(UI.HEIGHT * y) + 12), new Size(100, 2), Color.DodgerBlue).Draw(); new UIText(npc.Name, new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y)), 0.21f, Color.White, 0, true).Draw(); } if(npc.IsQuestNpc && !npc.Spawned) { //RPGLog.Log("Found unspawned NPC"); if (dist < 100) { //RPGLog.Log("Spawning NPC"); var model = new Model(npc.ModelName); model.Request(1000); var ped = World.CreatePed(model, npc.Position, npc.Heading); try { ped.RelationshipGroup = Game.Player.Character.RelationshipGroup; ped.IsInvincible = true; Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, ped.Handle); Function.Call(Hash.SET_PED_CAN_BE_TARGETTED, ped.Handle, false); Function.Call(Hash.SET_PED_CAN_BE_TARGETTED_BY_PLAYER, ped.Handle, false); } catch { RPGLog.Log("Error setting npc and player friendliness."); } npc.SetPed(ped); npc.Spawned = true; } } } }
public override void Update() { WorldData = RPG.WorldData; Ped player = Game.Player.Character; if(RPG.ExplosiveHits) { Function.Call(Hash.SET_EXPLOSIVE_AMMO_THIS_FRAME,Game.Player.Handle); Function.Call(Hash.SET_EXPLOSIVE_MELEE_THIS_FRAME,Game.Player.Handle); } if(RPG.SuperJump) { Function.Call(Hash.SET_SUPER_JUMP_THIS_FRAME, Game.Player.Handle); } if(!CreatedNpcBlips) { foreach (var npc in NpcDatas) { var blip = World.CreateBlip(npc.Position); blip.Sprite = npc.BlipSprite; WorldData.Blips.Add(new BlipObject("Blip_" + npc.Name, blip)); } CreatedNpcBlips = true; } if(!PlayerData.Tutorial.BoughtAmmoFromShop && PlayerData.Tutorial.PressJToOpenMenu) { var tut = RPG.GetPopup<TutorialBox>(); var ammo = PlayerData.Inventory.FirstOrDefault(i => i.Name == "Ammo Pack I"); if(ammo != null) { PlayerData.Tutorial.BoughtAmmoFromShop = true; EventHandler.Do(o => { tut.Hide(); Wait(300); if(!RPG.PlayerData.Tutorial.GetAKill) { tut.Pop("Getting kills, completing missions are just two ways to earn XP and Skill Points", "Get a kill."); } }); } } CheckNpcs(); foreach(var l in RPG.WorldData.Loot) { if(l.Prop != null && l.Prop.Exists() && l.Item != null) { if(RPG.UIHandler.ShowUI) { var dist = l.Prop.Position.DistanceTo(Game.Player.Character.Position); if (dist < 60) { OutputArgument xArg = new OutputArgument(); OutputArgument yArg = new OutputArgument(); var pos = l.Prop.Position; var dimensions = l.Prop.Model.GetDimensions(); pos.Y -= dimensions.Y / 2; pos.Z += 0.4f; Function.Call(Hash._WORLD3D_TO_SCREEN2D, pos.X, pos.Y, pos.Z, xArg, yArg); var x = xArg.GetResult<float>(); var y = yArg.GetResult<float>(); var itemName = l.Item.Type == ItemType.Money ? "gta$" + l.Item.MoneyValue : l.Item.Quantity + "x " + l.Item.Name; new UIRectangle(new Point((int)(UI.WIDTH * x) - 50, (int)(UI.HEIGHT * y) + 12), new Size(100, 2), l.Item.GetRarityColor()).Draw(); new UIText(itemName, new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y)), 0.21f, Color.White, 0, true).Draw(); } } l.Prop.ApplyForce(new Vector3(0,0,-0.1f)); } } var nearbyForVecs = World.GetAllVehicles(); foreach (var vec in nearbyForVecs.Where(v => v.EngineHealth <= 0)) { if (RPG.PlayerData.CurrentVehicle != null && vec.Handle == RPG.PlayerData.CurrentVehicle.Handle) continue; if (!KilledVecs.Contains(vec.Handle)) { KilledVecs.Add(vec.Handle); var rng = Random.Range(0, 100 + 1); if(rng < 70) { var m = new Model(GM.GetHashKey("prop_box_guncase_03a")); m.Request(1000); var p = World.CreateProp(m, vec.Position + new Vector3(0, 0, 1.0f) + Vector3.RandomXY(), vec.Rotation, true, false); p.ApplyForce(new Vector3(0, 0, -0.05f)); RPG.WorldData.AddLoot(new LootItem(ItemRepository.Get("Vehicle Parts"), p)); } else if (rng < 80) { var m = new Model(GM.GetHashKey("prop_box_guncase_03a")); m.Request(1000); var p = World.CreateProp(m, vec.Position + new Vector3(0, 0, 1.0f) + Vector3.RandomXY(), vec.Rotation, true, false); p.ApplyForce(new Vector3(0, 0, -0.05f)); RPG.WorldData.AddLoot(new LootItem(ItemRepository.Get("Vehicle Repair Kit"), p)); } if (!vec.HasBeenDamagedBy(Game.Player.Character)) continue; if (vec.Model.IsHelicopter) { RPG.Notify(Notification.Kill("destroyed helicopter: +100 Exp")); PlayerData.AddExp(100); } else if (vec.Model.IsPlane) { RPG.Notify(Notification.Kill("destroyed aircraft: +150 Exp")); PlayerData.AddExp(150); } else if (vec.Model.IsBoat) { RPG.Notify(Notification.Kill("Destroyed Boat: +200 Exp")); PlayerData.AddExp(200); } else if (vec.Model.IsBike) { RPG.Notify(Notification.Kill("Destroyed Bike: +20 Exp")); PlayerData.AddExp(20); } else if (vec.Model.IsTrain) { RPG.Notify(Notification.Kill("Destroyed Train: +500 Exp")); PlayerData.AddExp(500); } else { RPG.Notify(Notification.Kill("Destroyed Vehicle: +15 Exp")); PlayerData.AddExp(15); } CheckIfForQuest(vec, vec.Model.Hash, false); } } var nearbyForKills = World.GetAllPeds(); //var nearbyForKills = World.GetAllPeds(); foreach (var ped in nearbyForKills.Where(p => !p.IsAlive)) { if (ped.CurrentBlip != null) ped.CurrentBlip.Remove(); var n = RPG.WorldData.Npcs.FirstOrDefault(x => x.Ped != null && x.Ped.Handle == ped.Handle); if (n != null) { RPG.WorldData.Npcs.Remove(n); } if (!KilledPeds.Contains(ped.Handle)) { KilledPeds.Add(ped.Handle); //Check if kill needed for quest CheckIfForQuest(ped,ped.Model.Hash, true); //If player didn't damage, continue if (!ped.HasBeenDamagedBy(Game.Player.Character)) continue; if (!PlayerData.Tutorial.GetAKill && PlayerData.Tutorial.PressJToOpenMenu && PlayerData.Tutorial.BoughtAmmoFromShop) { var tut = RPG.GetPopup<TutorialBox>(); PlayerData.Tutorial.GetAKill = true; PlayerData.SkillExp += 100; EventHandler.Do(o => { tut.Hide(); Wait(300); if (!RPG.PlayerData.Tutorial.UnlockSkillWithSp) { tut.Pop("Hope you haven't attracted the cops. If so lose them. Time to unlock some skills.", "Access the menu > Character Menu > Skills. Unlock your first skill."); } }); } RPG.Notify(Notification.Kill("target eliminated: +5 Exp")); //Basic loot rng var rng = Random.Range(0, 100 + 1); if(rng < 70) { var m = new Model(GM.GetHashKey("prop_cash_pile_01")); m.Request(1000); var p = World.CreateProp(m, ped.Position + new Vector3(0, 0, 2.2F) + Vector3.RandomXYZ(), ped.Rotation, true, false); p.ApplyForce(new Vector3(0, 0, 0.05f)); RPG.WorldData.AddLoot(new LootItem(ItemRepository.Cash(Random.Range(20, 80)), p)); } if(rng < 30) { var items2 = new[] { "Bandages", "Basic Scraps", "Simple Protective Gear","Ammo Pack I" }; var m2 = new Model(GM.GetHashKey("prop_money_bag_01")); m2.Request(1000); var p2 = World.CreateProp(m2, ped.Position + new Vector3(0, 0.5f, 2.2F) + Vector3.RandomXY(), ped.Rotation, true, false); p2.ApplyForce(new Vector3(0, 0, 0.05f)); RPG.WorldData.AddLoot(new LootItem(ItemRepository.Get(items2[Random.Range(0, items2.Length)]), p2)); } else if(rng < 40) { var items2 = new[] { "Health Kit" , "Refurbished Kevlar","Ammo Pack II" }; var m2 = new Model(GM.GetHashKey("prop_money_bag_01")); m2.Request(1000); var p2 = World.CreateProp(m2, ped.Position + new Vector3(0.5f, 0, 2.2F) + Vector3.RandomXY(), ped.Rotation, true, false); p2.ApplyForce(new Vector3(0, 0, 0.05f)); RPG.WorldData.AddLoot(new LootItem(ItemRepository.Get(items2[Random.Range(0, items2.Length)]), p2)); } PlayerData.AddExp(5); } } var activeQuests = PlayerData.Quests.Where(q => q.InProgress).ToList(); for (int i = 0; i < activeQuests.Count; i++) { activeQuests[i].CheckState(); } QuestUpdates(); }
public static bool WorldToScreenRel_Native(Vector3 worldCoords, out Vector2 screenCoords) { var num1 = new OutputArgument(); var num2 = new OutputArgument(); if (!Function.Call<bool>(Hash._WORLD3D_TO_SCREEN2D, worldCoords.X, worldCoords.Y, worldCoords.Z, num1, num2)) { screenCoords = new Vector2(); return false; } screenCoords = new Vector2((num1.GetResult<float>() - 0.5f) * 2, (num2.GetResult<float>() - 0.5f) * 2); return true; }