Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Cayo Perico Heist
      2. The Diamond Casino Heist
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA VI

      1. St. Andrews Cathedral
    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

Cyron43

Strange behavior of Task.GoTo

Recommended Posts

Cyron43

Hi,

I don't know what causes this behavior. Is it the .net scripthook (build from 05/21 installed) or is it the native function under the hood?

Anyway, when I try to let my player character walk towards a waypoint he just stands idle BUT when I set a waypoint anywhere in water he starts running and even follows pathways! At the time he gets into the water he even swims towards the waypoint. I just make this simple call:

 

Game.Player.Character.Task.GoTo(CommonFunctions.GetWaypoint().Position, ignorePaths: false);
Note: CommonFunctions is a static class from my own framework and contains (among other things) temporary implementations which didn't make it into the .net script hook yet. GetWaypoint() is one of those.

 

      public static Blip GetWaypoint()      {         try         {            return World.GetActiveBlips().FirstOrDefault(b => b.Type == 4);         }         catch(ArgumentNullException)         {            return null;         }      }
Edit to add: He must either be in the water or near the water at the beach. It only works if the waypoint is set somewhere in the ocean. It does not work on lakes. Edited by Cyron43

Share this post


Link to post
Share on other sites
Graphicscore

I've had this strange behavior too, I can't remember how exactly I did it, I'll post my Code as soon as I am back @home :)

Share this post


Link to post
Share on other sites
Cyron43

Thanks. It seems this method (or native function) rather be named SwimTo.

  • Like 1

Share this post


Link to post
Share on other sites
c39687

i suspect it has something to do with the Z value of the position he is going to. Try something like this... and im not sure im using proper code so just make the necessary corrections (these methods existed in the old shdn)...

 

Vector3 goToPos = new Vector3(wayPoint.Position.X, wayPoint.Position.Y, wayPoint.Position.ToGround().Z);

 

ToGround is a wrapper for a native that gets the ground Z position, just search for it in the natives.h

Share this post


Link to post
Share on other sites
Graphicscore

This is the code I used :

player.Task.GoTo(new GTA.Math.Vector3(2369.901F, 6614.253F, 234F), true);I think you have to do the ignore path to true , like in my case there was no street or something.

Share this post


Link to post
Share on other sites
Cyron43

i suspect it has something to do with the Z value of the position he is going to. Try something like this... and im not sure im using proper code so just make the necessary corrections (these methods existed in the old shdn)...

 

Vector3 goToPos = new Vector3(wayPoint.Position.X, wayPoint.Position.Y, wayPoint.Position.ToGround().Z);

 

ToGround is a wrapper for a native that gets the ground Z position, just search for it in the natives.h

Now that brings up the question "what is the ground" when it comes to the ocean? One should think it's the bottom of the sea but technically it could be as well the height of the water surface (is that 0 anyway?). Ima do some more experiments and also with Driving style and the ignore path parameter (@Graphicscore).

Thanks for your replies, guys. :)

Edited by Cyron43

Share this post


Link to post
Share on other sites
c39687

i would suspect the logical origin for Z is at sea level but it really could be an arbitry plane the developers picked. Just test it by printing ground z of a position where X,Y is over the ocean

 

here is the native btw... (not sure about the return type but BOOL is just an integer, it is different than bool and 0 represents false, use with Function.Call<int> i also suspect this declaration is not 100% accurate)

static  BOOL GET_GROUND_Z_FOR_3D_COORD(float x, float y, float z, float* groundZ) { return invoke<BOOL>(0xC906A7DAB05C8D2B, x, y, z, groundZ); } // 0xC906A7DAB05C8D2B 0xA1BFD5E0
Edited by c39687

Share this post


Link to post
Share on other sites
Cyron43

Thanks c39687. I use World.GetGroundZ of the .net scripthook. Isn't that the same under the hood?

Anyway I did some tests with all combinations of parameters and here is what I got:

 

This editor sucks for real! I can't edit a table because all the formatting gets lost. Here is a png instead.

zn3sp1.png

Note: walks/swims straight means he gets stuck at whatever obstacle is in the line between him and the waypoint.

Edited by Cyron43

Share this post


