Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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

get closest actor camera pointing at


gokuta
 Share

Recommended Posts

this opcode:

0AB5: store_actor $PLAYER_ACTOR closest_vehicle_to [email protected] closest_ped_to [email protected]

gives closest actor. Not exactly what I need. How do I get actor handle, which is closest to me, but in a specific direction where I'm looking at. How to do that... need massive help on this! Any help much appreciated.

 

Most certainly will us plugin-sdk for this. Need to get camera position and camera looking-at position. Also I will need to loop through all peds and check their positions. How do I do it? So... I seriously need some help, no tutorials could be found regarding this.

Edited by gokuta
Link to comment
Share on other sites

alright guys, problem almost solved. Still one problem persists. Alright, so I loop through all the peds and I want to skip player character (that is myself as a player). How do I check whether character is me? For some reason `ped->IsPlayer()` returns TRUE for characters, that are not me as well.

Link to comment
Share on other sites

oh yas yas yaaas, one more question. How do I get camera position and vector, where camera is looking at? Cuz me tried these two `CVector m_vecAimingTargetCoors;` and `CVector m_vecGameCamPos;` but I get nonsensical results. Well, I definitely do not know what parameters meen what. No tutorials available. Anybody knows?

Link to comment
Share on other sites

ahh, yess yes yes... and one more question. So as far as I know (and I know nothing), I should use CCamera class to retrieve camera position. And I should not use CCam class to retrieve camera position. My opinion is based on nothing, because I know nothing. And I find absolutely nothing on the internet. No documentation, nothing at all. Any help? Which class should I use?

Edited by gokuta
Link to comment
Share on other sites

You might wanna use these scm commands:

GET_ACTIVE_CAMERA_POINT_AT  //  opcode_068E
IS_CHAR_ON_SCREEN   //  opcode_02CB

 

The next c++ code will kill any NPC visible on screen and close to a player within a radius of 4.0 or less:

auto playa = FindPlayerPed();
for (int i = 0; i < CPools::ms_pPedPool->m_nSize; i++) {
    auto ped = CPools::ms_pPedPool->GetAt(i);
    if (ped && playa) {
        if (ped->m_nPedType > 3) { //    check ePedType  GET_PED_TYPE
            CVector pedPosition = ped->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f));      //  GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS
            CVector playaPosition = playa->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f));  //  GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS
            float radius3D = sqrt(powf(playaPosition.x - pedPosition.x, 2) + powf(playaPosition.y - pedPosition.y, 2) + powf(playaPosition.z - pedPosition.z, 2));
            if (ped->GetIsOnScreen() && radius3D <= 4.0f) {
                ped->m_fHealth = 0.0;
            }
        }
    }
}

Link to comment
Share on other sites

ok, thanks. helped a bit. scm stuff irrelevant. still not clear how do I get camera pos

Edited by gokuta
Link to comment
Share on other sites

068D: and 068E: only work for the default camera

068D: get_camera_position_to [email protected] [email protected] [email protected]
068E: get_camera_target_point_to [email protected] [email protected] [email protected]


camera_position is placed ca. 1 or 2 units behind player_actor, depending to the cam adjustment by key V
camera_target_point is placed between camera_position and player_actor

to get a view point anywhere in view direction needs needs to do some calcutions
test the script below to understand
key_press Backspace shows a searchlight in view direction for 2 seconds
it requires to give a target point, which is calculated 30 units infront

{$CLEO .cs}
:AIM_LIGHT_BY_CAMERA
thread 'AIMLIHT'

while true
    wait 0
    if 
        0256:   player $PLAYER_CHAR defined
    then
        if and
            0AB0:   key_pressed 8//----------------------------key = Backspace
            044B:   actor $PLAYER_ACTOR on_foot
            84AD:  not actor $PLAYER_ACTOR in_water
        then            
            068D: get_camera_position_to 1@ 2@ 3@
            068E: get_camera_target_point_to 7@ 8@ 9@  
            0087: 11@ = 7@ // (float) 
            0087: 12@ = 8@ // (float) 
            0087: 13@ = 9@ // (float)            
            0087: 21@ = 7@ // (float) 
            0087: 22@ = 8@ // (float) 
            0087: 23@ = 9@ // (float) 
            0063: 21@ -= 1@ // (float) 
            0063: 22@ -= 2@ // (float) 
            0063: 23@ -= 3@ // (float) 
            0013: 21@ *= 30.0 
            0013: 22@ *= 30.0 
            0013: 23@ *= 30.0             
            005B: 7@ += 21@ // (float) 
            005B: 8@ += 22@ // (float) 
            005B: 9@ += 23@ // (float)                       
            06B1: 31@ = create_searchlight_at 11@ 12@ 13@ radius 0.1 target 7@ 8@ 9@ radius 0.2 
            wait 2000                        
            06B2: destroy_searchlight 31@
        end
    end
end

 

Link to comment
Share on other sites

gosh... I need help with plugin-sdk. I can do all the calculations, no problems. The problem is I have no idead how to GET the frickin' simpliest thing - camera position. I just need camera position, that's all I need. And where it's pointing. These opcodes:

068D: get_camera_position_to [email protected] [email protected] [email protected]
068E: get_camera_target_point_to [email protected] [email protected] [email protected] 

I need these exact things, just in plugin-sdk

 

Edited by gokuta
Link to comment
Share on other sites

37 minutes ago, gokuta said:
068D: get_camera_position_to [email protected] [email protected] [email protected]
068E: get_camera_target_point_to [email protected] [email protected] [email protected] 

I need these exact things, just in plugin-sdk

 

 

//   068D: get_camera_position_to [email protected] [email protected] [email protected]
float camX = TheCamera.m_aCams->m_vecSource.x;
float camY = TheCamera.m_aCams->m_vecSource.y;
float camZ = TheCamera.m_aCams->m_vecSource.z;
         
//  068E: get_camera_target_point_to [email protected] [email protected] [email protected]
float camTargetX = camX + TheCamera.m_aCams->m_vecFront.x;
float camTargetY = camY + TheCamera.m_aCams->m_vecFront.y;
float camTargetZ = camZ + TheCamera.m_aCams->m_vecFront.z;

Link to comment
Share on other sites

yaas! that is basically it. Thanks, Jack, very helpful. to find the appropriate distance basically I need to calculate the magnitude (normalized) of vector cross product

Edited by gokuta
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.