feat(client/anim): Added animation flow for calls (#104)

Co-authored-by: Taso <[email protected]>
This commit is contained in:
RockySouthpawandTaso authored and GitHub committed 2021-02-18 12:39:30 -05:00
1 parent d6d2bed335
commit 3a572cbc7b
7 files changed
+243 -189

No files matched your search

+1 -171
View File
@@ -1,6 +1,6 @@
import config from '../utils/config';
import { Delay } from '../utils/fivem';
import events from '../utils/events';
import {phoneCloseAnim, phoneOpenAnim, removePhoneProp} from './functions';
let prop = 0;
let isPhoneOpen = false;
@@ -48,176 +48,6 @@ RegisterCommand(
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
/* * * * * * * * * * * * *
*
* Prop Deletion/Creation handling
*
* * * * * * * * * * * * */
const newPhoneProp = async () => {
removePhoneProp(); //deletes the already existing prop before creating another.
if (!propCreated) {
RequestModel(phoneModel);
while (!HasModelLoaded(phoneModel)) {
await Delay(1);
}
const playerPed = PlayerPedId();
const [x, y, z] = GetEntityCoords(playerPed, true);
prop = CreateObject(
GetHashKey(phoneModel),
x,
y,
z + 0.2,
true,
true,
true
);
//prop = CreateObject(GetHashKey(phoneModel), 1.0, 1.0, 1.0, 1, 1, 0)
const boneIndex = GetPedBoneIndex(playerPed, 28422);
AttachEntityToEntity(
prop,
playerPed,
boneIndex,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0,
true,
true,
false,
true,
1.0,
true
); //-- Attaches the phone to the player.
propCreated = true;
console.log('prop created');
} else if (propCreated) {
console.log('prop already created');
}
};
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;
}
}
async function loadAnimDict(dict: any) {
//-- Loads the animation dict. Used in the anim functions.
while (!HasAnimDictLoaded(dict)) {
RequestAnimDict(dict);
await Delay(100);
}
}
/* * * * * * * * * * * * *
*
* Animations
*
* * * * * * * * * * * * */
const handleOpenVehicleAnim = async (playerPed: number): Promise<void> => {
const dict = 'anim@cellphone@in_car@ps';
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() {
const playerPed = PlayerPedId();
if (IsPedInAnyVehicle(playerPed, true)) {
return await handleCloseVehicleAnim(playerPed);
}
await handleCloseNormalAnim(playerPed);
}
// setTick(() => {
// if (IsControlJustPressed(1, config.KeyTogglePhone)) {
// Phone();
// }
// });
/* * * * * * * * * * * * *
*
* Phone Visibility Handling