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. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

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

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. 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 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 Mods
    10. GTA Vice City

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

      1. Guides & Strategies
      2. Help & Support
      3. GTA 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

KelFlakes

[.NET] Make vehicles avoiding objects

Recommended Posts

KelFlakes

Hi all, 

 

First of all, I'm new to this forum, not a beginner at all of modding or programming because in the past I modded GTA IV before and I am a fulltime webdeveloper. Despite the fact I'm sometimes a bit 'playing' with coding in GTA 5 I still have some questions. But one of these (on-topic) question is: 

 

How do I make vehicles (drivers) avoid spawned objects on the road? 

 

First, I have thought about various ways to implement some AI like code which checks if a object is near to the driver and let the driver avoid it by tasks etc. But I thought there must be a setting like a boolean or something else which drivers will avoid spawned props. 

 

For example:

 

  • Spawned cars will be avoided. Drivers are stopping in front of the car or will drive around it. That's the behaviour I would like to give drivers for props/objects as well. 
  • Spawned props like a road barrier/block spawned ingame with my own written script will not be avoided. Drivers will drive into it and collide with the barriers. But spawned props (e.g. barriers) spawned from scripts like Map Editor or Menyoo will be avoided by drivers. That's weird, so I thought there must be some intelligence which drivers will avoid props. 

 

 

So, does anyone know if there is already some usable intelligence built-in? Or how the map editor makes drivers avoid it? Or if you have any other ideas to make drivers avoid it you can write it down.  

Any help will be appreciated :) 

 

Tonight when I'm at home I could upload my code, but it's not very special just the basic simple spawn code (world.CreateProp something like that out of my head just 2 lines of code).

 

Thanks!

 

Share this post


Link to post
Share on other sites
KelFlakes

@Jitnaught Thank you. I already did. Couldn't find something relevent. Watched a YouTube video which you can see what I mean. He spawns some cones/barriers which drivers are following the modified route or drive around it: 

Actually, he is using Menyoo trainer for it and not map-editor. Menyoo is ASI plugin (probably c++ written) and I don't know how to decompile it. Also, my c++ skills aren't that much good. 

 

Share this post


Link to post
Share on other sites
InfamousSabre

PATHFIND::ADD_NAVMESH_BLOCKING_OBJECT

Share this post


Link to post
Share on other sites
KelFlakes

@InfamousSabre Thank you! I think that's worth trying. Although I really don't know what this function does because there isn't a documentation or descripion of this function and Alexander Blade's website, only a list of functions. 

 

Any ADD_NAVMESH_BLOCKING_OBJECT(float p0, float p1, float p2, float p3,
  float p4, float p5, float p6, BOOL p7, Any p8)
// 0xFCD5C8E06E502F5A 0x2952BA56
 
I assume that "Any" is the object or prop in this case, though I don't know what the definition of all these other floats are. I can just try them out. 
 
Any differences with this code?: 
void ADD_NAVMESH_REQUIRED_REGION(float x, float y, float radius)
// 0x387EAD7EE42F6685 0x12B086EA
 


Share this post


Link to post
Share on other sites
Guest
2 hours ago, KelFlakes said:

Thank you! I think that's worth trying. Although I really don't know what this function does because there isn't a documentation or descripion of this function and Alexander Blade's website, only a list of functions. 

You're probably going to have to play the "Hunt the native" game in the decompiled scripts. If you download the decompiled scripts and get a decent text-searcher, you can find where the natives are used in the scripts. The parameters passed might give you a better idea of how the game uses the native and what it requires.

 

So like in prologue1.c, it has this:

iLocal_91 = PATHFIND::ADD_NAVMESH_BLOCKING_OBJECT(3551.478f, -4690.381f, 112.995f, 15f, 15f, 6f, 0.017f, 0, 7);

From that, I would say the first three parameters are coordinates, the next three are possibly length, width and height, with the next being rotation/heading maybe. The last two always seem to be 0 & 7.

 

What I usually do in those instances, is use some debug code to place markers at the locations and draw a box that matches the length, width, height and rotation. When you can visually see what the parameters create in the world, you can get an idea of what they are affecting.

Edited by Guest

Share this post


Link to post
Share on other sites
KelFlakes