Link to post
Share on other sites
c39687

before you task the ped to go somewhere try using...

 

 

static BOOL LOAD_ALL_PATH_NODES(BOOL p0) { return invoke<BOOL>(0x80E4A6EDDB0BE8D9, p0); } // 0x80E4A6EDDB0BE8D9 0xC66E28C3

 

 

use 1 to load all paths and 0 just loads paths around the player, not sure paths are the exact problem but them idling when you tell them to use a path may suggest the paths are not loaded

Share this post


Link to post
Share on other sites
c39687

btw... when you change ignore paths you are using different natives to make the ped move, you may need to call other native functions as well to get this all to work... you can check the game scripts for examples of the context these natives are used in...

 

IgnorePaths = TASK_GO_STRAIGHT_TO_COORD

!IgnorePaths = TASK_FOLLOW_NAV_MESH_TO_COORD (you may need to call some native that loads the navmesh)

 

i really dont know how this all works in GTA but trial and error plus researching the game scripts may solve the problem

 

try researching how the natives relevant to "NavMeshes" are used...

 

 

 

namespace  PATHFIND{  static void SET_ROADS_IN_AREA(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7) { invoke<Void>(0xBF1A602B5BA52FEE, p0, p1, p2, p3, p4, p5, p6, p7); } // 0xBF1A602B5BA52FEE 0xEBC7B918  static void SET_ROADS_IN_ANGLED_AREA(float p0, float p1, float p2, float p3, float p4, float p5, float p6, BOOL p7, BOOL p8, BOOL p9) { invoke<Void>(0x1A5AA1208AF5DB59, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } // 0x1A5AA1208AF5DB59 0xBD088F4B  static void SET_PED_PATHS_IN_AREA(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6) { invoke<Void>(0x34F060F4BF92E018, p0, p1, p2, p3, p4, p5, p6); } // 0x34F060F4BF92E018 0x2148EA84  static Any GET_SAFE_COORD_FOR_PED(float x, float y, float z, Any p3, Vector3* outPosition, Any p5) { return invoke<Any>(0xB61C8E878A4199CA, x, y, z, p3, outPosition, p5); } // 0xB61C8E878A4199CA 0xB370270A  static BOOL GET_CLOSEST_VEHICLE_NODE(float x, float y, float z, Vector3* outPosition, int p4, float p5, float p6) { return invoke<BOOL>(0x240A18690AE96513, x, y, z, outPosition, p4, p5, p6); } // 0x240A18690AE96513 0x6F5F1E6C  static Any GET_CLOSEST_MAJOR_VEHICLE_NODE(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5) { return invoke<Any>(0x2EABE3B06F58C1BE, p0, p1, p2, p3, p4, p5); } // 0x2EABE3B06F58C1BE 0x04B5F15B  static Any GET_CLOSEST_VEHICLE_NODE_WITH_HEADING(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7) { return invoke<Any>(0xFF071FB798B803B0, p0, p1, p2, p3, p4, p5, p6, p7); } // 0xFF071FB798B803B0 0x8BD5759B  static BOOL GET_NTH_CLOSEST_VEHICLE_NODE(float x, float y, float z, int nthClosest, Vector3* outPosition, Any unknown1, Any unknown2, Any unknown3) { return invoke<BOOL>(0xE50E52416CCF948B, x, y, z, nthClosest, outPosition, unknown1, unknown2, unknown3); } // 0xE50E52416CCF948B 0xF125BFCC  static int GET_NTH_CLOSEST_VEHICLE_NODE_ID(float p0, float p1, float p2, Any p3, Any p4, float p5, float p6) { return invoke<int>(0x22D7275A79FE8215, p0, p1, p2, p3, p4, p5, p6); } // 0x22D7275A79FE8215 0x3F358BEA  static BOOL GET_NTH_CLOSEST_VEHICLE_NODE_WITH_HEADING(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7, Any p8, Any p9) { return invoke<BOOL>(0x80CA6A8B6C094CC4, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } // 0x80CA6A8B6C094CC4 0x7349C856  static Any GET_NTH_CLOSEST_VEHICLE_NODE_ID_WITH_HEADING(float p0, float p1, float p2, Any p3, Any* p4, Any* p5, Any p6, float p7, float p8) { return invoke<Any>(0x6448050E9C2A7207, p0, p1, p2, p3, p4, p5, p6, p7, p8); } // 0x6448050E9C2A7207 0xC1AEB88D  static Any GET_NTH_CLOSEST_VEHICLE_NODE_FAVOUR_DIRECTION(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7, Any p8, Any p9, Any p10, Any p11) { return invoke<Any>(0x45905BE8654AE067, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); } // 0x45905BE8654AE067 0x928A4DEC  static BOOL GET_VEHICLE_NODE_PROPERTIES(float p0, float p1, float p2, Any* p3, Any* p4) { return invoke<BOOL>(0x0568566ACBB5DEDC, p0, p1, p2, p3, p4); } // 0x0568566ACBB5DEDC 0xCC90110B  static BOOL IS_VEHICLE_NODE_ID_VALID(int p0) { return invoke<BOOL>(0x1EAF30FCFBF5AF74, p0); } // 0x1EAF30FCFBF5AF74 0x57DFB1EF  static void GET_VEHICLE_NODE_POSITION(Any p0, Vector3* outPosition) { invoke<Void>(0x703123E5E7D429C2, p0, outPosition); } // 0x703123E5E7D429C2 0xE38E252D  static BOOL _0xA2AE5C478B96E3B6(int p0) { return invoke<BOOL>(0xA2AE5C478B96E3B6, p0); } // 0xA2AE5C478B96E3B6 0xEE4B1219  static BOOL _0x4F5070AA58F69279(int p0) { return invoke<BOOL>(0x4F5070AA58F69279, p0); } // 0x4F5070AA58F69279 0x56737A3C  static Any GET_CLOSEST_ROAD(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7, Any p8, Any p9, Any p10) { return invoke<Any>(0x132F52BBA570FE92, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } // 0x132F52BBA570FE92 0x567B0E11  static BOOL LOAD_ALL_PATH_NODES(BOOL p0) { return invoke<BOOL>(0x80E4A6EDDB0BE8D9, p0); } // 0x80E4A6EDDB0BE8D9 0xC66E28C3  static void _0x228E5C6AD4D74BFD(BOOL p0) { invoke<Void>(0x228E5C6AD4D74BFD, p0); } // 0x228E5C6AD4D74BFD 0xD6A3B458  static BOOL _0xF7B79A50B905A30D(float p0, float p1, float p2, float p3) { return invoke<BOOL>(0xF7B79A50B905A30D, p0, p1, p2, p3); } // 0xF7B79A50B905A30D 0x86E80A17  static BOOL _0x07FB139B592FA687(float p0, float p1, float p2, float p3) { return invoke<BOOL>(0x07FB139B592FA687, p0, p1, p2, p3); } // 0x07FB139B592FA687 0x2CDA5012  static void SET_ROADS_BACK_TO_ORIGINAL(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5) { invoke<Void>(0x1EE7063B80FFC77C, p0, p1, p2, p3, p4, p5); } // 0x1EE7063B80FFC77C 0x86AC4A85  static void SET_ROADS_BACK_TO_ORIGINAL_IN_ANGLED_AREA(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6) { invoke<Void>(0x0027501B9F3B407E, p0, p1, p2, p3, p4, p5, p6); } // 0x0027501B9F3B407E 0x9DB5D209  static void _0x0B919E1FB47CC4E0(float p0) { invoke<Void>(0x0B919E1FB47CC4E0, p0); } // 0x0B919E1FB47CC4E0 0x3C5085E4  static void _0xAA76052DDA9BFC3E(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6) { invoke<Void>(0xAA76052DDA9BFC3E, p0, p1, p2, p3, p4, p5, p6); } // 0xAA76052DDA9BFC3E 0xD0F51299  static void SET_PED_PATHS_BACK_TO_ORIGINAL(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5) { invoke<Void>(0xE04B48F2CC926253, p0, p1, p2, p3, p4, p5); } // 0xE04B48F2CC926253 0x3F1ABDA4  static Any GET_RANDOM_VEHICLE_NODE(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7, Any p8) { return invoke<Any>(0x93E0DB8440B73A7D, p0, p1, p2, p3, p4, p5, p6, p7, p8); } // 0x93E0DB8440B73A7D 0xAD1476EA  static void GET_STREET_NAME_AT_COORD(float p0, float p1, float p2, Hash* p3, Hash* p4) { invoke<Void>(0x2EB41072B4C1E4C0, p0, p1, p2, p3, p4); } // 0x2EB41072B4C1E4C0 0xDEBEEFCF  static Any GENERATE_DIRECTIONS_TO_COORD(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6) { return invoke<Any>(0xF90125F1F79ECDF8, p0, p1, p2, p3, p4, p5, p6); } // 0xF90125F1F79ECDF8 0xED35C094  static void SET_IGNORE_NO_GPS_FLAG(BOOL p0) { invoke<Void>(0x72751156E7678833, p0); } // 0x72751156E7678833 0xB72CF194  static void _0x1FC289A0C3FF470F(BOOL p0) { invoke<Void>(0x1FC289A0C3FF470F, p0); } // 0x1FC289A0C3FF470F 0x90DF7A4C  static void SET_GPS_DISABLED_ZONE(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5) { invoke<Void>(0xDC20483CD3DD5201, p0, p1, p2, p3, p4, p5); } // 0xDC20483CD3DD5201 0x720B8073  static Any _0xBBB45C3CF5C8AA85() { return invoke<Any>(0xBBB45C3CF5C8AA85); } // 0xBBB45C3CF5C8AA85 0x4B770634  static Any _0x869DAACBBE9FA006() { return invoke<Any>(0x869DAACBBE9FA006); } // 0x869DAACBBE9FA006 0x286F82CC  static Any _0x16F46FB18C8009E4(Any p0, Any p1, Any p2, Any p3, Any p4) { return invoke<Any>(0x16F46FB18C8009E4, p0, p1, p2, p3, p4); } // 0x16F46FB18C8009E4 0xF6422F9A  static BOOL IS_POINT_ON_ROAD(float p0, float p1, float p2, Any p3) { return invoke<BOOL>(0x125BF4ABFC536B09, p0, p1, p2, p3); } // 0x125BF4ABFC536B09 0xCF198055  static void ADD_NAVMESH_REQUIRED_REGION(float p0, float p1, float p2) { invoke<Void>(0x387EAD7EE42F6685, p0, p1, p2); } // 0x387EAD7EE42F6685 0x12B086EA  static void REMOVE_NAVMESH_REQUIRED_REGIONS() { invoke<Void>(0x916F0A3CDEC3445E); } // 0x916F0A3CDEC3445E 0x637BB680  static void DISABLE_NAVMESH_IN_AREA(Any p0, Any p1, Any p2, Any p3, Any p4, Any p5, Any p6) { invoke<Void>(0x4C8872D8CDBE1B8B, p0, p1, p2, p3, p4, p5, p6); } // 0x4C8872D8CDBE1B8B 0x6E37F132  static BOOL ARE_ALL_NAVMESH_REGIONS_LOADED() { return invoke<BOOL>(0x8415D95B194A3AEA); } // 0x8415D95B194A3AEA 0x34C4E789  static BOOL IS_NAVMESH_LOADED_IN_AREA(float p0, float p1, float p2, float p3, float p4, float p5) { return invoke<BOOL>(0xF813C7E63F9062A5, p0, p1, p2, p3, p4, p5); } // 0xF813C7E63F9062A5 0x4C2BA99E  static Any _0x01708E8DD3FF8C65(float p0, float p1, float p2, float p3, float p4, float p5) { return invoke<Any>(0x01708E8DD3FF8C65, p0, p1, p2, p3, p4, p5); } // 0x01708E8DD3FF8C65  static Any ADD_NAVMESH_BLOCKING_OBJECT(float p0, float p1, float p2, float p3, float p4, float p5, float p6, BOOL p7, Any p8) { return invoke<Any>(0xFCD5C8E06E502F5A, p0, p1, p2, p3, p4, p5, p6, p7, p8); } // 0xFCD5C8E06E502F5A 0x2952BA56  static void UPDATE_NAVMESH_BLOCKING_OBJECT(Any p0, float p1, float p2, float p3, float p4, float p5, float p6, float p7, Any p8) { invoke<Void>(0x109E99373F290687, p0, p1, p2, p3, p4, p5, p6, p7, p8); } // 0x109E99373F290687 0x4E9776D0  static void REMOVE_NAVMESH_BLOCKING_OBJECT(Any p0) { invoke<Void>(0x46399A7895957C0E, p0); } // 0x46399A7895957C0E 0x098602B0  static BOOL _0x0EAEB0DB4B132399(Any p0) { return invoke<BOOL>(0x0EAEB0DB4B132399, p0); } // 0x0EAEB0DB4B132399 0x4B67D7EE  static float _0x29C24BFBED8AB8FB(float p0, float p1) { return invoke<float>(0x29C24BFBED8AB8FB, p0, p1); } // 0x29C24BFBED8AB8FB 0x3FE8C5A0  static float _0x8ABE8608576D9CE3(float p0, float p1, float p2, float p3) { return invoke<float>(0x8ABE8608576D9CE3, p0, p1, p2, p3); } // 0x8ABE8608576D9CE3 0x3ED21C90  static float _0x336511A34F2E5185(float p0, float p1) { return invoke<float>(0x336511A34F2E5185, p0, p1); } // 0x336511A34F2E5185 0xA07C5B7D  static float _0x3599D741C9AC6310(float p0, float p1, float p2, float p3) { return invoke<float>(0x3599D741C9AC6310, p0, p1, p2, p3); } // 0x3599D741C9AC6310 0x76751DD4  static float CALCULATE_TRAVEL_DISTANCE_BETWEEN_POINTS(float x1, float y1, float z1, float x2, float y2, float z2) { return invoke<float>(0xADD95C7005C4A197, x1, y1, z1, x2, y2, z2); } // 0xADD95C7005C4A197 0xB114489B}

 

Edited by c39687

Share this post


Link to post
Share on other sites
Cyron43

o_0 just wow!

Thanks so much for your help, @c39687. That's gonna take some time to fiddle with.

BTW I used LoadAllPathNodes already but that didn't do it.

Edited by Cyron43

Share this post


Link to post
Share on other sites
Graphicscore

If I remember right , you can give the ped a custom Nav grid mesh (basically an array of Vector3s) where the entity would actually walk from Vector to Vector. If of course the route should be calculated automatically he can only use the Vector's given by the game, maybe you could try to ignore paths and walk to the nearest Vector of the Games Nav Mesh Grid and calculate your war from there on. Just a guess.

 

-Created from mobile, keep typos :)

