patsanchique Posted July 15, 2020 Share Posted July 15, 2020 (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 July 15, 2020 by patsanchique correction Link to comment Share on other sites More sharing options...
LeeC22 Posted July 15, 2020 Share Posted July 15, 2020 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. Link to comment Share on other sites More sharing options...
patsanchique Posted July 15, 2020 Author Share Posted July 15, 2020 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 Link to comment Share on other sites More sharing options...
LeeC22 Posted July 15, 2020 Share Posted July 15, 2020 (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 July 15, 2020 by LeeC22 Link to comment Share on other sites More sharing options...
patsanchique Posted July 15, 2020 Author Share Posted July 15, 2020 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 Link to comment Share on other sites More sharing options...
patsanchique Posted July 15, 2020 Author Share Posted July 15, 2020 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 Link to comment Share on other sites More sharing options...
LeeC22 Posted July 15, 2020 Share Posted July 15, 2020 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. Link to comment Share on other sites More sharing options...
patsanchique Posted July 15, 2020 Author Share Posted July 15, 2020 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 Link to comment Share on other sites More sharing options...
LeeC22 Posted July 15, 2020 Share Posted July 15, 2020 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. Link to comment Share on other sites More sharing options...
patsanchique Posted July 16, 2020 Author Share Posted July 16, 2020 (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 July 16, 2020 by patsanchique Link to comment Share on other sites More sharing options...
LeeC22 Posted July 16, 2020 Share Posted July 16, 2020 (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 July 16, 2020 by LeeC22 Link to comment Share on other sites More sharing options...
patsanchique Posted July 16, 2020 Author Share Posted July 16, 2020 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 LeeC22 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now