@LeeC2202: Thanks for your help. At the moment I'm at work, so will try this later. I think it's a good idea to create a visible box with the same parameters. How do I assign an object/prop to the native function so the right prop get's recognized as a navmesh blocking object? Just to assign the prop variable with the native function next to it I think? 

 

Like:

 

propBarrier = PATHFIND::ADD_NAVMESH_BLOCKING_OBJECT(3551.478f, -4690.381f, 112.995f, 15f, 15f, 6f, 0.017f, 0, 7);

Share this post


Link to post
Share on other sites
Guest
1 hour ago, KelFlakes said:

@LeeC2202: Thanks for your help. At the moment I'm at work, so will try this later. I think it's a good idea to create a visible box with the same parameters. How do I assign an object/prop to the native function so the right prop get's recognized as a navmesh blocking object? Just to assign the prop variable with the native function next to it I think? 

 

Like:

 

propBarrier = PATHFIND::ADD_NAVMESH_BLOCKING_OBJECT(3551.478f, -4690.381f, 112.995f, 15f, 15f, 6f, 0.017f, 0, 7);

No, you can't assign property types, to natives that don't return that type of object. The native seems to return an int, which is probably an ID for that object. It can be updated or removed and I suspect that ID is how you reference it.

 

In theory, you would create a prop, then create the NAVMESH object based on the prop location and dimensions. However, unless Menyoo lets you set specific flags that define the prop as navmesh blocking, I would think it unlikely it uses that technique. Menyoo maps can be converted to YMap, with what I presume are the same results, which means things are then out of Menyoo's control. I suspect those blocking objects are used to temporarily block access to areas you would normally be able to get to, or to control access based on mission progress.

 

Perhaps the key is the type of prop that is placed into the traffic flow, maybe certain objects contain navmesh blocking flags as part of their ytyp definition data. I have just placed the same prop used in that video (prop_barrier_wat_03a) with Map Editor and cars drove around them, and not into them. So those props definitely have properties that cause cars to avoid them.

Edited by Guest

Share this post


Link to post
Share on other sites
InfamousSabre

@KelFlakes I took a look at how it was used in the scripts, and my guess is

PATHFIND::ADD_NAVMESH_BLOCKING_OBJECT(positionX, positionY, positionZ, sizeX, sizeY, sizeZ, unkFloat, unkBool, Flags);

Share this post


Link to post
Share on other sites
Guest

Okay, I created a small map in Map Editor, got it to output a script to generate that map and this is the end result.

 

This is the code Map Editor generated for those few props.

using System;
using System.Linq;
using System.Collections.Generic;
using GTA;
using GTA.Math;
using GTA.Native;

public class MapEditorGeneratedMap : GTA.Script
{
    public MapEditorGeneratedMap()
    {
        List<Prop> Props = new List<Prop>();
        bool Initialized = false;
        base.Tick += delegate (object sender, EventArgs args)
        {
            if (!Initialized)
            {
                /* PROPS */
               Props.Add(GTA.World.CreateProp(new Model(2080595106), new GTA.Math.Vector3(1914.344f, 3691.948f, 31.77539f), new GTA.Math.Vector3(0f, 0f, 0f), false, false));
               Props.Add(GTA.World.CreateProp(new Model(2080595106), new GTA.Math.Vector3(1915.053f, 3693.918f, 31.7624f), new GTA.Math.Vector3(0f, 0f, 0f), false, false));
               Props.Add(GTA.World.CreateProp(new Model(2080595106), new GTA.Math.Vector3(1916.62f, 3696.176f, 31.7381f), new GTA.Math.Vector3(0f, 0f, 0f), false, false));
               Props.Add(GTA.World.CreateProp(new Model(2080595106), new GTA.Math.Vector3(1919.221f, 3696.725f, 31.69437f), new GTA.Math.Vector3(0f, 0f, 0f), false, false));
               Props.Add(GTA.World.CreateProp(new Model(2080595106), new GTA.Math.Vector3(1921.63f, 3696.514f, 31.65773f), new GTA.Math.Vector3(0f, 0f, 0f), false, false));
                Initialized = true;
            }
            Prop returnedProp;
        };
    }
}

Edit: This is an interesting use of that blocking native.

iLocal_438[0] = PATHFIND::ADD_NAVMESH_BLOCKING_OBJECT(ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true), 0.75f, 0.75f, 1f, ((ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID()) / 360f) * 6.28f), 0, 7);