Share this post


Link to post
Share on other sites
Cyron43

HEUREKA!
I got grey hairs over this the last days and you know what? It wasn't my fault! I thought, well just maybe there's something wrong with the GetGroundZ method in the .net scripthook. So I tried to recreate it myself and as I was reading the description in the natives DB some special words caught my attention:
"Note that if the specified position is below ground level, the function will output zero!"
AHA! The Z-value of a waypoint is always 0 and even the lowest terrain at Trevor's home is about 32 units in elevation. So GetGroundZ returns 0 as described!

With that in mind I went to the highest elevation on the map, the roof top of the cable car station on mount Chiliad and got a Z-value of about 797 units. Here is my simple solution:

      public static Vector3 ToGround(this Vector3 position)      {         position.Z = 1000.0f;         return new Vector3(position.X, position.Y, World.GetGroundZ(position));      }

With the help of this extension method the rest was a piece of cake.

      private void GoToWaypoint()      {         _isActive = !_isActive;         if(!_isActive)         {            Game.Player.Character.Task.ClearAll();            UI.Notify("Walking task should be released now.");            return;         }         var waypoint = CommonFunctions.GetWaypoint();         if(waypoint == null)         {            _isActive = false;            UI.Notify("No waypoint found.");            return;         }         UI.Notify("Character should be walking now.");         CommonFunctions.LoadAllPathNodes(true);         Game.Player.Character.Task.RunTo(waypoint.Position.ToGround(), ignorePaths: false);         Game.Player.Character.Task.ClearAll();      }

