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

    1. GTANet.com

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

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

    1. Red Dead Redemption 2

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

    1. Grand Theft Auto Series

    2. GTA 6

      1. St Andrews Cathedral
    3. GTA V

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

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    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. DYOM
      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
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

patsanchique

аim lосk on ped's bone

Recommended Posts

patsanchique
Posted (edited)

Hi, i'm trying to lock аim on ped's head in specified fov, but unfortunately all i getting is weird twitchy moves. Would be very grateful for any help.

 Entity ent;
			float dx, dy, fov, max_fov = 360.f;
			int resolution_x, resolution_y;
			GRAPHICS::GET_SCREEN_RESOLUTION(&resolution_x, &resolution_y);
			if (PLAYER::GET_ENTITY_PLAYER_IS_FREE_AIMING_AT(PLAYER::PLAYER_ID(), &ent))
			{
				if (ENTITY::IS_ENTITY_A_PED(ent))
				{
					if (ENTITY::GET_ENTITY_HEALTH(ent) != 0)
					{
						int bone = ENTITY::GET_ENTITY_BONE_INDEX_BY_NAME(ent, "SKEL_Head");
						Vector3 dst = ENTITY::GET_WORLD_POSITION_OF_ENTITY_BONE(ent, bone);
						Vector3 src = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), 1, 1);
						float distance = MISC::GET_DISTANCE_BETWEEN_COORDS(src.x, src.y, src.z, dst.x, dst.y, dst.z, TRUE);
						auto angle = MISC::GET_ANGLE_BETWEEN_2D_VECTORS(src.x, src.y, dst.x, dst.y);

						if (distance < 100.0f)
						{
							float screen_x, screen_y;
							GRAPHICS::GET_SCREEN_COORD_FROM_WORLD_COORD(dst.x, dst.y, dst.z, &screen_x, &screen_y);

							float x_distance = screen_x - 0.5f;
							float y_distance = screen_y - 0.5f;
							fov = sqrt(x_distance * x_distance + y_distance * y_distance);


							if (ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY(PLAYER::PLAYER_PED_ID(), ent, 17)
								&& fov < max_fov
								&& !PED::IS_PED_DEAD_OR_DYING(ent, false))
							{

								dx = ((screen_x - 0.5f) * (resolution_x / 2.f)) / angle;
								dy = ((screen_y - 0.5f) * (resolution_y / 2.f)) / angle;
								mouse_event(MOUSEEVENTF_MOVE, dx, dy, 0, 0);
							}
						}
					}
				}
			}
 
Edited by patsanchique
correction

Share this post


Link to post
Share on other sites
LeeC22

Just a heads up... you might not get any replies to this until you post some existing code. You're asking a question that is usually related to online "aimbot" behaviour, so you might need to show enough code to convince people that you're doing this in offline mode only. The forum has rules that don't allow discussion of online modding, so people might be hesitant to answer based on that.

 

It also helps people to see where the code might be going wrong if you post the code that isn't working.

 

Just to clarify... I'm not saying you're modding online, simply that your questions is common for people that are.

Share this post


Link to post
Share on other sites
patsanchique
4 hours ago, LeeC22 said:

Just a heads up... you might not get any replies to this until you post some existing code. You're asking a question that is usually related to online "aimbot" behaviour, so you might need to show enough code to convince people that you're doing this in offline mode only. The forum has rules that don't allow discussion of online modding, so people might be hesitant to answer based on that.

 

It also helps people to see where the code might be going wrong if you post the code that isn't working.

 

Just to clarify... I'm not saying you're modding online, simply that your questions is common for people that are.

i added my code, anyway it's broken, i think there is problem with calculations
this is for story mode, it has to be part of my mod, can you please help me? all i trying to figure out is how to conver world to screen and point to this x/y coord but i'm stuck with calculations

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)
int bone = ENTITY::GET_ENTITY_BONE_INDEX_BY_NAME(ent, "SKEL_Head");

That native doesn't work on that bone name. I did some research on that native in this thread, there might be something of use in there.

 

 

Edited by LeeC22

Share this post


Link to post
Share on other sites
patsanchique
1 minute ago, LeeC22 said:

That native doesn't work on that bone name. I did some research on that native in this thread, there might be something of use in here.

 

hmm interesting thank you, i'll test this but i'm still thinking the problem is in calculations

 

Share this post


Link to post
Share on other sites
patsanchique
54 minutes ago, LeeC22 said:
int bone = ENTITY::GET_ENTITY_BONE_INDEX_BY_NAME(ent, "SKEL_Head");

That native doesn't work on that bone name. I did some research on that native in this thread, there might be something of use in there.

 

 

i  tried this and still have same issue, bone is detects, something is wrong with coords

Share this post


Link to post
Share on other sites
LeeC22
1 hour ago, patsanchique said:

i  tried this and still have same issue, bone is detects, something is wrong with coords

I don't really understand the maths involved so I can't help with that side of things I am afraid.

Share this post


Link to post
Share on other sites
patsanchique
7 minutes ago, LeeC22 said:

I don't really understand the maths involved so I can't help with that side of things I am afraid.

