SHARE
TWEET

GenerateSpawnPos (vehicles, boats, peds)

Eddlm Apr 9th, 2016 (edited) 162 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public enum Nodetype {AnyRoad,Road,Offroad,Water}
  2.     public static Vector3 GenerateSpawnPos(Vector3 desiredPos, Nodetype roadtype, bool sidewalk)
  3.     {
  4.         Vector3 finalpos = Vector3.Zero;
  5.         bool ForceOffroad = false;
  6.  
  7.         OutputArgument outArgA = new OutputArgument();
  8.         OutputArgument outArgB = new OutputArgument();
  9.         OutputArgument outArgC = new OutputArgument();
  10.  
  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 = 4;
  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.         if (ForceOffroad)
  22.         {
  23.             while (!Function.Call<bool>(Hash._GET_IS_SLOW_ROAD_FLAG, NodeID) && NodeNumber < 500)
  24.             {
  25.                 NodeNumber++;
  26.                 NodeID = Function.Call<int>(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_ID, desiredPos.X, desiredPos.Y, desiredPos.Z, NodeNumber + 5, type, 300f, 300f);
  27.             }
  28.         }
  29.         Function.Call(Hash.GET_VEHICLE_NODE_POSITION, NodeID, outArgA);
  30.         finalpos = outArgA.GetResult<Vector3>();
  31.         if (sidewalk) finalpos = World.GetNextPositionOnSidewalk(finalpos);
  32.         return finalpos;
  33.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top