TADDAA! The route could not be calculated because the target was below ground but that issue is history now. :)

I wouldn't wonder if Autodrive is also less error prone now.

Edited by Cyron43
  • Like 1

Share this post


Link to post
Share on other sites
Graphicscore

HEUREKA!

I got grey hairs over this the last days and you know what? It wasn't my fault! I thought, well just maybe there's something wrong with the GetGroundZ method in the .net scripthook. So I tried to recreate it myself and as I was reading the description in the natives DB some special words caught my attention:

"Note that if the specified position is below ground level, the function will output zero!"

AHA! The Z-value of a waypoint is always 0 and even the lowest terrain at Trevor's home is about 32 units in elevation. So GetGroundZ returns 0 as described!

With that in mind I went to the highest elevation on the map, the roof top of the cable car station on mount Chiliad and got a Z-value of about 797 units. Here is my simple solution:

      public static Vector3 ToGround(this Vector3 position)      {         position.Z = 1000.0f;         return new Vector3(position.X, position.Y, World.GetGroundZ(position));      }

With the help of this extension method the rest was a piece of cake.

      private void GoToWaypoint()      {         _isActive = !_isActive;         if(!_isActive)         {            Game.Player.Character.Task.ClearAll();            UI.Notify("Walking task should be released now.");            return;         }         var waypoint = CommonFunctions.GetWaypoint();         if(waypoint == null)         {            _isActive = false;            UI.Notify("No waypoint found.");            return;         }         UI.Notify("Character should be walking now.");         CommonFunctions.LoadAllPathNodes(true);         Game.Player.Character.Task.RunTo(waypoint.Position.ToGround(), ignorePaths: false);         Game.Player.Character.Task.ClearAll();      }

