Advertisement
Eddlm

Road Nodes

Oct 27th, 2019
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1.  
  2.     public enum Nodetype { AnyRoad, Road, Offroad, Water }
  3.     public static Vector3 GenerateSpawnPos(Vector3 desiredPos, Nodetype roadtype, bool sidewalk)
  4.     {
  5.  
  6.         Vector3 finalpos = Vector3.Zero;
  7.         bool ForceOffroad = false;
  8.  
  9.  
  10.         OutputArgument outArgA = new OutputArgument();
  11.         int NodeNumber = 1;
  12.         int type = 0;
  13.  
  14.         if (roadtype == Nodetype.AnyRoad) type = 1;
  15.         if (roadtype == Nodetype.Road) type = 0;
  16.         if (roadtype == Nodetype.Offroad) { type = 1; ForceOffroad = true; }
  17.         if (roadtype == Nodetype.Water) type = 3;
  18.  
  19.  
  20.         int NodeID = Function.Call<int>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_ID, desiredPos.X, desiredPos.Y, desiredPos.Z, NodeNumber, type, 300f, 300f);
  21.  
  22.         if (ForceOffroad)
  23.         {
  24.             for (int i = 0; i < 100; i++)
  25.             {
  26.                 if (!Function.Call<bool>(Hash._GET_IS_SLOW_ROAD_FLAG, NodeID))
  27.                 {
  28.                     NodeID = Function.Call<int>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_ID, desiredPos.X, desiredPos.Y, desiredPos.Z, NodeNumber, type, 300f, 300f);
  29.                     NodeNumber++;
  30.                 }
  31.             }
  32.         }
  33.  
  34.         Function.Call(Hash.GET_VEHICLE_NODE_POSITION, NodeID, outArgA);
  35.         finalpos = outArgA.GetResult<Vector3>();
  36.  
  37.         if (sidewalk) finalpos = World.GetNextPositionOnSidewalk(finalpos);
  38.         return finalpos;
  39.  
  40.     }
  41.  
  42.  
  43.     public enum PathnodeFlags
  44.     {
  45.         Slow = 1,
  46.         Two = 2,
  47.         Intersection = 4,
  48.         Eight = 8, SlowTraffic = 12, ThirtyTwo = 32, Freeway = 64, FourWayIntersection = 128, BigIntersectionLeft = 512
  49.     }
  50.     public static string GetRoadFlags(Vector3 pos)
  51.     {
  52.         OutputArgument outArgA = new OutputArgument();
  53.         OutputArgument outArgB = new OutputArgument();
  54.         if (Function.Call<bool>(Hash.GET_VEHICLE_NODE_PROPERTIES, pos.X, pos.Y, pos.Z, outArgA, outArgB))
  55.         {
  56.             int busy = outArgA.GetResult<int>();
  57.             int flags = outArgB.GetResult<int>();
  58.  
  59.             string d = "";
  60.             foreach (int flag in Enum.GetValues(typeof(PathnodeFlags)).Cast<PathnodeFlags>())
  61.             {
  62.  
  63.                 if ((flag & flags) != 0) d += " " + (PathnodeFlags)flag;
  64.             }
  65.             return d;  // DisplayHelpTextThisFrame("Flags: " + d);
  66.         }
  67.         return "";
  68.     }
  69.     public static bool RoadHasFlag(Vector3 pos, PathnodeFlags flag)
  70.     {
  71.         OutputArgument outArgA = new OutputArgument();
  72.         OutputArgument outArgB = new OutputArgument();
  73.         if (Function.Call<bool>(Hash.GET_VEHICLE_NODE_PROPERTIES, pos.X, pos.Y, pos.Z, outArgA, outArgB))
  74.         {
  75.             int busy = outArgA.GetResult<int>();
  76.             int flags = outArgB.GetResult<int>();
  77.             if ((flags & (int)flag) != 0) return true;
  78.         }
  79.         return false;
  80.     }
  81.  
  82.     public static bool IntHasFlag(int number, int flag)
  83.     {
  84.  
  85.         if ((number & (int)flag) != 0) return true;
  86.         return false;
  87.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement