Advertisement
Eddlm

GenerateSpawnpos

May 1st, 2018
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1.         public enum Nodetype { AnyRoad,Highway , Road, Offroad, Water }
  2.         public static Vector3 GenerateSpawnPos(Vector3 desiredPos, Nodetype roadtype, bool sidewalk)
  3.         {
  4.  
  5.             Vector3 finalpos = Vector3.Zero;
  6.  
  7.  
  8.             OutputArgument outArgA = new OutputArgument();
  9.             int NodeNumber = 1;
  10.             int type = 0;
  11.  
  12.             if (roadtype == Nodetype.AnyRoad) type = 1;
  13.             if (roadtype == Nodetype.Road || roadtype == Nodetype.Highway) type = 0;
  14.             if (roadtype == Nodetype.Offroad) { type = 1; }
  15.             if (roadtype == Nodetype.Water) type = 3;
  16.  
  17.  
  18.             int NodeID = Function.Call<int>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_ID, desiredPos.X, desiredPos.Y, desiredPos.Z, NodeNumber, type, 300f, 300f);
  19.  
  20.             if ( roadtype== Nodetype.Offroad || roadtype == Nodetype.Highway )
  21.             {
  22.                 for (int i = 0; i < 100; i++)
  23.                 {
  24.                     if(roadtype == Nodetype.Highway)
  25.                     {
  26.                         Function.Call(Hash.GET_VEHICLE_NODE_POSITION, NodeID, outArgA);
  27.                         Vector3 properPos = outArgA.GetResult<Vector3>();
  28.  
  29.                         if (!RoadHasFlag(properPos, PathnodeFlags.Freeway)) // !Function.Call<bool>(Hash._GET_IS_SLOW_ROAD_FLAG, NodeID))
  30.                         {
  31.                             NodeID = Function.Call<int>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_ID, desiredPos.X, desiredPos.Y, desiredPos.Z, NodeNumber, type, 300f, 300f);
  32.                             NodeNumber++;
  33.                         }
  34.                         else break;
  35.                     }
  36.                     if (roadtype == Nodetype.Offroad )
  37.                     {
  38.                         if (!Function.Call<bool>(Hash._GET_IS_SLOW_ROAD_FLAG, NodeID))
  39.                         {
  40.                             NodeID = Function.Call<int>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_ID, desiredPos.X, desiredPos.Y, desiredPos.Z, NodeNumber, type, 300f, 300f);
  41.                             NodeNumber++;
  42.                         }
  43.                         else break;
  44.                     }
  45.                 }
  46.             }
  47.  
  48.             Function.Call(Hash.GET_VEHICLE_NODE_POSITION, NodeID, outArgA);
  49.             finalpos = outArgA.GetResult<Vector3>();
  50.  
  51.             if (sidewalk) finalpos = World.GetNextPositionOnSidewalk(finalpos);
  52.             return finalpos;
  53.  
  54.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement