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. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    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

Sign in to follow this  
hgstGTA

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

Recommended Posts

hgstGTA

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

Share this post


Link to post
Share on other sites
hgstGTA

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

Share this post


Link to post
Share on other sites
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.

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.

Sign in to follow this  

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