mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +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
+106
-39
+106
-39
@@ -8,6 +8,7 @@ Citizen.CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterCommand('phone:close', function(source, args, rawCommand)
|
RegisterCommand('phone:close', function(source, args, rawCommand)
|
||||||
|
phoneCloseAnim()
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
app = 'PHONE',
|
app = 'PHONE',
|
||||||
method = 'setVisibility',
|
method = 'setVisibility',
|
||||||
@@ -18,25 +19,22 @@ end, false)
|
|||||||
-----
|
-----
|
||||||
--END OF ESX
|
--END OF ESX
|
||||||
-----
|
-----
|
||||||
local prop = 0
|
|
||||||
local isPhoneOpen = false
|
--RegisterKeyMapping('phone', _U('keymap_phone'), 'keyboard', '') -- Lets people set a keybind for the phone command but can't be implemented yet.
|
||||||
local phoneModel = "prop_amb_phone"
|
|
||||||
--RegisterKeyMapping('phone', _U('keymap_phone'), 'keyboard', '')
|
|
||||||
|
|
||||||
--[[RegisterCommand('phone:get', function(source, args, rawCommand)
|
--[[RegisterCommand('phone:get', function(source, args, rawCommand)
|
||||||
riggerServerEvent('phone:server:getCredentials')
|
riggerServerEvent('phone:server:getCredentials')
|
||||||
end, false)]]
|
end, false)]]
|
||||||
|
|
||||||
function loadAnimDict(dict)
|
-----
|
||||||
while ( not HasAnimDictLoaded(dict)) do
|
--Start of Phone
|
||||||
RequestAnimDict(dict)
|
----
|
||||||
Citizen.Wait(0)
|
local prop = 0
|
||||||
end
|
local isPhoneOpen = false
|
||||||
end
|
local phoneModel = "prop_amb_phone" -- Refered to in newphoneProp function. Requires custom phone being streamed.
|
||||||
|
|
||||||
function newPhoneProp()
|
function newPhoneProp() -- Function for creating the phone prop
|
||||||
deletePhone()
|
deletePhone() -- deletes the already existing prop before creating another.
|
||||||
DeleteObject(prop)
|
|
||||||
RequestModel(phoneModel)
|
RequestModel(phoneModel)
|
||||||
while not HasModelLoaded(phoneModel) do
|
while not HasModelLoaded(phoneModel) do
|
||||||
Citizen.Wait(1)
|
Citizen.Wait(1)
|
||||||
@@ -46,33 +44,83 @@ function newPhoneProp()
|
|||||||
local x,y,z = table.unpack(GetEntityCoords(playerPed))
|
local x,y,z = table.unpack(GetEntityCoords(playerPed))
|
||||||
prop = CreateObject(GetHashKey(phoneModel), x, y, z + 0.2, true, true, true)
|
prop = CreateObject(GetHashKey(phoneModel), x, y, z + 0.2, true, true, true)
|
||||||
local boneIndex = GetPedBoneIndex(playerPed, 28422)
|
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
|
end
|
||||||
|
|
||||||
function phoneAnim()
|
function loadAnimDict(dict) -- Loads the animation dict. Used in the anim functions.
|
||||||
loadAnimDict('cellphone@')
|
while ( not HasAnimDictLoaded(dict)) do
|
||||||
TaskPlayAnim(GetPlayerPed(-1), 'cellphone@', 'cellphone_text_in', 9.0, -1, -1, 50, 0, false, false, false)
|
RequestAnimDict(dict)
|
||||||
|
Citizen.Wait(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--function deleteProp()
|
function phoneOpenAnim() --Phone Open Animation
|
||||||
-- print(prop)
|
local flag = 50 -- https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||||
-- if prop ~= 0 then
|
deletePhone() -- Deleting before creating a new phone where itll be deleted again.
|
||||||
-- DeleteObject(prop)
|
if IsPedInAnyVehicle(GetPlayerPed(-1), true) then -- true refers to at get in.
|
||||||
-- ClearAllPedProps(prop)
|
local dict = 'anim@cellphone@in_car@ps'
|
||||||
-- prop = 0
|
local kek = "pepein"
|
||||||
-- end
|
|
||||||
--end
|
|
||||||
|
|
||||||
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.
|
||||||
|
else -- While not in a vehicle it will use this dict.
|
||||||
|
local dict = 'cellphone@'
|
||||||
|
local kek = "pepeout"
|
||||||
|
|
||||||
|
--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
|
if prop ~= 0 then
|
||||||
Citizen.InvokeNative(0xAE3CBE5BF394C9C9 , Citizen.PointerValueIntInitialized(prop))
|
Citizen.InvokeNative(0xAE3CBE5BF394C9C9 , Citizen.PointerValueIntInitialized(prop))
|
||||||
prop = 0
|
prop = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
Citizen.Wait(0)
|
Citizen.Wait(0)
|
||||||
@@ -80,9 +128,10 @@ Citizen.CreateThread(function()
|
|||||||
if isPhoneOpen == false then
|
if isPhoneOpen == false then
|
||||||
isPhoneOpen = true
|
isPhoneOpen = true
|
||||||
print(Config.KeyTogglePhone) --Left for testing purposes.
|
print(Config.KeyTogglePhone) --Left for testing purposes.
|
||||||
newPhoneProp()
|
phoneOpenAnim()
|
||||||
phoneAnim()
|
SetCursorLocation(0.936, 0.922) -- Experimental
|
||||||
|
local res = GetActiveScreenResolution()
|
||||||
|
--print(res)
|
||||||
SendNUIMessage( -- Shows phone
|
SendNUIMessage( -- Shows phone
|
||||||
{
|
{
|
||||||
app = 'PHONE',
|
app = 'PHONE',
|
||||||
@@ -95,8 +144,8 @@ Citizen.CreateThread(function()
|
|||||||
elseif isPhoneOpen == true then
|
elseif isPhoneOpen == true then
|
||||||
isPhoneOpen = false
|
isPhoneOpen = false
|
||||||
print(Config.KeyTogglePhone) --Left for testing purposes.
|
print(Config.KeyTogglePhone) --Left for testing purposes.
|
||||||
ClearPedTasksImmediately(GetPlayerPed(-1))
|
phoneCloseAnim()
|
||||||
deletePhone()
|
|
||||||
SendNUIMessage( -- Hides phone
|
SendNUIMessage( -- Hides phone
|
||||||
{
|
{
|
||||||
app = 'PHONE',
|
app = 'PHONE',
|
||||||
@@ -113,9 +162,12 @@ end)
|
|||||||
RegisterCommand('phone', function(source) -- Toggles Phone
|
RegisterCommand('phone', function(source) -- Toggles Phone
|
||||||
if isPhoneOpen == false then
|
if isPhoneOpen == false then
|
||||||
isPhoneOpen = true
|
isPhoneOpen = true
|
||||||
phoneAnim()
|
phoneOpenAnim()
|
||||||
print("phone is now open") --Left for testing purposes.
|
print("phone is now open") --Left for testing purposes.
|
||||||
TriggerServerEvent('phone:getCredentials', source)
|
TriggerServerEvent('phone:getCredentials', source)
|
||||||
|
SetCursorLocation(0.936, 0.922) -- Experimental
|
||||||
|
local res = GetActiveScreenResolution()
|
||||||
|
--print(res)
|
||||||
SendNUIMessage( -- Shows phone
|
SendNUIMessage( -- Shows phone
|
||||||
{
|
{
|
||||||
app = 'PHONE',
|
app = 'PHONE',
|
||||||
@@ -135,7 +187,7 @@ RegisterCommand('phone', function(source) -- Toggles Phone
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
ClearPedTasksImmediately(GetPlayerPed(-1))
|
phoneCloseAnim()
|
||||||
end
|
end
|
||||||
end, false)
|
end, false)
|
||||||
|
|
||||||
@@ -145,7 +197,7 @@ AddEventHandler('phone:send', function()
|
|||||||
TriggerEvent('phone:sendContacts')
|
TriggerEvent('phone:sendContacts')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('phone:close', function()
|
RegisterNUICallback('phone:close', function() -- Called for when the phone is closed via the UI.
|
||||||
isPhoneOpen = false
|
isPhoneOpen = false
|
||||||
SendNUIMessage(
|
SendNUIMessage(
|
||||||
{
|
{
|
||||||
@@ -155,8 +207,7 @@ RegisterNUICallback('phone:close', function()
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
ClearPedTasksImmediately(GetPlayerPed(-1))
|
phoneCloseAnim() -- Closes the phone and deletes the prop.
|
||||||
deletePhone()
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('phone:sendCredentials')
|
RegisterNetEvent('phone:sendCredentials')
|
||||||
@@ -170,3 +221,19 @@ AddEventHandler('phone:sendCredentials', function(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