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

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

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

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

BenBaron

Finding a point to spawn a car next to x, y, z

Recommended Posts

BenBaron

Hi guys,

 

I am trying to find a convenient way to get a Vector3 to spawn a car on the road at a certain distance (out of view) from the player. I am wondering how Rockstar does that in terms of their taxi service, though, as investigating the taxilauncher.txt it seems there is no "simple" native for that.

 

I was fiddeling around with GET_CLOSEST_VEHICLE_NODE and such, but I couldn't figure out what they're supposed to do.

 

Instead, it seems to me they are using GET_NAME_OF_ZONE with the Player's coordinates in connection with a string compare in sub_2979. This is then "somehow" used in sub_6C1A with the help of many switch constructions to write suitable, but predefined coordinates into a Vector3. This is then used in sub_6147 to do a GAMEPLAY::CLEAR_AREA and to finally create the vehicle in sub_6268.

 

This is highly speculative, though, and it seems extremely complicated, to me. A lot in the taxilauncher.txt is also simply not understandable, at least from my point of knowledge.

 

Maybe someone has a different idea or understanding of the matter, instead of having to map all zones to suitable coordinates to spawn a vehicle :panic: .

Share this post


Link to post
Share on other sites
Inco

Try something like this.

Around method for Vector3:

Vector3 Vector3::Around(float distance){	return Vector3(this->X, this->Y, this->Z) + getRandomXY() * distance;}...var spawnVector = playerPosition.Around( 60 );

then use GET_CLOSEST_VEHICLE_NODE (or GET_NTH_CLOSEST_VEHICLE_NODE), you will get Vector3 with Heading, assign it to the car and after use SET_VEHICLE_ON_GROUND_PROPERLY.

Share this post


Link to post
Share on other sites
BenBaron

Hi,

 

thanks for your reply.

 

How does GET_CLOSEST_VEHICLE_NODE and such actually work? I was thinking, that the first 3 three params are x, y and z with the 4th being a pointer to a Vector3 that receives the result, should the function return true. The last three are unknown but are almost always 1, 0x40400000, 0 in the scripts.

 

But reading the vector the function fills in is giving me useless and inconcludent results. In your code I also don't know what to do with spawnVector in terms of GET_CLOSEST_VEHICLE_NODE.

Share this post


Link to post
Share on other sites
Inco

spawnVector - distance from the player where you want to spawn a car. With this functions (GET_NTH_CLOSEST_VEHICLE_NODE, SET_VEHICLE_ON_GROUND_PROPERLY) you adjust spawn vector for the car.

I wrote PlaceOnNextStreet method for .net script hook (similar method was in gta 4 .net script hook, i think). It seems that it works fine. Look here: https://github.com/IncoCode/scripthookvdotnet/blob/vehicle_upd/source/Vehicle.cpp#L326

Usage:

_veh = World.CreateVehicle( VehicleHash.Banshee, player.Position.Around( 50 ) );_veh.PlaceOnNextStreet();

Share this post


Link to post
Share on other sites
Prof_Farnsworth

 

spawnVector - distance from the player where you want to spawn a car. With this functions (GET_NTH_CLOSEST_VEHICLE_NODE, SET_VEHICLE_ON_GROUND_PROPERLY) you adjust spawn vector for the car.

I wrote PlaceOnNextStreet method for .net script hook (similar method was in gta 4 .net script hook, i think). It seems that it works fine. Look here: https://github.com/IncoCode/scripthookvdotnet/blob/vehicle_upd/source/Vehicle.cpp#L326

Usage:

_veh = World.CreateVehicle( VehicleHash.Banshee, player.Position.Around( 50 ) );_veh.PlaceOnNextStreet();

Awesome Inco, thank you. I think I used this in every one of my scripts for IV.

Share this post


Link to post
Share on other sites
BenBaron

Hmm...this is weird, as for some reason, this isn't working for me. Here is what I basically do:

Vector3 myCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true);float x, y, z, hdg;if (PATHFIND::GET_NTH_CLOSEST_VEHICLE_NODE(myCoords.x, myCoords.y, myCoords.z, 0, &x, &y, &z, &hdg)){    // here the values in x, y, z and hdg don't make sense at all in terms of returning a point on a street next to myCoords}

But maybe I didn't get it right?

Edited by BenBaron

Share this post


Link to post
Share on other sites
Inco

Did some test and for me it works, but spawn a car too far away :(

Well, need more time to understand how it's works.

Share this post


Link to post
Share on other sites
BenBaron

Did some test and for me it works, but spawn a car too far away :(

Well, need more time to understand how it's works.

 

Thanks for your help, so far...please come back when you discover something :pp .

Share this post


Link to post
Share on other sites
Inco

Well, parameters of GET_NTH_CLOSEST_VEHICLE_NODE slightly different.

GET_NTH_CLOSEST_VEHICLE_NODE(int x, int y, int z, int nodeCount, Vector3 *newPos, Any p6, Any p7, Any p8)

In scripts the last 3 params is 1, 0x40400000, 0 .

Share this post


Link to post
Share on other sites
BenBaron

Well, parameters of GET_NTH_CLOSEST_VEHICLE_NODE slightly different.

GET_NTH_CLOSEST_VEHICLE_NODE(int x, int y, int z, int nodeCount, Vector3 *newPos, Any p6, Any p7, Any p8)

In scripts the last 3 params is 1, 0x40400000, 0 .

 

Yes, that is what I was also trying the whole time, but didn't give me the results I wanted, either. Maybe you can try, if this works for you.

Share this post


Link to post
Share on other sites
Inco

Works fine for me.

1. Get player position;

2. Shift the player's coordinates there where you want to spawn a car (look on AroundTo method above);

3. Use GET_NTH_CLOSEST_VEHICLE_NODE with new coordinates;

4. Spawn a car with coordinates which you got from GET_NTH_CLOSEST_VEHICLE_NODE.

You can see result on this screenshots (used ArountTo method, distance = 100):

Yellow blip - spawned car.

09660c409319779.jpg

35c61d409319782.jpg

Share this post


Link to post
Share on other sites
BenBaron

Thanks for your effort, I will look into it, soon :) .

Share this post


Link to post
Share on other sites
BenBaron

Sorry to bother you again:

 

I'd need to you to confirm the following:

 

Yes, I can get coordinates from GET_NTH_CLOSEST_VEHICLE_NODE to spawn a car, but it doesn't seem that choosing lower values for nodeCount does necessarily mean the resulting coordinates are nearer than with higher values. Simply incrementing nodeCount the distances between my position and the resulting position are jumping around without any pattern. So in order to find the nearest node, you'd need to increment nodeCount, calculate the distance between the two positions at every step and choose the node with the lowest distance to spawn a car, afterwards. Can you confirm this from your side?

 

In addition, I am not getting results from every point in the world, so there are coordinates where GET_NTH_CLOSEST_VEHICLE_NODE always returns false, no matter what nodeCount is used.

 

I am not seeing why using your AroundTo method is necessary to make GET_NTH_CLOSEST_VEHICLE_NODE work, because from my understanding it is returning a new Vector3 with a different random x, y depending on the used distance. This shouldn't be needed if I am simply looking for a node in my direct vicinity, should it? Otherwise I could also use GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDINATES, I guess. Please, correct me if I am wrong... .

 

Maybe you can look at my code again and tell me, if I you can see any flaw, if you cannot confirm the above mentioned behaviour:

Vector3 myCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true);Vector3 resultCoords;if (PATHFIND::GET_CLOSEST_VEHICLE_NODE(myCoords.x, myCoords.y, myCoords.z, 1, &resultCoords, 1, 0x40400000, 0)){				}

Thanks again for your help!

Share this post


Link to post
Share on other sites
Inco

Yes, I can get coordinates from GET_NTH_CLOSEST_VEHICLE_NODE to spawn a car, but it doesn't seem that choosing lower values for nodeCount does necessarily mean the resulting coordinates are nearer than with higher values. Simply incrementing nodeCount the distances between my position and the resulting position are jumping around without any pattern. So in order to find the nearest node, you'd need to increment nodeCount, calculate the distance between the two positions at every step and choose the node with the lowest distance to spawn a car, afterwards. Can you confirm this from your side?

When testing i used several nodeCount: 1 and 10. With 1 it returns nearer coordinate than with 10.

I am not seeing why using your AroundTo method is necessary to make GET_NTH_CLOSEST_VEHICLE_NODE work, because from my understanding it is returning a new Vector3 with a different random x, y depending on the used distance. This shouldn't be needed if I am simply looking for a node in my direct vicinity, should it? Otherwise I could also use GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDINATES, I guess. Please, correct me if I am wrong... .

It's not necessary use AroundTo (or similar) method to make GET_NTH_CLOSEST_VEHICLE_NODE work. You wanted to spawn a car on the road at a certain distance (out of view) from the player, right? So, i suggested use similar on AroundTo method (I then didn't know about existence GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDINATES method) to shift the player's coordinates.

 