It creates one around trhe player, in the opposite direction the player is facing... (I think)

Edited by Guest

Share this post


Link to post
Share on other sites
KelFlakes

@LeeC2202: Well, looks good. Looks like it's basically already implemented and just need to use some extra parameters when spawning a prop. Still haven't got time to test it, I'm so busy these days.. And Windows needs to be restored/re-installed damn.. Will reply on you when I tried it myself :)

Share this post


Link to post
Share on other sites
Jitnaught

There aren't any special natives used in the script Lee posted, and I tested the script myself and confirmed the traffic goes around the objects. I even tested changing the "dynamic" parameter of the CreateProp function from false to true, with no difference (traffic still goes around objects).

 

This is the code SHV.NET uses when calling the CreateProp function:

Native::Function::Call<Prop ^>(Native::Hash::CREATE_OBJECT, model.Hash, position.X, position.Y, position.Z, 1, 1, dynamic);

https://github.com/crosire/scripthookvdotnet/blob/dev_v2/source/scripting/World.cpp#L929

 

And this is the reference for the CREATE_OBJECT native:

Object CREATE_OBJECT(Object modelHash, float x, float y, float z, BOOL isNetwork, BOOL thisScriptCheck, BOOL dynamic)

 

Objects spawned using Simple Trainer are avoided as well. Simple Trainer also doesn't use any special natives for it.

Edited by Jitnaught
info about simple trainer

Share this post


Link to post
Share on other sites
KelFlakes

@LeeC2202 Well, I tested it by creating my own script and I found out that the prop avoidance is basically already built-in on specific props. So, when I spawn "prop_barrier_wat_03b" drivers will avoid it by default. However, when spawning another barrier like "prop_barier_conc_05b" a concrete barrier wall, drivers will crash into it. So I think the AI of avoiding is built-in on specific props only. 

Share this post


Link to post
Share on other sites
Guest

@KelFlakesYeah, that was what prompted me to say:

Quote

Perhaps the key is the type of prop that is placed into the traffic flow, maybe certain objects contain navmesh blocking flags as part of their ytyp definition data. I have just placed the same prop used in that video (prop_barrier_wat_03a) with Map Editor and cars drove around them, and not into them. So those props definitely have properties that cause cars to avoid them.

I pulled a few props at random from a few ytyp files and they seem to have a bit-flag in common. If you notice this list:

prop_barrier_wat_03a		537001984 = 100000000000100000000000000000
prop_generator_01a		549584896 = 100000110000100000000000000000
prop_conc_blocks01c		537001984 = 100000000000100000000000000000
Prop_BarrierCrash_02		537001984 = 100000000000100000000000000000
Prop_Beware_Dog_Sign		549584896 = 100000110000100000000000000000
Prop_fountain2			536870912 = 100000000000000000000000000000
Prop_Paper_Ball			805437440 = 110000000000100000000000000000
Prop_Barier_Conc_05b		671219744 = 101000000000100000000000100000
Prop_Barier_Conc_05c		671219712 = 101000000000100000000000000000
Prop_logFile_05			671088640 = 101000000000000000000000000000

The bottom 3 all have the same bit set, bit 27. One of those is another of the concrete barriers and one is a log file (I presume wooden logs). The other ones don't have that bit set and at least one of those was the prop the cars drove around. So maybe that flag has something to do with telling the cars to go around it.

 

An interesting test would be to get the rpf that has that data in it, dump it into your mods folder and change the bit flags for the concrete blocks to also not have that bit set and then see if the cars avoid them or not.

 

Edit: Just noticed as well, prop_barrier_wat_03a is a yft file and Prop_Barier_Conc_05c is a ydr file. Don't know if that's another factor that affects anything. Oh god, how did I miss this... Prop_Barier_Conc_05b also has bit 5 set and nothng else in that list does.

 

Update: I tried setting Prop_Barier_Conc_05b to have the same flags as prop_barrier_wat_03a and the cars tried to go around it but it was almost as if the prop was wider than the amount of solid-object the AI looks at, to get round objects. It missed the middle of the prop but drove into the end, as if it expected the end to not be there. It did the same thing with those corrugated crash barriers as well, it avoided the middle and hit the end. And once it had hit the end, it kep driving into it.

Edited by Guest

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.