TADDAA! The route could not be calculated because the target was below ground but that issue is history now. :)

I wouldn't wonder if Autodrive is also less error prone now.

 

Oh , nice. ! Maybe you should post that at the github page of the .NET scripthook though :)

  • Like 1

Share this post


Link to post
Share on other sites
Cyron43

 

HEUREKA!

I got grey hairs over this the last days and you know what? It wasn't my fault! I thought, well just maybe there's something wrong with the GetGroundZ method in the .net scripthook. So I tried to recreate it myself and as I was reading the description in the natives DB some special words caught my attention:

"Note that if the specified position is below ground level, the function will output zero!"

AHA! The Z-value of a waypoint is always 0 and even the lowest terrain at Trevor's home is about 32 units in elevation. So GetGroundZ returns 0 as described!

With that in mind I went to the highest elevation on the map, the roof top of the cable car station on mount Chiliad and got a Z-value of about 797 units. Here is my simple solution:

      public static Vector3 ToGround(this Vector3 position)      {         position.Z = 1000.0f;         return new Vector3(position.X, position.Y, World.GetGroundZ(position));      }

With the help of this extension method the rest was a piece of cake.

      private void GoToWaypoint()      {         _isActive = !_isActive;         if(!_isActive)         {            Game.Player.Character.Task.ClearAll();            UI.Notify("Walking task should be released now.");            return;         }         var waypoint = CommonFunctions.GetWaypoint();         if(waypoint == null)         {            _isActive = false;            UI.Notify("No waypoint found.");            return;         }         UI.Notify("Character should be walking now.");         CommonFunctions.LoadAllPathNodes(true);         Game.Player.Character.Task.RunTo(waypoint.Position.ToGround(), ignorePaths: false);         Game.Player.Character.Task.ClearAll();      }

TADDAA! The route could not be calculated because the target was below ground but that issue is history now. :)

I wouldn't wonder if Autodrive is also less error prone now.

 

Oh , nice. ! Maybe you should post that at the github page of the .NET scripthook though :)

 

I created an issue ticket with a link to this post, my friend. :)

https://github.com/crosire/scripthookvdotnet/issues/180

Edited by Cyron43

Share this post


Link to post
Share on other sites
Cyron43

Yep, no flaws in the pathfinding with my Autodrive anymore. :)

Share this post


Link to post
Share on other sites
Michael Wojtanis

Why the goto function making ped ALWAYS turn to north?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.