fixed up client.ts

This commit is contained in:
erik-sn committed 2020-10-13 22:39:48 -04:00
1 parent 409c35ed28
commit f672cd9645
2 files changed
+67 -126

No files matched your search

+65 -126
View File
@@ -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 "process"; import config from '../utils/config';
let ESX: ESXClient = null; let ESX: ESXClient = null;
setTick(() => { setTick(() => {
@@ -21,17 +22,6 @@ RegisterCommand('phone:close', (source: any, args: string[], raw: any) => {
) )
}, false) }, false)
//RegisterKeyMapping('phone', _U('keymap_phone'), 'keyboard', '') -- Lets people set a keybind for the phone command but can't be implemented yet.
//[[RegisterCommand('phone:get', function(source, args, rawCommand)
// TriggerServerEvent('phone:server:getCredentials')
//end, false)]]
//
//Start of Phone
//
let prop = 0 let prop = 0
let isPhoneOpen = false let isPhoneOpen = false
let propCreated = false let propCreated = false
@@ -39,7 +29,7 @@ let phoneModel = "prop_amb_phone" // Refered to in newphoneProp function. Requir
const newPhoneProp = () => { //Function for creating the phone prop const newPhoneProp = () => { //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 == false) { if (!propCreated) {
RequestModel(phoneModel) RequestModel(phoneModel)
while (!HasModelLoaded(phoneModel)) { while (!HasModelLoaded(phoneModel)) {
Wait(1) Wait(1)
@@ -55,7 +45,7 @@ const newPhoneProp = () => { //Function for creating the phone prop
propCreated = true propCreated = true
console.log("prop created") console.log("prop created")
} }
else if (propCreated == true) { else if (propCreated) {
console.log("prop already created") console.log("prop already created")
} }
} }
@@ -131,47 +121,41 @@ function phoneCloseAnim() { //Phone Close Animation
} }
} }
//function carryingPhone(cb)
// cb(true)
//end
async function carryingPhone(cb: any) { async function carryingPhone(cb: any) {
if (ESX == null) return cb(0); if (ESX === null) return cb(0);
const qtty = await ESX.TriggerServerCallback('phone:getItemAmount', 'phone'); ESX.TriggerServerCallback('phone:getItemAmount', (qtty: number) => {
cb(qtty > 0); cb(qtty > 0);
}, 'phone');
} }
function noPhone() { function noPhone() {
if (ESX == null) return; if (ESX === null) return;
//exports['mythic_notify']('error', 'Oi Mate, No El Telephono')
ESX.ShowNotification('Oi Mate, No El Telephono') ESX.ShowNotification('Oi Mate, No El Telephono')
} }
function sendPhoneConfig() { function sendPhoneConfig() {
ESX.TriggerServerCallback('phone:phoneConfig', function(config: any) { SendNuiMessage(
SendNuiMessage( JSON.stringify({
JSON.stringify({ app: "PHONE",
app: "PHONE", method: "phoneConfig",
method: "phoneConfig", data: config
data: config })
}) )
)
});
} }
setTick(() => { setTick(() => {
if (IsControlJustPressed(1, 288)) { if (IsControlJustPressed(1, config.KeyTogglePhone)) {
Phone(); Phone();
} }
}) })
let PhoneAsItem = false; let PhoneAsItem = config.PhoneAsItem;
function Phone() { function Phone() {
if (PhoneAsItem == true) { if (PhoneAsItem) {
carryingPhone((carryingPhone: any) => { carryingPhone((carryingPhone: any) => {
if (carryingPhone == true) { if (carryingPhone) {
if (isPhoneOpen == false) { if (!isPhoneOpen) {
isPhoneOpen = true isPhoneOpen = true
phoneOpenAnim() phoneOpenAnim()
console.log("phone is now open") //Left for testing purposes. console.log("phone is now open") //Left for testing purposes.
@@ -207,79 +191,56 @@ function Phone() {
} }
}) })
} }
else if (PhoneAsItem == false) { else if (!PhoneAsItem) {
//print("ConfigOff") if (!isPhoneOpen) {
if (isPhoneOpen == false) { isPhoneOpen = true
isPhoneOpen = true phoneOpenAnim()
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 let res = GetActiveScreenResolution()
let res = GetActiveScreenResolution() SendNuiMessage(
//print(res) JSON.stringify({
SendNuiMessage( app: "PHONE",
JSON.stringify({ method: "setVisibility",
app: "PHONE", data: true
method: "setVisibility", })
data: true )
}) sendPhoneConfig()
) SetNuiFocus(true, true)
sendPhoneConfig()
SetNuiFocus(true, true)
} }
else { else {
isPhoneOpen = false isPhoneOpen = false
console.log("phone is now closed") //Left for testing purposes. console.log("phone is now closed") //Left for testing purposes.
SendNuiMessage( //Hides phone SendNuiMessage( //Hides phone
JSON.stringify({ JSON.stringify({
app: "PHONE", app: "PHONE",
method: "setVisibility", method: "setVisibility",
data: false data: false
}) })
) )
SetNuiFocus(false, false) SetNuiFocus(false, false)
phoneCloseAnim() phoneCloseAnim()
}
} }
} }
RegisterCommand('phone', function(source) { //-- Toggles Phone RegisterCommand('phone', () => { //-- Toggles Phone
Phone() Phone()
}, false) }, false)
// Need to add the contacts file before even doing this
//RegisterNetEvent('phone:send')
//AddEventHandler('phone:send', function()
// TriggerEvent('phone:sendContacts')
//end)
RegisterNuiCallbackType('phone:close'); RegisterNuiCallbackType('phone:close');
on(`__cfx_nui:phone:close`, () => { on(`__cfx_nui:phone:close`, () => {
Phone(); Phone();
}) // //Called for when the phone is closed via the UI. }) // Called for when the phone is closed via the UI.
AddEventHandler('onResourceStop', function(resource: string) {
// Will take care of this later on the other branch if (resource === GetCurrentResourceName()) {
//RegisterNetEvent('phone:sendCredentials')
//AddEventHandler('phone:sendCredentials', function(number)
// print(number)
// SendNUIMessage(
// {
// app = "SIMCARD",
// method = "setNumber",
// data = number
// }
// )
//end)
AddEventHandler('onResourceStop', function(resource) {
if (resource == GetCurrentResourceName()) {
SendNuiMessage( SendNuiMessage(
JSON.stringify({ JSON.stringify({
app: 'PHONE', app: 'PHONE',
@@ -296,54 +257,32 @@ AddEventHandler('onResourceStop', function(resource) {
// //
//Phone Destory When Wet //Phone Destory When Wet
// //
function countPhone(cb: any) {
async function countPhone(cb: any) { if (ESX === null) return cb(0)
if (ESX == null) return cb(0) ESX.TriggerServerCallback('phone:getItemAmount', (qtty: number) => {
const qtty = await ESX.TriggerServerCallback('phone:getItemAmount', 'phone'); cb(qtty > 0);
cb(qtty > 0); }, 'phone');
} }
let destroyedPhone = false let destroyedPhone = false
let SwimDestroy = false;
setTick(() => { setTick(() => {
while (SwimDestroy) { while (config.SwimDestroy) {
Wait(10 * 1000); Wait(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 <= 100) { if (chance <= config.DestoryChance) {
countPhone((countPhone: boolean) => { countPhone((countPhone: boolean) => {
if (countPhone == true) { if (countPhone) {
ESX.ShowNotification('Your phone is ruined from the water!') ESX.ShowNotification('Your phone is ruined from the water!')
destroyedPhone = true destroyedPhone = true
} }
}) })
} }
if (destroyedPhone == true) { if (destroyedPhone) {
Wait(3 * 60000) Wait(config.DestroyPhoneReCheck * 60000)
} }
} }
} }
}) })
//Citizen.CreateThread(function()
// while Config.SwimDestroy do -- Checks if phone should destroy while swimming.
// Citizen.Wait(Config.RunRate * 1000) -- Checks how often the player is swimming x * 1 second.
// if IsPedSwimming(GetPlayerPed(-1)) then
// local chance = GetRandomIntInRange(0, 100)
// if chance <= Config.DestoryChance then -- Chance of destroying the phone.
// countPhone(function (countPhone)
// if countPhone == true then
// --print("Phone destroyed")
// ESX.ShowNotification('Your phone is ruined from the water!')
// destroyedPhone = true
// end
// end)
// end
// if destroyedPhone == true then -- If the phone was destroyed earlier then we will wait to check again.
// Wait(Config.DestroyPhoneReCheck * 60000) -- Waits x * 1 minute before checking again because it's pointless to re check.
// end
// end
// end
//end)
+2
View File
@@ -1,6 +1,8 @@
import { ESXClient } from "fivem-esx-js/client/esx_client"; import { ESXClient } from "fivem-esx-js/client/esx_client";
import './cl_main';
import './cl_twitter'; import './cl_twitter';
let ESX: ESXClient = null; let ESX: ESXClient = null;
setTick(() => { setTick(() => {