Merge pull request #83 from project-error/cleanup/game-scripts

Cleanup/game scripts - Misc. cleanup of game scripts
This commit is contained in:
Taso authored and GitHub committed 2021-02-11 16:51:28 -05:00
commit 992719980a
6 files changed
+334 -360

No files matched your search

+3 -3
View File
@@ -21,9 +21,9 @@ onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => {
});
RegisterNuiCallbackType(events.BANK_ADD_TRANSFER);
on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => {
const transfer = data;
emitNet(events.BANK_ADD_TRANSFER, transfer);
on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any, cb: Function) => {
emitNet(events.BANK_ADD_TRANSFER, data);
cb();
});
onNet(events.BANK_ADD_TRANSFER_SUCCESS, () => {
+8 -5
View File
@@ -4,10 +4,10 @@ import { ICall } from '../../phone/src/common/typings/call';
const exp = (global as any).exports;
RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL);
on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any) => {
on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any, cb: Function) => {
const start = Date.now();
emitNet(events.PHONE_INITIALIZE_CALL, data.number, start);
cb();
});
onNet(
@@ -31,8 +31,9 @@ onNet(
);
RegisterNuiCallbackType(events.PHONE_ACCEPT_CALL);
on(`__cfx_nui:${events.PHONE_ACCEPT_CALL}`, (data: any) => {
on(`__cfx_nui:${events.PHONE_ACCEPT_CALL}`, (data: any, cb: Function) => {
emitNet(events.PHONE_ACCEPT_CALL, data.transmitterNumber);
cb();
});
onNet(
@@ -56,9 +57,10 @@ onNet(
);
RegisterNuiCallbackType(events.PHONE_CALL_REJECTED);
on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any) => {
on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any, cb: Function) => {
const end = Date.now();
emitNet(events.PHONE_CALL_REJECTED, data.transmitterNumber, end);
cb();
});
onNet(events.PHONE_CALL_WAS_REJECTED, () => {
@@ -79,9 +81,10 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => {
});
RegisterNuiCallbackType(events.PHONE_END_CALL);
on(`__cfx_nui:${events.PHONE_END_CALL}`, (data: any) => {
on(`__cfx_nui:${events.PHONE_END_CALL}`, (data: any, cb: Function) => {
const end = Date.now();
emitNet(events.PHONE_END_CALL, data.transmitterNumber, end);
cb();
});
onNet(events.PHONE_CALL_WAS_ENDED, () => {
+9 -8
View File
@@ -11,11 +11,12 @@ onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => {
});
RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT);
on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any, cb: Function) => {
const display = data.name;
const number = data.number;
const avatar = data.avatar;
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
cb();
});
onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
@@ -23,20 +24,20 @@ onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
});
RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
const contact = data;
emitNet(events.CONTACTS_UPDATE_CONTACT, contact);
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any, cb: Function) => {
emitNet(events.CONTACTS_UPDATE_CONTACT, data);
cb();
});
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
emitNet(events.CONTACTS_GET_CONTACTS);
console.log("did you update the contact??????????????????");
console.log('did you update the contact??????????????????');
});
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
const contact = data;
emitNet(events.CONTACTS_DELETE_CONTACT, contact);
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any, cb: Function) => {
emitNet(events.CONTACTS_DELETE_CONTACT, data);
cb();
});
onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
+256 -288
View File
@@ -1,12 +1,22 @@
import { ESX } from '../client/client';
import config from '../utils/config';
import { Delay } from '../utils/fivem';
import events from '../utils/events';
let prop = 0;
let isPhoneOpen = false;
let propCreated = false;
let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed.
/* * * * * * * * * * * * *
*
* Register Command and Keybinding
*
* * * * * * * * * * * * */
RegisterCommand(
'phone:close',
(source: any, args: string[], raw: any) => {
phoneCloseAnim();
async (source: any, args: string[], raw: any) => {
await phoneCloseAnim();
SetNuiFocus(false, false);
SendNuiMessage(
JSON.stringify({
@@ -19,19 +29,38 @@ RegisterCommand(
false
);
let prop = 0;
let isPhoneOpen = false;
let propCreated = false;
let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed.
RegisterCommand(
'+phone',
async () => {
//-- Toggles Phone
await Phone();
},
false
);
RegisterCommand(
'phone:open',
async () => {
await Phone();
},
false
);
RegisterKeyMapping('+phone', 'Open Phone', 'keyboard', 'f1');
/* * * * * * * * * * * * *
*
* Prop Deletion/Creation handling
*
* * * * * * * * * * * * */
const newPhoneProp = async () => {
//Function for creating the phone prop
deletePhone(); //deletes the already existing prop before creating another.
removePhoneProp(); //deletes the already existing prop before creating another.
if (!propCreated) {
RequestModel(phoneModel);
while (!HasModelLoaded(phoneModel)) {
await Delay(1);
console.log('MODEL HASNT LOADED');
}
const playerPed = PlayerPedId();
@@ -71,14 +100,13 @@ const newPhoneProp = async () => {
}
};
function deletePhone() {
function removePhoneProp() {
//-- Triggered in newphoneProp function. Only way to destory the prop correctly.
if (prop != 0) {
//Citizen.invokeNative(0xAE3CBE5BF394C9C9 , Citizen.pointerValueIntInitialized(prop))
DeleteEntity(prop);
prop = 0;
propCreated = false;
console.log('prop destroyed');
}
}
@@ -90,274 +118,175 @@ async function loadAnimDict(dict: any) {
}
}
async function phoneOpenAnim() {
//Phone Open Animation
console.log('phoneOpenAnim'); //Left for testing purposes.
const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
deletePhone(); //Deleting before creating a new phone where itll be deleted again.
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) {
//-- true refers to at get in.
const dict = 'anim@cellphone@in_car@ps';
/* * * * * * * * * * * * *
*
* Animations
*
* * * * * * * * * * * * */
ClearPedTasks(GetPlayerPed(-1));
await loadAnimDict(dict);
TaskPlayAnim(
GetPlayerPed(-1),
dict,
'cellphone_text_in',
8.0,
-1,
-1,
flag,
0,
false,
false,
false
);
await Delay(300); //Gives time for animation starts before creating the phone
await newPhoneProp(); //Creates the phone and attaches it.
} else {
//While not in a vehicle it will use this dict.
const dict = 'cellphone@';
const handleOpenVehicleAnim = async (playerPed: number): Promise<void> => {
const dict = 'anim@cellphone@in_car@ps';
ClearPedTasks(GetPlayerPed(-1));
await loadAnimDict(dict);
TaskPlayAnim(
GetPlayerPed(-1),
dict,
'cellphone_text_in',
8.0,
-1,
-1,
flag,
0,
false,
false,
false
);
await Delay(300); //Gives time for animation starts before creating the phone
await newPhoneProp(); //Creates the phone and attaches it.
ClearPedTasks(playerPed);
await loadAnimDict(dict);
TaskPlayAnim(
playerPed,
dict,
'cellphone_text_in',
8.0,
-1,
-1,
50,
0,
false,
false,
false
);
await Delay(300); //Gives time for animation starts before creating the phone
await newPhoneProp(); //Creates the phone and attaches it.
};
const handleOpenNormalAnim = async (playerPed: number): Promise<void> => {
//While not in a vehicle it will use this dict.
const dict = 'cellphone@';
ClearPedTasks(playerPed);
await loadAnimDict(dict);
TaskPlayAnim(
playerPed,
dict,
'cellphone_text_in',
8.0,
-1,
-1,
50,
0,
false,
false,
false
);
await Delay(300); //Gives time for animation starts before creating the phone
await newPhoneProp(); //Creates the phone and attaches it.
};
const handleCloseVehicleAnim = async (playerPed: number): Promise<void> => {
//true refers to at get in.
const DICT = 'anim@cellphone@in_car@ps';
const ANIM = 'cellphone_text_out';
StopAnimTask(playerPed, DICT, 'cellphone_text_in', 1.0); //Stop the pull out animation
removePhoneProp(); //Deletes the prop early incase they get out of the vehicle.
await Delay(250); //lets it get to a certain point
await loadAnimDict(DICT); //loads the new animation
TaskPlayAnim(playerPed, DICT, ANIM, 8.0, -1, -1, 50, 0, false, false, false); //puts phone into pocket
await Delay(200); //waits until the phone is in the pocket
StopAnimTask(playerPed, DICT, ANIM, 1.0); //clears the animation
};
const handleCloseNormalAnim = async (playerPed: number): Promise<void> => {
const DICT = 'cellphone@';
const ANIM = 'cellphone_text_out';
StopAnimTask(playerPed, DICT, 'cellphone_text_in', 1.0); //Stop the pull out animation
await Delay(100); //lets it get to a certain point
await loadAnimDict(DICT); //loads the new animation
TaskPlayAnim(playerPed, DICT, ANIM, 8.0, -1, -1, 50, 0, false, false, false); //puts phone into pocket
await Delay(200); //waits until the phone is in the pocket
StopAnimTask(playerPed, DICT, ANIM, 1.0); //clears the animation
removePhoneProp(); //Deletes the prop.
};
async function phoneOpenAnim(): Promise<void> {
const playerPed = PlayerPedId();
removePhoneProp(); //Deleting before creating a new phone where itll be deleted again.
if (IsPedInAnyVehicle(playerPed, true)) {
return await handleOpenVehicleAnim(playerPed);
}
return await handleOpenNormalAnim(playerPed);
}
async function phoneCloseAnim() {
//Phone Close Animation
console.log('phoneCloseAnim'); //Left for testing purposes.
const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
const anim = 'cellphone_text_out';
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) {
//true refers to at get in.
const dict = 'anim@cellphone@in_car@ps';
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0); //Stop the pull out animation
deletePhone(); //Deletes the prop early incase they get out of the vehicle.
await Delay(250); //lets it get to a certain point
loadAnimDict(dict); //loads the new animation
TaskPlayAnim(
GetPlayerPed(-1),
dict,
anim,
8.0,
-1,
-1,
flag,
0,
false,
false,
false
); //puts phone into pocket
await Delay(200); //waits until the phone is in the pocket
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation
} else {
//While not in a vehicle it will use this dict.
const dict = 'cellphone@';
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0); //Stop the pull out animation
await Delay(100); //lets it get to a certain point
loadAnimDict(dict); //loads the new animation
TaskPlayAnim(
GetPlayerPed(-1),
dict,
anim,
8.0,
-1,
-1,
flag,
0,
false,
false,
false
); //puts phone into pocket
await Delay(200); //waits until the phone is in the pocket
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation
deletePhone(); //Deletes the prop.
const playerPed = PlayerPedId();
if (IsPedInAnyVehicle(playerPed, true)) {
return await handleCloseVehicleAnim(playerPed);
}
await handleCloseNormalAnim(playerPed);
}
async function carryingPhone(cb: any) {
if (ESX === null) return cb(0);
ESX.TriggerServerCallback(
'phone:getItemAmount',
(qtty: number) => {
cb(qtty > 0);
},
'phone'
);
}
function noPhone() {
if (ESX === null) return;
ESX.ShowNotification('Oi Mate, No El Telephono', false, false, 1);
}
setTick(() => {
if (IsControlJustPressed(1, config.KeyTogglePhone)) {
Phone();
}
});
// setTick(() => {
// if (isPhoneOpen) {
// DisableControlAction(0, 1, true)
// DisableControlAction(0, 2, true)
// DisableControlAction(0, 24, true)
// DisableControlAction(0, 257, true)
// DisableControlAction(0, 25, true)
// DisableControlAction(0, 263, true)
// } else {
// EnableControlAction(0, 1, true)
// EnableControlAction(0, 2, true)
// EnableControlAction(0, 24, true)
// EnableControlAction(0, 257, true)
// EnableControlAction(0, 25, true)
// EnableControlAction(0, 263, true)
// if (IsControlJustPressed(1, config.KeyTogglePhone)) {
// Phone();
// }
// })
// });
async function Phone() {
if (config.PhoneAsItem) {
console.log('CONFIG ON');
carryingPhone(async (carryingPhone: any) => {
if (carryingPhone) {
if (!isPhoneOpen) {
isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
console.log('Sellout fetched from client side'); // Gets the credentials. Will eventually most likely only get the phone number and name, idk.
SetCursorLocation(0.9, 0.922); //Experimental
let res = GetActiveScreenResolution();
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: true,
})
);
SetNuiFocus(true, true);
//SetNuiFocusKeepInput(true)
} else {
isPhoneOpen = false;
SendNuiMessage(
//Hides phone
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
})
);
SetNuiFocus(false, false);
//SetNuiFocusKeepInput(false)
/* * * * * * * * * * * * *
*
* Phone Visibility Handling
*
* * * * * * * * * * * * */
await phoneCloseAnim(); // Animation starts after the UI is closed.
}
} else {
noPhone();
}
});
} else if (!config.PhoneAsItem) {
console.log('CONFIG OFF');
if (!isPhoneOpen) {
isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
console.log('Sellout fetched from client side');
SetCursorLocation(0.936, 0.922); //Experimental
let res = GetActiveScreenResolution();
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: true,
})
);
SetNuiFocus(true, true);
//SetNuiFocusKeepInput(true)
} else {
isPhoneOpen = false;
SendNuiMessage(
//Hides phone
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
})
);
SetNuiFocus(false, false);
//SetNuiFocusKeepInput(false)
const showPhone = async (): Promise<void> => {
isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
SetCursorLocation(0.9, 0.922); //Experimental
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: true,
})
);
sendPhoneConfig();
SetNuiFocus(true, true);
};
await phoneCloseAnim(); // Animation starts after the UI is closed.
}
const hidePhone = async (): Promise<void> => {
isPhoneOpen = false;
SendNuiMessage(
//Hides phone
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
})
);
await phoneCloseAnim();
SetNuiFocus(false, false);
};
const togglePhoneVisible = async (): Promise<void> => {
if (isPhoneOpen) {
await hidePhone();
} else {
await showPhone();
}
};
/* * * * * * * * * * * * *
*
* Misc. Helper Functions
*
* * * * * * * * * * * * */
async function Phone(): Promise<void> {
if (config.PhoneAsItem) {
// TODO: Do promise callback here
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
// if (!hasPhoneItem) return
return await togglePhoneVisible();
}
await togglePhoneVisible();
}
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
// contacts app
RegisterNuiCallbackType(events.OPEN_APP_CONTACTS);
on(`__cfx_nui:${events.OPEN_APP_CONTACTS}`, () => {
emitNet(events.CONTACTS_GET_CONTACTS);
});
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, () => {
emitNet(events.SELLOUT_FETCH_LISTING);
});
RegisterNuiCallbackType(events.OPEN_APP_NOTES);
on(`__cfx_nui:${events.OPEN_APP_NOTES}`, () => {
emitNet(events.NOTE_FETCH_ALL_NOTES);
});
RegisterNuiCallbackType(events.OPEN_APP_BANK);
on(`__cfx_nui:${events.OPEN_APP_BANK}`, () => {
emitNet(events.BANK_FETCH_TRANSACTIONS);
emitNet(events.BANK_GET_CREDENTIALS);
});
RegisterNuiCallbackType(events.OPEN_APP_CAMERA);
on(`__cfx_nui:${events.OPEN_APP_CAMERA}`, () => {
emitNet(events.CAMERA_FETCH_PHOTOS);
});
RegisterNuiCallbackType(events.OPEN_APP_DAILER);
on(`__cfx_nui:${events.OPEN_APP_DAILER}`, () => {
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.PHONE_CALL_FETCH_CALLS);
});
RegisterCommand(
'phone',
() => {
//-- Toggles Phone
Phone();
},
false
);
RegisterNuiCallbackType('phone:close');
on(`__cfx_nui:phone:close`, () => {
Phone();
}); // Called for when the phone is closed via the UI.
function sendPhoneConfig() {
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'phoneConfig',
data: config,
})
);
}
AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) {
@@ -369,26 +298,75 @@ AddEventHandler('onResourceStop', function (resource: string) {
})
);
SetNuiFocus(false, false);
deletePhone(); //Deletes the phone incase it was attached.
ClearPedTasks(GetPlayerPed(-1)); //Leave here until launch as it'll fix any stuck animations.
removePhoneProp(); //Deletes the phone incase it was attached.
ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations.
}
});
//
//Phone Destory When Wet
//
function countPhone(cb: any) {
if (ESX === null) return cb(0);
ESX.TriggerServerCallback(
'phone:getItemAmount',
(qtty: number) => {
cb(qtty > 0);
},
'phone'
onNet('phone:sendCredentials', (number: string) => {
SendNuiMessage(
JSON.stringify({
app: 'SIMCARD',
method: 'setNumber',
data: number,
})
);
}
});
let destroyedPhone = false;
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
/* * * * * * * * * * * * *
*
* NUI Service Callback Registration
*
* * * * * * * * * * * * */
// contacts app
RegisterNuiCallbackType(events.OPEN_APP_CONTACTS);
on(`__cfx_nui:${events.OPEN_APP_CONTACTS}`, (data: any, cb: Function) => {
emitNet(events.CONTACTS_GET_CONTACTS);
cb();
});
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
emitNet(events.SELLOUT_FETCH_LISTING);
cb();
});
RegisterNuiCallbackType(events.OPEN_APP_NOTES);
on(`__cfx_nui:${events.OPEN_APP_NOTES}`, (data: any, cb: Function) => {
emitNet(events.NOTE_FETCH_ALL_NOTES);
cb();
});
RegisterNuiCallbackType(events.OPEN_APP_BANK);
on(`__cfx_nui:${events.OPEN_APP_BANK}`, (data: any, cb: Function) => {
emitNet(events.BANK_FETCH_TRANSACTIONS);
emitNet(events.BANK_GET_CREDENTIALS);
cb();
});
RegisterNuiCallbackType(events.OPEN_APP_CAMERA);
on(`__cfx_nui:${events.OPEN_APP_CAMERA}`, (data: any, cb: Function) => {
emitNet(events.CAMERA_FETCH_PHOTOS);
cb();
});
RegisterNuiCallbackType(events.OPEN_APP_DAILER);
on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.PHONE_CALL_FETCH_CALLS);
cb();
});
RegisterNuiCallbackType('phone:close');
on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => {
await Phone();
cb();
}); // Called for when the phone is closed via the UI.
// setTick(async () => {
// while (config.SwimDestroy) {
@@ -409,13 +387,3 @@ let destroyedPhone = false;
// }
// }
// });
onNet('phone:sendCredentials', (number: string) => {
SendNuiMessage(
JSON.stringify({
app: 'SIMCARD',
method: 'setNumber',
data: number,
})
);
});
+11 -5
View File
@@ -34,8 +34,9 @@ emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS);
RegisterNuiCallbackType(events.MESSAGES_CREATE_MESSAGE_GROUP);
on(
`__cfx_nui:${events.MESSAGES_CREATE_MESSAGE_GROUP}`,
({ phoneNumbers, label }: any): void => {
({ phoneNumbers, label }: any, cb: Function): void => {
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP, phoneNumbers, label);
cb();
}
);
@@ -52,9 +53,13 @@ onNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, (result: any): void => {
* Messages fetch messages
*/
RegisterNuiCallbackType(events.MESSAGES_FETCH_MESSAGES);
on(`__cfx_nui:${events.MESSAGES_FETCH_MESSAGES}`, ({ groupId }: any): void => {
emitNet(events.MESSAGES_FETCH_MESSAGES, groupId);
});
on(
`__cfx_nui:${events.MESSAGES_FETCH_MESSAGES}`,
({ groupId }: any, cb: Function): void => {
emitNet(events.MESSAGES_FETCH_MESSAGES, groupId);
cb();
}
);
onNet(events.MESSAGES_FETCH_MESSAGES_SUCCESS, (messages: Message[]): void => {
sendMessageEvent(events.MESSAGES_FETCH_MESSAGES_SUCCESS, messages);
@@ -68,8 +73,9 @@ onNet(events.MESSAGES_FETCH_MESSAGES_FAILED, (): void => {
* Messages send message
*/
RegisterNuiCallbackType(events.MESSAGES_SEND_MESSAGE);
on(`__cfx_nui:${events.MESSAGES_SEND_MESSAGE}`, (data: any) => {
on(`__cfx_nui:${events.MESSAGES_SEND_MESSAGE}`, (data: any, cb: Function) => {
emitNet(events.MESSAGES_SEND_MESSAGE, data.groupId, data.message);
cb();
});
onNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, (groupId: string) => {
+47 -51
View File
@@ -4,7 +4,10 @@ const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
const exp = (global as any).exports;
let inCameraMode = false;
function closePhoneTemp() {
SetNuiFocus(false, false);
SendNuiMessage(
//Hides phone
JSON.stringify({
@@ -16,6 +19,7 @@ function closePhoneTemp() {
}
function openPhoneTemp() {
SetNuiFocus(true, true);
SendNuiMessage(
//Opens phone
JSON.stringify({
@@ -26,74 +30,66 @@ function openPhoneTemp() {
);
}
let takingPhoto = false;
function CellFrontCamActivate(activate: any) {
function CellFrontCamActivate(activate: boolean) {
return Citizen.invokeNative('0x2491A93618B7D838', activate);
}
RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO);
on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async () => {
CreateMobilePhone(1);
CellCamActivate(true, true);
const displayHelperText = () => {
BeginTextCommandDisplayHelp('TWOSTRINGS');
AddTextComponentString('Exit Camera Mode: ~INPUT_CELLPHONE_CANCEL~');
AddTextComponentString('Toggle Front/Back: ~INPUT_PHONE~');
EndTextCommandDisplayHelp(0, true, false, -1);
};
RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO);
on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async (data: any, cb: Function) => {
cb();
// Create Phone Prop
CreateMobilePhone(1);
// Active Camera Change
CellCamActivate(true, true);
// Hide phone from rendering temporary
closePhoneTemp();
SetNuiFocus(false, false);
takingPhoto = true;
inCameraMode = true;
while (takingPhoto) {
while (inCameraMode) {
await Delay(0);
let frontCam = false;
displayHelperText();
if (IsControlJustPressed(1, 27)) {
if (!frontCam) {
frontCam = true;
CellFrontCamActivate(true);
} else {
frontCam = false;
CellFrontCamActivate(false);
}
frontCam = !frontCam;
CellFrontCamActivate(frontCam);
} else if (IsControlJustPressed(1, 176)) {
takePhoto();
await Delay(200);
console.log('phone closing');
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
SetNuiFocus(true, true);
takingPhoto = false;
await handleTakePicture();
} else if (IsControlJustPressed(1, 177)) {
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
SetNuiFocus(true, true);
takingPhoto = false;
handleCameraExit();
break;
}
}
ClearHelp(true);
});
//setTick(async () => {
// while (takingPhoto) {
// await Delay(0);
//
// if (IsControlReleased(1, 177)) {
// DestroyMobilePhone();
// CellCamActivate(false, false);
// takingPhoto = false;
// SetNuiFocus(true, true);
// break;
// }
// }
//})
const handleTakePicture = async () => {
takePhoto();
await Delay(200);
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
inCameraMode = false;
};
const handleCameraExit = () => {
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
inCameraMode = false;
};
onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
console.log(photos);
// console.log(photos);
SendNuiMessage(
JSON.stringify({
app: 'CAMERA',
@@ -104,7 +100,6 @@ onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
});
function takePhoto() {
const [width, height] = GetActiveScreenResolution();
// Return and log error if screenshot basic token not found
if (SCREENSHOT_BASIC_TOKEN === 'none') {
return console.error(
@@ -129,13 +124,14 @@ function takePhoto() {
onNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, () => {
emitNet(events.CAMERA_FETCH_PHOTOS);
})
});
// delete photo
RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO);
on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any) => {
on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any, cb: Function) => {
emitNet(events.CAMERA_DELETE_PHOTO, data);
cb();
});
onNet(events.CAMERA_DELETE_PHOTO_SUCCESS, () => {