Files
new-phone-who-dis/resources/client/cl_photo.ts
T

144 lines
2.9 KiB
TypeScript

import events from "../utils/events";
import { Delay } from "../utils/fivem";
import { tokenData } from '../utils/token';
const exp = (global as any).exports
function closePhoneTemp() {
SendNuiMessage(
//Hides phone
JSON.stringify({
app: "PHONE",
method: "setVisibility",
data: false,
})
);
}
function openPhoneTemp() {
SendNuiMessage(
//Opens phone
JSON.stringify({
app: "PHONE",
method: "setVisibility",
data: true,
})
);
}
let takingPhoto = false
function CellFrontCamActivate(activate: any) {
return Citizen.invokeNative('0x2491A93618B7D838', activate)
}
RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO);
on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async () => {
CreateMobilePhone(1);
CellCamActivate(true, true);
closePhoneTemp()
SetNuiFocus(false, false);
takingPhoto = true;
while (takingPhoto) {
await Delay(0);
let frontCam = false;
if (IsControlJustPressed(1, 27)) {
if (!frontCam) {
frontCam = true;
CellFrontCamActivate(true);
} else {
frontCam = false;
CellFrontCamActivate(false);
}
} else if (IsControlJustPressed(1, 176)) {
takePhoto()
await Delay(200)
console.log("phone closing")
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp()
SetNuiFocus(true, true);
takingPhoto = false;
} else if (IsControlJustPressed(1, 177)) {
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp()
SetNuiFocus(true, true);
takingPhoto = false;
break;
}
}
});
//setTick(async () => {
// while (takingPhoto) {
// await Delay(0);
//
// if (IsControlReleased(1, 177)) {
// DestroyMobilePhone();
// CellCamActivate(false, false);
// takingPhoto = false;
// SetNuiFocus(true, true);
// break;
// }
// }
//})
onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
console.log(photos)
SendNuiMessage(
JSON.stringify({
app: "CAMERA",
method: "setPhotos",
data: photos
})
)
})
function takePhoto() {
const [width, height] = GetActiveScreenResolution();
console.log("photo taken")
exp["screenshot-basic"].requestScreenshotUpload(
"https://api.imgur.com/3/image",
"imgur",
{
headers: {
'authorization': `Client-ID ${ tokenData.token }`,
'content-type': 'multipart/form-data'
}
},
(data: string) => {
console.log("herrrrroooooooo")
const imageLink = JSON.parse(data).data.link;
emitNet(events.CAMERA_UPLOAD_PHOTO, imageLink)
}
);
}
// delete photo
RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO);
on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any) => {
emitNet(events.CAMERA_DELETE_PHOTO, data)
})
onNet(events.CAMERA_DELETE_PHOTO_SUCCESS, () => {
emitNet(events.CAMERA_FETCH_PHOTOS)
})