GlitchWolfNLD Posted October 14, 2018 Share Posted October 14, 2018 I'm trying to get my victim ped to spawn on a sidewalk somewhere random on the map within a range from the player however the ped just ends up spawning at (0,0,0) when I have a range greater then 200 from the player. I would love to have a much larger range I am using the World.GetSafeCoordForPed(Vector3 pos, bool sidewalk) method. Thanks in advance! Link to comment Share on other sites More sharing options...
Guest Posted October 14, 2018 Share Posted October 14, 2018 (edited) I have used this in the past World.GetNextPositionOnSidewalk. Which actually just calls the same native GET_SAFE_COORD_FOR_PED as the function you used. One thing to be aware of, is beyond a certain range from the player, the map or collision might not have loaded and I think that can affect the results of functions like this. If you can see the spawn location, or it's close- by, you have a better chance of success. Edited October 15, 2018 by Guest Link to comment Share on other sites More sharing options...
Guest Posted October 14, 2018 Share Posted October 14, 2018 (edited) Just something further on this, I noticed in NativeDB they mentioned the flags option for GET_SAFE_COORD_FOR_PED, which you can also access with one of the overloads for World.GetSafeCoordForPed, it's GetSafeCoordForPed(Vector3 pos, bool sidewalk, int flags). There seems to be a list of common flag values that are used in the scripts, so what I would be tempted to do, is create a small test mod that gets a result with each of the flag settings and then draw different coloured markers at the positions returned by each one. That way, you can see if any flag settings give consistently good or bad results, which might let you refine your checking for optimal results. Edited October 15, 2018 by Guest Link to comment Share on other sites More sharing options...
NModds Posted November 1, 2018 Share Posted November 1, 2018 On 10/14/2018 at 8:40 AM, LeeC2202 said: I have used this in the past World.GetNextPositionOnSidewalk. Which actually just calls the same native GET_SAFE_COORD_FOR_PED as the function you used. One thing to be aware of, is beyond a certain range from the player, the map or collision might not have loaded and I think that can affect the results of functions like this. If you can see the spawn location, or it's close- by, you have a better chance of success. Now it makes sense why I can't spawn something really far away from the player using get ground z coord or even waypoint teleporting because the map collision didn't load. Is that also the same reason why raycasting doesn't work for extreme distances? I have tested it a little and found that if I teleport to a really far part of the map and I raycast back to the original position I can then teleport back to where I started even if it is almost half way across the city but it is highly inconsistent to say the pattern is always true. Example would be from maze tower raycasted to the bridge or to the beach. Link to comment Share on other sites More sharing options...
Guest Posted November 1, 2018 Share Posted November 1, 2018 Yep, there is a native to request collision but that also only works within a certain range. If you spawn an entity (I have only tried this on a vehicle), you can use Function.Call(Hash.SET_ENTITY_LOAD_COLLISION_FLAG, entity, true); And that will cause that entity to load collision around it. So maybe spawning an entity, set that flag, let that load the collision and then doing the raycast might work. It does seem a bit extreme though if you have to load something like a vehicle, just to get collision but I haven't seen any other way of getting the collision to load at a distance. Link to comment Share on other sites More sharing options...
NModds Posted November 1, 2018 Share Posted November 1, 2018 30 minutes ago, LeeC2202 said: Yep, there is a native to request collision but that also only works within a certain range. If you spawn an entity (I have only tried this on a vehicle), you can use Function.Call(Hash.SET_ENTITY_LOAD_COLLISION_FLAG, entity, true); And that will cause that entity to load collision around it. So maybe spawning an entity, set that flag, let that load the collision and then doing the raycast might work. It does seem a bit extreme though if you have to load something like a vehicle, just to get collision but I haven't seen any other way of getting the collision to load at a distance. Thanks for the info, I will try that out. Link to comment Share on other sites More sharing options...