Advertisement
djhonga2001

Untitled

Jan 30th, 2017
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. void RaycastGun()
  2. {
  3. if (PLAYER::IS_PLAYER_FREE_AIMING(self))
  4. {
  5. Vector3 endCoords;
  6. Vector3 shootcoord;
  7. Vector3 playerCoords = PED::GET_PED_BONE_COORDS(selfPed, SKEL_R_Hand, 0, 0, 0);
  8. Vector3 cameraRot = CAM::GET_GAMEPLAY_CAM_ROT(0);
  9. Vector3 cameraPosition = CAM::GET_GAMEPLAY_CAM_COORD();
  10. Vector3 gameplayCam = CAM::_GET_GAMEPLAY_CAM_COORDS();
  11. Vector3 gameplayCamRot = CAM::GET_GAMEPLAY_CAM_ROT(0);
  12. Vector3 gameplayCamDirection = RotationToDirection(&gameplayCamRot);
  13. Vector3 startCoords = addVector(gameplayCam, (multiplyVector(gameplayCamDirection, 1.0f)));
  14. Vector3 endCoordinates = addVector(startCoords, multiplyVector(gameplayCamDirection, 500.0f));
  15. try
  16. {
  17. RaycastResult rc = Raycast(cameraPosition, endCoordinates, IntersectEverything);
  18. endCoords = rc.HitCoords;
  19. if (rc.DidHitAnything)
  20. {
  21. switch (ENTITY::GET_ENTITY_TYPE(rc.HitEntity))
  22. {
  23. case 1: // Ped
  24. shootcoord = PED::GET_PED_BONE_COORDS(rc.HitEntity, SKEL_Head, 0, 0, 0);
  25. GRAPHICS::DRAW_LINE(playerCoords.x, playerCoords.y, playerCoords.z + 0.1f, shootcoord.x, shootcoord.y, shootcoord.z, 0, 255, 0, 255);
  26. notifyBottom("~g~Ped ~s~is %.0f mt away", distanceBetween(selfCoords, rc.HitCoords));
  27. break;
  28. case 2: // Vehicle
  29. shootcoord = rc.HitCoords;
  30. GRAPHICS::DRAW_LINE(playerCoords.x, playerCoords.y, playerCoords.z + 0.1f, shootcoord.x, shootcoord.y, shootcoord.z, 255, 0, 0, 255);
  31. notifyBottom("~r~Vehicle ~s~is %.0f mt away", distanceBetween(selfCoords, rc.HitCoords));
  32. break;
  33. case 3: // Object
  34. shootcoord = rc.HitCoords;
  35. GRAPHICS::DRAW_LINE(playerCoords.x, playerCoords.y, playerCoords.z + 0.1f, shootcoord.x, shootcoord.y, shootcoord.z, 0, 0, 255, 255);
  36. notifyBottom("~b~Object ~s~is %.0f mt away", distanceBetween(selfCoords, rc.HitCoords));
  37. break;
  38. default: // Something is wrong, the entity is not a ped/vehicle/object
  39. break;
  40. }
  41.  
  42. if (PED::IS_PED_SHOOTING(selfPed))
  43. {
  44. PED::SET_PED_SHOOTS_AT_COORD(selfPed, shootcoord.x, shootcoord.y, shootcoord.z, true);
  45. auto currentWeapon = WEAPON::GET_SELECTED_PED_WEAPON(selfPed);
  46. GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(startCoords.x, startCoords.y, startCoords.z,
  47. shootcoord.x, shootcoord.y, shootcoord.z,
  48. 250, 1, currentWeapon, selfPed, 1, 0, -1.0);
  49. }
  50. }
  51. }
  52. catch (...) {}
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement