Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

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

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    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. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. 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. Red Dead Redemption 2

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

    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
    1. Announcements

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

Help, How to determine if Ped can see other Ped with no obstacles in t


hgstGTA
 Share

Recommended Posts

Hi,

 

I am trying for the past few days now to come with code to see if 1 Ped can see another Ped without having any obstacles in the way.

I could not find a single way so far to achieve this. What i am basically making is trying to shoot a bullet to the other Ped if I can see him and if I

have determined he is an enemy.

 

 

First I have a method to determine if the ped is a player hater:

 

BOOL doesPedHatePlayer(Ped player, Ped iPed){BOOL COP = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("COP");BOOL CRIMINAL = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("CRIMINAL");BOOL DEALER = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("DEALER");BOOL ARMY = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("ARMY");BOOL SWAT = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("SWAT");BOOL THIEF = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("THIEF");BOOL PRISONGUARD = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("PRISONGUARD");BOOL SECURITY_GUARD = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("SECURITY_GUARD");BOOL PRIVATE_SECURITY = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("PRIVATE_SECURITY");BOOL HATES_PLAYER = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("HATES_PLAYER");BOOL GUARD_DOG = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("GUARD_DOG");BOOL AGGRESSIVE_INVESTIGATE = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AGGRESSIVE_INVESTIGATE");BOOL GANG_1 = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("GANG_1");BOOL GANG_2 = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("GANG_2");BOOL GANG_9 = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("GANG_9");BOOL GANG_10 = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("GANG_10");BOOL AMBIENT_GANG_LOST = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_LOST");BOOL AMBIENT_GANG_MEXICAN = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_MEXICAN");BOOL AMBIENT_GANG_FAMILY = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_FAMILY");BOOL AMBIENT_GANG_BALLAS = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_BALLAS");BOOL AMBIENT_GANG_MARABUNTE = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_MARABUNTE");BOOL AMBIENT_GANG_CULT = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_CULT");BOOL AMBIENT_GANG_SALVA = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_SALVA");BOOL AMBIENT_GANG_WEICHENG = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_WEICHENG");BOOL AMBIENT_GANG_HILLBILLY = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("AMBIENT_GANG_HILLBILLY");BOOL PRISONER = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("PRISONER");BOOL DOMESTIC_ANIMAL = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("DOMESTIC_ANIMAL");BOOL WILD_ANIMAL = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("WILD_ANIMAL");BOOL DEER = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("DEER");BOOL COUGAR = PED::GET_PED_RELATIONSHIP_GROUP_HASH(iPed) == GAMEPLAY::GET_HASH_KEY("COUGAR");BOOL HATE = PED::GET_RELATIONSHIP_BETWEEN_PEDS(player,iPed) == 5;BOOL DAMAGED = ENTITY::HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY(player,iPed,TRUE);return  HATE    || DAMAGED   || COP || CRIMINAL|| DEALER || ARMY || SWAT || THIEF || PRISONGUARD|| SECURITY_GUARD || PRIVATE_SECURITY|| HATES_PLAYER || GUARD_DOG || AGGRESSIVE_INVESTIGATE || GANG_1 || GANG_2 || GANG_9 || GANG_10 || AMBIENT_GANG_LOST || AMBIENT_GANG_MEXICAN || AMBIENT_GANG_FAMILY || AMBIENT_GANG_BALLAS || AMBIENT_GANG_MARABUNTE || AMBIENT_GANG_CULT || AMBIENT_GANG_SALVA|| AMBIENT_GANG_WEICHENG || AMBIENT_GANG_HILLBILLY|| PRISONER || DOMESTIC_ANIMAL || WILD_ANIMAL || DEER || COUGAR;}
And then some more code to shoot a bullet to the player hater (or blow up vehicle):
if (ENTITY::DOES_ENTITY_EXIST(iPed) && !ENTITY::IS_ENTITY_DEAD(iPed)){Vector3 from = ENTITY::GET_ENTITY_COORDS(playerPed, false);Vector3 to = ENTITY::GET_ENTITY_COORDS(iPed, false);BOOL networkped = isNetworkPed(iPed);BOOL myself = playerPed == iPed;if (!myself & !networkped) {BOOL requiredformission = ENTITY::IS_ENTITY_A_MISSION_ENTITY(iPed);BOOL invehicle = PED::IS_PED_IN_ANY_VEHICLE(iPed,TRUE);BOOL inheli = PED::IS_PED_IN_ANY_HELI(iPed);BOOL inplane = PED::IS_PED_IN_ANY_PLANE(iPed);BOOL enemy = doesPedHatePlayer(playerPed,iPed);if (!requiredformission & enemy) {if (inheli || inplane || invehicle){FIRE::ADD_EXPLOSION(to.x, to.y, to.z, 25, 1000, TRUE, FALSE, 0);} else {GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(from.x,from.y,to.z+1,to.x,to.y,to.z,400,TRUE,Heavy_Sniper_Rifle,playerPed,TRUE,TRUE,10);GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(to.x+50,from.y,to.z+1,to.x,to.y,to.z,400,TRUE,Heavy_Sniper_Rifle,playerPed,TRUE,TRUE,10);GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(to.x-50,from.y,to.z+1,to.x,to.y,to.z,400,TRUE,Heavy_Sniper_Rifle,playerPed,TRUE,TRUE,10);GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(from.x,to.y+50,to.z+1,to.x,to.y,to.z,400,TRUE,Heavy_Sniper_Rifle,playerPed,TRUE,TRUE,10);GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(from.x,to.y-50,to.z+1,to.x,to.y,to.z,400,TRUE,Heavy_Sniper_Rifle,playerPed,TRUE,TRUE,10);}     }     }

As you can see I am using all kinds of coords using the other Ped's X,Y,Z to fire a bullet because the other Ped is behind walls, props, vehicles etc.

 

So how do I solve this ?

 

Feel free to use my code and correct me when i am wrong.

Edited by hgstGTA
Link to comment
Share on other sites

So will reply to myself with more information:

 

What i want to achieve is to check whether or not having two coordinates

 

If they can see each other.... (so no obstacles are in the way : cars/walls/other peds/etc.)

 

 

The closest functions i thought could be used were:

 

PATHFIND::IS_POINT_OBSCURED_BY_A_MISSION_ENTITY  //this is only for vehicles in the way ?CAM::IS_SPHERE_VISIBLE
They seem not to be working correctly , or I don't understand them,
Then there are other functions which I quickly scanned by looking at the decompiled C files of Alexander Blade :
GAMEPLAY::ABSFAI::GET_NAVMESH_ROUTE_RESULTSYSTEM::VDIST2AI::TASK_LOOK_AT_ENTITYAI::TASK_AIM_GUN_AT_COORDAI::TASK_SHOOT_AT_COORDAI::TASK_SHOOT_AT_ENTITYPATHFIND::REMOVE_NAVMESH_REQUIRED_REGIONSGAMEPLAY::GET_HEADING_FROM_VECTOR_2DINTERIOR::IS_VALID_INTERIOR(INTERIOR::GET_INTERIOR_AT_COORDS(v_D))OBJECT::IS_POINT_IN_ANGLED_AREAGAMEPLAY::GET_GROUND_Z_FOR_3D_COORDPATHFIND::IS_POINT_OBSCURED_BY_A_MISSION_ENTITY  //this is only for vehicles in the way ?CAM::IS_SPHERE_VISIBLE

But my goal is to first determine whether or not the two PED's can see each other BEFORE they shoot. I am sure somewhere out there someone knows how...

Edited by hgstGTA
Link to comment
Share on other sites

  • 2 weeks later...
Prof_Farnsworth

So will reply to myself with more information:

 

What i want to achieve is to check whether or not having two coordinates

 

If they can see each other.... (so no obstacles are in the way : cars/walls/other peds/etc.)

 

 

The closest functions i thought could be used were:

 

PATHFIND::IS_POINT_OBSCURED_BY_A_MISSION_ENTITY  //this is only for vehicles in the way ?CAM::IS_SPHERE_VISIBLE
They seem not to be working correctly , or I don't understand them,
Then there are other functions which I quickly scanned by looking at the decompiled C files of Alexander Blade :
GAMEPLAY::ABSFAI::GET_NAVMESH_ROUTE_RESULTSYSTEM::VDIST2AI::TASK_LOOK_AT_ENTITYAI::TASK_AIM_GUN_AT_COORDAI::TASK_SHOOT_AT_COORDAI::TASK_SHOOT_AT_ENTITYPATHFIND::REMOVE_NAVMESH_REQUIRED_REGIONSGAMEPLAY::GET_HEADING_FROM_VECTOR_2DINTERIOR::IS_VALID_INTERIOR(INTERIOR::GET_INTERIOR_AT_COORDS(v_D))OBJECT::IS_POINT_IN_ANGLED_AREAGAMEPLAY::GET_GROUND_Z_FOR_3D_COORDPATHFIND::IS_POINT_OBSCURED_BY_A_MISSION_ENTITY  //this is only for vehicles in the way ?CAM::IS_SPHERE_VISIBLE

But my goal is to first determine whether or not the two PED's can see each other BEFORE they shoot. I am sure somewhere out there someone knows how...

I know it is a late reply but you could try the following:

static BOOL HAS_ENTITY_CLEAR_LOS_TO_ENTITY(Any p0, Any p1, Any p2) { return invoke<BOOL>(0xFCDFF7B72D23A1AC, p0, p1, p2); } // 0xFCDFF7B72D23A1AC 0x53576FA7    static BOOL HAS_ENTITY_CLEAR_LOS_TO_ENTITY_IN_FRONT(Any p0, Any p1) { return invoke<BOOL>(0x0267D00AF114F17A, p0, p1); } // 0x0267D00AF114F17A 0x210D87C8

I haven't tested this but I believe it refers to line of sight between entities.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 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.