In your code you are using GET_CLOSEST_VEHICLE_NODE, not a GET_NTH_CLOSEST_VEHICLE_NODE.

Edited by Inco

Share this post


Link to post
Share on other sites
BenBaron

 

Yes, I can get coordinates from GET_NTH_CLOSEST_VEHICLE_NODE to spawn a car, but it doesn't seem that choosing lower values for nodeCount does necessarily mean the resulting coordinates are nearer than with higher values. Simply incrementing nodeCount the distances between my position and the resulting position are jumping around without any pattern. So in order to find the nearest node, you'd need to increment nodeCount, calculate the distance between the two positions at every step and choose the node with the lowest distance to spawn a car, afterwards. Can you confirm this from your side?

When testing i used several nodeCount: 1 and 10. With 1 it returns nearer coordinate that with 10.

I am not seeing why using your AroundTo method is necessary to make GET_NTH_CLOSEST_VEHICLE_NODE work, because from my understanding it is returning a new Vector3 with a different random x, y depending on the used distance. This shouldn't be needed if I am simply looking for a node in my direct vicinity, should it? Otherwise I could also use GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDINATES, I guess. Please, correct me if I am wrong... .

It's not necessary use AroundTo (or similar) method to make GET_NTH_CLOSEST_VEHICLE_NODE work. You wanted to spawn a car on the road at a certain distance (out of view) from the player, right? So, i suggested use similar on AroundTo method (I then didn't know about existence GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDINATES method) to shift the player's coordinates.

 

In your code you are using GET_CLOSEST_VEHICLE_NODE, not a GET_NTH_CLOSEST_VEHICLE_NODE.

 

 

It was only a typo, it actually is GET_NTH_CLOSEST_VEHICLE_NODE in my code :colgate: ...but in theory you wouldn't see any reason why the above code shouldn't work, right?

Share this post


Link to post
Share on other sites
Inco

Perhaps, problem in 5th parameter, if this function didn't work then 5th not a pointer to Vector3. Something another :D

I used this function in V .net script hook (passed 5th parameter as OutputArgument) therefore I don't have such problems.

Share this post


Link to post
Share on other sites
BenBaron

Ok, so thanks until now for your help...maybe I will have a look at the .net wrapper then, to see if I can find out what the difference is :lol: . And maybe someone else who is scripting in C++ could try to get some meaningful result out of this native :p .

Edited by BenBaron

Share this post


Link to post
Share on other sites
Fireboyd78

'0x40400000' is actually hexadecimal that stands for decimal value 3.0 - could someone mess around with this parameter a bit and report back any changes in behavior? Also, I think the last parameter is actually a BOOL - try messing with that too!

 

Thanks!

Edited by CarLuver69

Share this post


Link to post
Share on other sites
BenBaron

Well, as it seems to be working with the .net wrapper for him but not in C++ for me and he is using 1, 0x40400000, 0 as last 3 paramters like I do I'd say the only explanation is that, like Inco suggested, maybe the outParameter is actually not a Vector3*, but something different. :bored:

Share this post


Link to post
Share on other sites
BenBaron

After fiddeling around with this again I finally found out what the problem was:

 

The first three params (which are the x, y and z coordinates) were defined as int in the natives db and thus also in the natives.h. But they are actually floats, not ints and I've already changed it in the db.

 

It may very well be compiler dependant, but on my system ints are 4 byte while floats are 8 byte types. So I was passing 24 bytes while only 12 where expected as per the header. Don't know what the invoke call does with that but it obviously caused trouble.

 

But now it finally all works :lol: .

Share this post


Link to post
Share on other sites
Freakyy

After fiddeling around with this again I finally found out what the problem was:

 

The first three params (which are the x, y and z coordinates) were defined as int in the natives db and thus also in the natives.h. But they are actually floats, not ints and I've already changed it in the db.

 

It may very well be compiler dependant, but on my system ints are 4 byte while floats are 8 byte types. So I was passing 24 bytes while only 12 where expected as per the header. Don't know what the invoke call does with that but it obviously caused trouble.

 

But now it finally all works :lol: .

Float is always 4 bytes, even on 64 bit.

The size of int depends on your compiler, on 64bit VS (I assume you're using it) the type "int" is 64bit too - However that may not be true on other compilers.

Share this post


Link to post
Share on other sites
BenBaron

Thanks for the clarification, Freakyy,

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.
Note: Your post will require moderator approval before it will be visible.

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.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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