mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Wait -> Delay
This commit is contained in:
1 parent
2e278e2a40
commit
bc873e5a14
2 files changed
+30
-27
No files matched your search
+28
-27
@@ -1,5 +1,6 @@
|
|||||||
import { ESXClient } from "fivem-esx-js/client/esx_client";
|
import { ESXClient } from "fivem-esx-js/client/esx_client";
|
||||||
import config from '../utils/config';
|
import config from '../utils/config';
|
||||||
|
import { Delay } from '../utils/fivem';
|
||||||
|
|
||||||
let ESX: ESXClient = null;
|
let ESX: ESXClient = null;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ setTick(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RegisterCommand('phone:close', (source: any, args: string[], raw: any) => {
|
RegisterCommand('phone:close', (source: any, args: string[], raw: any) => {
|
||||||
phoneCloseAnim()
|
phoneCloseAnim()
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
@@ -27,12 +29,12 @@ let isPhoneOpen = false
|
|||||||
let propCreated = false
|
let propCreated = false
|
||||||
let phoneModel = "prop_amb_phone" // Refered to in newphoneProp function. Requires custom phone being streamed.
|
let phoneModel = "prop_amb_phone" // Refered to in newphoneProp function. Requires custom phone being streamed.
|
||||||
|
|
||||||
const newPhoneProp = () => { //Function for creating the phone prop
|
const newPhoneProp = async () => { //Function for creating the phone prop
|
||||||
deletePhone() //deletes the already existing prop before creating another.
|
deletePhone() //deletes the already existing prop before creating another.
|
||||||
if (!propCreated) {
|
if (!propCreated) {
|
||||||
RequestModel(phoneModel)
|
RequestModel(phoneModel)
|
||||||
while (!HasModelLoaded(phoneModel)) {
|
while (!HasModelLoaded(phoneModel)) {
|
||||||
Wait(1)
|
await Delay(1)
|
||||||
console.log("MODEL HASNT LOADED")
|
console.log("MODEL HASNT LOADED")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,14 +62,14 @@ function deletePhone() { //-- Triggered in newphoneProp function. Only way to de
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadAnimDict(dict: any) { //-- Loads the animation dict. Used in the anim functions.
|
async function loadAnimDict(dict: any) { //-- Loads the animation dict. Used in the anim functions.
|
||||||
while (!HasAnimDictLoaded(dict)) {
|
while (!HasAnimDictLoaded(dict)) {
|
||||||
RequestAnimDict(dict)
|
RequestAnimDict(dict)
|
||||||
Wait(0)
|
await Delay(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function phoneOpenAnim() { //Phone Open Animation
|
async function phoneOpenAnim() { //Phone Open Animation
|
||||||
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||||
deletePhone() //Deleting before creating a new phone where itll be deleted again.
|
deletePhone() //Deleting before creating a new phone where itll be deleted again.
|
||||||
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //-- true refers to at get in.
|
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //-- true refers to at get in.
|
||||||
@@ -75,24 +77,24 @@ function phoneOpenAnim() { //Phone Open Animation
|
|||||||
const kek = "pepein"
|
const kek = "pepein"
|
||||||
|
|
||||||
ClearPedTasks(GetPlayerPed(-1))
|
ClearPedTasks(GetPlayerPed(-1))
|
||||||
loadAnimDict(dict)
|
await loadAnimDict(dict)
|
||||||
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
|
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
|
||||||
Wait(300) //Gives time for animation starts before creating the phone
|
await Delay(300) //Gives time for animation starts before creating the phone
|
||||||
//newPhoneProp() //Creates the phone and attaches it.
|
await newPhoneProp() //Creates the phone and attaches it.
|
||||||
}
|
}
|
||||||
else { //While not in a vehicle it will use this dict.
|
else { //While not in a vehicle it will use this dict.
|
||||||
const dict = 'cellphone@'
|
const dict = 'cellphone@'
|
||||||
const kek = "pepeout"
|
const kek = "pepeout"
|
||||||
|
|
||||||
ClearPedTasks(GetPlayerPed(-1))
|
ClearPedTasks(GetPlayerPed(-1))
|
||||||
loadAnimDict(dict)
|
await loadAnimDict(dict)
|
||||||
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
|
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
|
||||||
Wait(300) //Gives time for animation starts before creating the phone
|
await Delay(300) //Gives time for animation starts before creating the phone
|
||||||
newPhoneProp() //Creates the phone and attaches it.
|
await newPhoneProp() //Creates the phone and attaches it.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function phoneCloseAnim() { //Phone Close Animation
|
async function phoneCloseAnim() { //Phone Close Animation
|
||||||
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||||
const anim = 'cellphone_text_out'
|
const anim = 'cellphone_text_out'
|
||||||
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //true refers to at get in.
|
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //true refers to at get in.
|
||||||
@@ -101,10 +103,10 @@ function phoneCloseAnim() { //Phone Close Animation
|
|||||||
|
|
||||||
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
|
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.
|
deletePhone() //Deletes the prop early incase they get out of the vehicle.
|
||||||
Wait(250) //lets it get to a certain point
|
await Delay(250) //lets it get to a certain point
|
||||||
loadAnimDict(dict) //loads the new animation
|
loadAnimDict(dict) //loads the new animation
|
||||||
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 1, false, false, false) //puts phone into pocket
|
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 1, false, false, false) //puts phone into pocket
|
||||||
Wait(200) //waits until the phone is in the pocket
|
await Delay(200) //waits until the phone is in the pocket
|
||||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
|
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
|
||||||
}
|
}
|
||||||
else { //While not in a vehicle it will use this dict.
|
else { //While not in a vehicle it will use this dict.
|
||||||
@@ -112,10 +114,10 @@ function phoneCloseAnim() { //Phone Close Animation
|
|||||||
const kek = "pepeout"
|
const kek = "pepeout"
|
||||||
|
|
||||||
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
|
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
|
||||||
Wait(100) //lets it get to a certain point
|
await Delay(100) //lets it get to a certain point
|
||||||
loadAnimDict(dict) //loads the new animation
|
loadAnimDict(dict) //loads the new animation
|
||||||
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 1, false, false, false) //puts phone into pocket
|
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 1, false, false, false) //puts phone into pocket
|
||||||
Wait(200) //waits until the phone is in the pocket
|
await Delay(200) //waits until the phone is in the pocket
|
||||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
|
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
|
||||||
deletePhone() //Deletes the prop.
|
deletePhone() //Deletes the prop.
|
||||||
}
|
}
|
||||||
@@ -149,15 +151,14 @@ setTick(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let PhoneAsItem = config.PhoneAsItem;
|
|
||||||
|
|
||||||
function Phone() {
|
async function Phone() {
|
||||||
if (PhoneAsItem) {
|
if (config.PhoneAsItem) {
|
||||||
carryingPhone((carryingPhone: any) => {
|
carryingPhone(async (carryingPhone: any) => {
|
||||||
if (carryingPhone) {
|
if (carryingPhone) {
|
||||||
if (!isPhoneOpen) {
|
if (!isPhoneOpen) {
|
||||||
isPhoneOpen = true
|
isPhoneOpen = true
|
||||||
phoneOpenAnim()
|
await phoneOpenAnim()
|
||||||
console.log("phone is now open") //Left for testing purposes.
|
console.log("phone is now open") //Left for testing purposes.
|
||||||
TriggerServerEvent('phone:getCredentials', source)
|
TriggerServerEvent('phone:getCredentials', source)
|
||||||
SetCursorLocation(0.936, 0.922) //Experimental
|
SetCursorLocation(0.936, 0.922) //Experimental
|
||||||
@@ -191,10 +192,10 @@ function Phone() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else if (!PhoneAsItem) {
|
else if (!config.PhoneAsItem) {
|
||||||
if (!isPhoneOpen) {
|
if (!isPhoneOpen) {
|
||||||
isPhoneOpen = true
|
isPhoneOpen = true
|
||||||
phoneOpenAnim()
|
await phoneOpenAnim()
|
||||||
console.log("phone is now open") //Left for testing purposes.
|
console.log("phone is now open") //Left for testing purposes.
|
||||||
TriggerServerEvent('phone:getCredentials', source)
|
TriggerServerEvent('phone:getCredentials', source)
|
||||||
SetCursorLocation(0.936, 0.922) //Experimental
|
SetCursorLocation(0.936, 0.922) //Experimental
|
||||||
@@ -220,7 +221,7 @@ function Phone() {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
phoneCloseAnim()
|
await phoneCloseAnim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,9 +268,9 @@ function countPhone(cb: any) {
|
|||||||
let destroyedPhone = false
|
let destroyedPhone = false
|
||||||
|
|
||||||
|
|
||||||
setTick(() => {
|
setTick(async () => {
|
||||||
while (config.SwimDestroy) {
|
while (config.SwimDestroy) {
|
||||||
Wait(config.RunRate * 1000);
|
await Delay(config.RunRate * 1000);
|
||||||
if (IsPedSwimming(PlayerPedId())) {
|
if (IsPedSwimming(PlayerPedId())) {
|
||||||
let chance = Math.floor((Math.random() * 100) + 1);
|
let chance = Math.floor((Math.random() * 100) + 1);
|
||||||
if (chance <= config.DestoryChance) {
|
if (chance <= config.DestoryChance) {
|
||||||
@@ -281,7 +282,7 @@ setTick(() => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (destroyedPhone) {
|
if (destroyedPhone) {
|
||||||
Wait(config.DestroyPhoneReCheck * 60000)
|
await Delay(config.DestroyPhoneReCheck * 60000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// https://forum.cfx.re/t/typescript-vs-lua-questions/612483/11
|
||||||
|
export const Delay = (ms: number) => new Promise(res => setTimeout(res, ms));
|
||||||
Reference in new issue
Block a user