anyway thank you for advices
this is world to screen coordinates of ped but they didnt work in supposed way for some reason, all what i'm basically trying to do is get 2D coordinates of my ped and aim at them

 

Share this post


Link to post
Share on other sites
LeeC22

Have you tried using the Native TASK_AIM_GUN_AT_COORD to see if you can assign a task to the player to adjust their aim?

 

You might have to disable player control, assign the task and then re-enable control once the task is complete. I don't know if it will work but if it does, it's a lot simpler that trying to adjust the aim based on 2D coordinates.

Share this post


Link to post
Share on other sites
patsanchique
Posted (edited)
11 hours ago, LeeC22 said:

Have you tried using the Native TASK_AIM_GUN_AT_COORD to see if you can assign a task to the player to adjust their aim?

 

You might have to disable player control, assign the task and then re-enable control once the task is complete. I don't know if it will work but if it does, it's a lot simpler that trying to adjust the aim based on 2D coordinates.

yes, i tried this as well it's sort of working and player is aiming but it's only affecting my model, my mouse position and camera angle didn't changing maybe you know how to also change them?

Edited by patsanchique

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)
7 hours ago, patsanchique said:

yes, i tried this as well it's sort of working and player is aiming but it's only affecting my model, my mouse position and camera angle didn't changing maybe you know how to also change them?

The only natives I have used on the gameplay camera are SET versions of these, maybe you can do what you want with them. I have only set RELATIVE values, not the RAW ones.

static float GET_GAMEPLAY_CAM_RELATIVE_HEADING() { return invoke<float>(0x743607648ADD4587); } // 0x743607648ADD4587 0xCAF839C2
static void SET_GAMEPLAY_CAM_RELATIVE_HEADING(float heading) { invoke<Void>(0xB4EC2312F4E5B1F1, heading); } // 0xB4EC2312F4E5B1F1 0x20C6217C
static float GET_GAMEPLAY_CAM_RELATIVE_PITCH() { return invoke<float>(0x3A6867B4845BEDA2); } // 0x3A6867B4845BEDA2 0xFC5A4946
static void SET_GAMEPLAY_CAM_RELATIVE_PITCH(float x, float Value2) { invoke<Void>(0x6D0858B8EDFD2B7D, x, Value2); } // 0x6D0858B8EDFD2B7D 0x6381B963
static void _SET_GAMEPLAY_CAM_RAW_YAW(float yaw) { invoke<Void>(0x103991D4A307D472, yaw); } // 0x103991D4A307D472
static void _SET_GAMEPLAY_CAM_RAW_PITCH(float pitch) { invoke<Void>(0x759E13EBC1C15C5A, pitch); } // 0x759E13EBC1C15C5A

I am not sure if the gameplay camera is used in First-Person mode though, it might be a custom camera like they use inside vehicles in FPV mode.

 

Edit: Just did a small test. When you are aiming, the Gameplay Camera Relative Rotation is always 0.0f and that's in all camera modes. So if you make the player's heading match the direction to the selected Ped, that should get the horizontal part of the problem solved. Then you just need to work out the relative pitch... which I suspect you will have no problem calculating.

Edited by LeeC22

Share this post


Link to post
Share on other sites
patsanchique
8 hours ago, LeeC22 said:

The only natives I have used on the gameplay camera are SET versions of these, maybe you can do what you want with them. I have only set RELATIVE values, not the RAW ones.

static float GET_GAMEPLAY_CAM_RELATIVE_HEADING() { return invoke<float>(0x743607648ADD4587); } // 0x743607648ADD4587 0xCAF839C2
static void SET_GAMEPLAY_CAM_RELATIVE_HEADING(float heading) { invoke<Void>(0xB4EC2312F4E5B1F1, heading); } // 0xB4EC2312F4E5B1F1 0x20C6217C
static float GET_GAMEPLAY_CAM_RELATIVE_PITCH() { return invoke<float>(0x3A6867B4845BEDA2); } // 0x3A6867B4845BEDA2 0xFC5A4946
static void SET_GAMEPLAY_CAM_RELATIVE_PITCH(float x, float Value2) { invoke<Void>(0x6D0858B8EDFD2B7D, x, Value2); } // 0x6D0858B8EDFD2B7D 0x6381B963
static void _SET_GAMEPLAY_CAM_RAW_YAW(float yaw) { invoke<Void>(0x103991D4A307D472, yaw); } // 0x103991D4A307D472
static void _SET_GAMEPLAY_CAM_RAW_PITCH(float pitch) { invoke<Void>(0x759E13EBC1C15C5A, pitch); } // 0x759E13EBC1C15C5A

I am not sure if the gameplay camera is used in First-Person mode though, it might be a custom camera like they use inside vehicles in FPV mode.

 

Edit: Just did a small test. When you are aiming, the Gameplay Camera Relative Rotation is always 0.0f and that's in all camera modes. So if you make the player's heading match the direction to the selected Ped, that should get the horizontal part of the problem solved. Then you just need to work out the relative pitch... which I suspect you will have no problem calculating.

wow nice find, big thanks to you

i'm 100% sure it will be useful in my case

  • Like 1

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.


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