Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void RaycastGun()
- {
- if (PLAYER::IS_PLAYER_FREE_AIMING(self))
- {
- Vector3 endCoords;
- Vector3 shootcoord;
- Vector3 playerCoords = PED::GET_PED_BONE_COORDS(selfPed, SKEL_R_Hand, 0, 0, 0);
- Vector3 cameraRot = CAM::GET_GAMEPLAY_CAM_ROT(0);
- Vector3 cameraPosition = CAM::GET_GAMEPLAY_CAM_COORD();
- Vector3 gameplayCam = CAM::_GET_GAMEPLAY_CAM_COORDS();
- Vector3 gameplayCamRot = CAM::GET_GAMEPLAY_CAM_ROT(0);
- Vector3 gameplayCamDirection = RotationToDirection(&gameplayCamRot);
- Vector3 startCoords = addVector(gameplayCam, (multiplyVector(gameplayCamDirection, 1.0f)));
- Vector3 endCoordinates = addVector(startCoords, multiplyVector(gameplayCamDirection, 500.0f));
- try
- {
- RaycastResult rc = Raycast(cameraPosition, endCoordinates, IntersectEverything);
- endCoords = rc.HitCoords;
- if (rc.DidHitAnything)
- {
- switch (ENTITY::GET_ENTITY_TYPE(rc.HitEntity))
- {
- case 1: // Ped
- shootcoord = PED::GET_PED_BONE_COORDS(rc.HitEntity, SKEL_Head, 0, 0, 0);
- GRAPHICS::DRAW_LINE(playerCoords.x, playerCoords.y, playerCoords.z + 0.1f, shootcoord.x, shootcoord.y, shootcoord.z, 0, 255, 0, 255);
- notifyBottom("~g~Ped ~s~is %.0f mt away", distanceBetween(selfCoords, rc.HitCoords));
- break;
- case 2: // Vehicle
- shootcoord = rc.HitCoords;
- GRAPHICS::DRAW_LINE(playerCoords.x, playerCoords.y, playerCoords.z + 0.1f, shootcoord.x, shootcoord.y, shootcoord.z, 255, 0, 0, 255);
- notifyBottom("~r~Vehicle ~s~is %.0f mt away", distanceBetween(selfCoords, rc.HitCoords));
- break;
- case 3: // Object
- shootcoord = rc.HitCoords;
- GRAPHICS::DRAW_LINE(playerCoords.x, playerCoords.y, playerCoords.z + 0.1f, shootcoord.x, shootcoord.y, shootcoord.z, 0, 0, 255, 255);
- notifyBottom("~b~Object ~s~is %.0f mt away", distanceBetween(selfCoords, rc.HitCoords));
- break;
- default: // Something is wrong, the entity is not a ped/vehicle/object
- break;
- }
- if (PED::IS_PED_SHOOTING(selfPed))
- {
- PED::SET_PED_SHOOTS_AT_COORD(selfPed, shootcoord.x, shootcoord.y, shootcoord.z, true);
- auto currentWeapon = WEAPON::GET_SELECTED_PED_WEAPON(selfPed);
- GAMEPLAY::SHOOT_SINGLE_BULLET_BETWEEN_COORDS(startCoords.x, startCoords.y, startCoords.z,
- shootcoord.x, shootcoord.y, shootcoord.z,
- 250, 1, currentWeapon, selfPed, 1, 0, -1.0);
- }
- }
- }
- catch (...) {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement