mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Feat(Animations): Added animations and hopefully prevented car yeeting.
Added some additional documentation and default mouse pointer but it needs to be scaled to screen resolution eventually so they all start on a certain one. Car may still flip around depending on how the phone prop is created. but I tried to midigate it the best I could without adding a citizen wait to phone creation.
This commit is contained in:
1 parent
eae8d317bd
commit
dd548fa745
1 file changed
+107
-40
+107
-40
@@ -8,6 +8,7 @@ Citizen.CreateThread(function()
|
||||
end)
|
||||
|
||||
RegisterCommand('phone:close', function(source, args, rawCommand)
|
||||
phoneCloseAnim()
|
||||
SendNUIMessage({
|
||||
app = 'PHONE',
|
||||
method = 'setVisibility',
|
||||
@@ -18,25 +19,22 @@ end, false)
|
||||
-----
|
||||
--END OF ESX
|
||||
-----
|
||||
local prop = 0
|
||||
local isPhoneOpen = false
|
||||
local phoneModel = "prop_amb_phone"
|
||||
--RegisterKeyMapping('phone', _U('keymap_phone'), 'keyboard', '')
|
||||
|
||||
--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)
|
||||
riggerServerEvent('phone:server:getCredentials')
|
||||
end, false)]]
|
||||
|
||||
function loadAnimDict(dict)
|
||||
while ( not HasAnimDictLoaded(dict)) do
|
||||
RequestAnimDict(dict)
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
end
|
||||
-----
|
||||
--Start of Phone
|
||||
----
|
||||
local prop = 0
|
||||
local isPhoneOpen = false
|
||||
local phoneModel = "prop_amb_phone" -- Refered to in newphoneProp function. Requires custom phone being streamed.
|
||||
|
||||
function newPhoneProp()
|
||||
deletePhone()
|
||||
DeleteObject(prop)
|
||||
function newPhoneProp() -- Function for creating the phone prop
|
||||
deletePhone() -- deletes the already existing prop before creating another.
|
||||
RequestModel(phoneModel)
|
||||
while not HasModelLoaded(phoneModel) do
|
||||
Citizen.Wait(1)
|
||||
@@ -46,33 +44,83 @@ function newPhoneProp()
|
||||
local x,y,z = table.unpack(GetEntityCoords(playerPed))
|
||||
prop = CreateObject(GetHashKey(phoneModel), x, y, z + 0.2, true, true, true)
|
||||
local boneIndex = GetPedBoneIndex(playerPed, 28422)
|
||||
AttachEntityToEntity(prop, playerPed, boneIndex, 28422, 0.0, 0.0, 0.0, 0.0, 0.0, -.0, true, true, false, true, 1, true)
|
||||
AttachEntityToEntity(prop, playerPed, boneIndex, 28422, 0.0, 0.0, 0.0, 0.0, 0.0, -.0, true, true, false, true, 1, true) -- Attaches the phone to the player.
|
||||
end
|
||||
|
||||
function phoneAnim()
|
||||
loadAnimDict('cellphone@')
|
||||
TaskPlayAnim(GetPlayerPed(-1), 'cellphone@', 'cellphone_text_in', 9.0, -1, -1, 50, 0, false, false, false)
|
||||
function loadAnimDict(dict) -- Loads the animation dict. Used in the anim functions.
|
||||
while ( not HasAnimDictLoaded(dict)) do
|
||||
RequestAnimDict(dict)
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
end
|
||||
|
||||
--function deleteProp()
|
||||
-- print(prop)
|
||||
-- if prop ~= 0 then
|
||||
-- DeleteObject(prop)
|
||||
-- ClearAllPedProps(prop)
|
||||
-- prop = 0
|
||||
-- end
|
||||
--end
|
||||
function phoneOpenAnim() --Phone Open Animation
|
||||
local 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) then -- true refers to at get in.
|
||||
local dict = 'anim@cellphone@in_car@ps'
|
||||
local kek = "pepein"
|
||||
|
||||
--print(dict)
|
||||
--print(kek)
|
||||
ClearPedTasks(GetPlayerPed(-1))
|
||||
loadAnimDict(dict)
|
||||
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
|
||||
newPhoneProp() -- Creates the phone and attaches it.
|
||||
else -- While not in a vehicle it will use this dict.
|
||||
local dict = 'cellphone@'
|
||||
local kek = "pepeout"
|
||||
|
||||
function deletePhone()
|
||||
--print(dict)
|
||||
--print(kek)
|
||||
ClearPedTasks(GetPlayerPed(-1))
|
||||
loadAnimDict(dict)
|
||||
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
|
||||
newPhoneProp() -- Creates the phone and attaches it.
|
||||
end
|
||||
end
|
||||
|
||||
function phoneCloseAnim() --Phone Close Animation
|
||||
local flag = 50 -- https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||
local anim = 'cellphone_text_out'
|
||||
if IsPedInAnyVehicle(GetPlayerPed(-1), true) then -- true refers to at get in.
|
||||
local dict = 'anim@cellphone@in_car@ps'
|
||||
local kek = "pepein"
|
||||
|
||||
--print(dict)
|
||||
--print(kek)
|
||||
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.
|
||||
Wait(250) -- lets it get to a certain point
|
||||
loadAnimDict(dict) -- loads the new animation
|
||||
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
|
||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) -- clears the animation
|
||||
else -- While not in a vehicle it will use this dict.
|
||||
local dict = 'cellphone@'
|
||||
local kek = "pepeout"
|
||||
|
||||
--print(dict)
|
||||
--print(kek)
|
||||
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) -- Stop the pull out animation
|
||||
Wait(100) -- lets it get to a certain point
|
||||
loadAnimDict(dict) -- loads the new animation
|
||||
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
|
||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) -- clears the animation
|
||||
deletePhone() -- Deletes the prop.
|
||||
end
|
||||
end
|
||||
|
||||
function deletePhone() -- Triggered in newphoneProp function. Only way to destory the prop correctly.
|
||||
if prop ~= 0 then
|
||||
Citizen.InvokeNative(0xAE3CBE5BF394C9C9 , Citizen.PointerValueIntInitialized(prop))
|
||||
prop = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
@@ -80,9 +128,10 @@ Citizen.CreateThread(function()
|
||||
if isPhoneOpen == false then
|
||||
isPhoneOpen = true
|
||||
print(Config.KeyTogglePhone) --Left for testing purposes.
|
||||
newPhoneProp()
|
||||
phoneAnim()
|
||||
|
||||
phoneOpenAnim()
|
||||
SetCursorLocation(0.936, 0.922) -- Experimental
|
||||
local res = GetActiveScreenResolution()
|
||||
--print(res)
|
||||
SendNUIMessage( -- Shows phone
|
||||
{
|
||||
app = 'PHONE',
|
||||
@@ -95,8 +144,8 @@ Citizen.CreateThread(function()
|
||||
elseif isPhoneOpen == true then
|
||||
isPhoneOpen = false
|
||||
print(Config.KeyTogglePhone) --Left for testing purposes.
|
||||
ClearPedTasksImmediately(GetPlayerPed(-1))
|
||||
deletePhone()
|
||||
phoneCloseAnim()
|
||||
|
||||
SendNUIMessage( -- Hides phone
|
||||
{
|
||||
app = 'PHONE',
|
||||
@@ -113,9 +162,12 @@ end)
|
||||
RegisterCommand('phone', function(source) -- Toggles Phone
|
||||
if isPhoneOpen == false then
|
||||
isPhoneOpen = true
|
||||
phoneAnim()
|
||||
phoneOpenAnim()
|
||||
print("phone is now open") --Left for testing purposes.
|
||||
TriggerServerEvent('phone:getCredentials', source)
|
||||
SetCursorLocation(0.936, 0.922) -- Experimental
|
||||
local res = GetActiveScreenResolution()
|
||||
--print(res)
|
||||
SendNUIMessage( -- Shows phone
|
||||
{
|
||||
app = 'PHONE',
|
||||
@@ -135,7 +187,7 @@ RegisterCommand('phone', function(source) -- Toggles Phone
|
||||
}
|
||||
)
|
||||
SetNuiFocus(false, false)
|
||||
ClearPedTasksImmediately(GetPlayerPed(-1))
|
||||
phoneCloseAnim()
|
||||
end
|
||||
end, false)
|
||||
|
||||
@@ -145,7 +197,7 @@ AddEventHandler('phone:send', function()
|
||||
TriggerEvent('phone:sendContacts')
|
||||
end)
|
||||
|
||||
RegisterNUICallback('phone:close', function()
|
||||
RegisterNUICallback('phone:close', function() -- Called for when the phone is closed via the UI.
|
||||
isPhoneOpen = false
|
||||
SendNUIMessage(
|
||||
{
|
||||
@@ -155,8 +207,7 @@ RegisterNUICallback('phone:close', function()
|
||||
}
|
||||
)
|
||||
SetNuiFocus(false, false)
|
||||
ClearPedTasksImmediately(GetPlayerPed(-1))
|
||||
deletePhone()
|
||||
phoneCloseAnim() -- Closes the phone and deletes the prop.
|
||||
end)
|
||||
|
||||
RegisterNetEvent('phone:sendCredentials')
|
||||
@@ -169,4 +220,20 @@ AddEventHandler('phone:sendCredentials', function(number)
|
||||
data = number
|
||||
}
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
AddEventHandler('onResourceStop', function(resource)
|
||||
if resource == GetCurrentResourceName() then
|
||||
SendNUIMessage(
|
||||
{
|
||||
app = 'PHONE',
|
||||
method = 'setVisibility',
|
||||
data = false
|
||||
}
|
||||
)
|
||||
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.
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in new issue
Block a user