Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring code for Scaleform movie queries and 3D text drawing #1259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions [core]/es_extended/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ ESX.UI.Menu.RegisteredTypes = {}
ESX.UI.Menu.Opened = {}

ESX.Game = {}
ESX.Game.Utils = {}

ESX.Scaleform = {}
ESX.Scaleform.Utils = {}

ESX.Streaming = {}

function ESX.IsPlayerLoaded()
Expand All @@ -27,17 +23,17 @@ end
function ESX.SearchInventory(items, count)
items = type(items) == 'string' and { items } or items

local data = {}
for i=1, #items do
for c=1, #ESX.PlayerData.inventory do
if ESX.PlayerData.inventory[c].name == items[i] then
local data = {}
for i=1, #items do
for c=1, #ESX.PlayerData.inventory do
if ESX.PlayerData.inventory[c].name == items[i] then
data[items[i]] = (count and ESX.PlayerData.inventory[c].count) or ESX.PlayerData.inventory[c]
end
end
end
end
end
end

return #items == 1 and data[items[1]] or data
end
end

function ESX.SetPlayerData(key, val)
local current = ESX.PlayerData[key]
Expand Down Expand Up @@ -323,7 +319,7 @@ end

function ESX.Game.SpawnObject(object, coords, cb, networked)
networked = networked == nil and true or networked

local model = type(object) == 'number' and object or joaat(object)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
CreateThread(function()
Expand Down Expand Up @@ -365,7 +361,7 @@ function ESX.Game.SpawnVehicle(vehicleModel, coords, heading, cb, networked)
local executingResource = GetInvokingResource() or "Unknown"
return print(("[^1ERROR^7] Resource ^5%s^7 Tried to spawn vehicle on the client but the position is too far away (Out of onesync range)."):format(executingResource))
end

CreateThread(function()
ESX.Streaming.RequestModel(model)

Expand Down Expand Up @@ -411,14 +407,14 @@ function ESX.Game.GetPeds(onlyOtherPeds)
local pool = GetGamePool('CPed')

if onlyOtherPeds then
local myPed = ESX.PlayerData.ped
local myPed = ESX.PlayerData.ped
for i = 1, #pool do
if pool[i] == myPed then
table.remove(pool, i)
break
table.remove(pool, i)
break
end
end
end
end

return pool
end
Expand All @@ -429,20 +425,20 @@ end

function ESX.Game.GetPlayers(onlyOtherPlayers, returnKeyValue, returnPeds)
local players, myPlayer = {}, PlayerId()
local active = GetActivePlayers()
local active = GetActivePlayers()

for i=1, #active do
for i=1, #active do
local currentPlayer = active[i]
local ped = GetPlayerPed(currentPlayer)
local ped = GetPlayerPed(currentPlayer)

if DoesEntityExist(ped) and ((onlyOtherPlayers and currentPlayer ~= myPlayer) or not onlyOtherPlayers) then
if returnKeyValue then
players[currentPlayer] = ped
else
if DoesEntityExist(ped) and ((onlyOtherPlayers and currentPlayer ~= myPlayer) or not onlyOtherPlayers) then
if returnKeyValue then
players[currentPlayer] = ped
else
players[#players + 1] = returnPeds and ped or currentPlayer
end
end
end
end
end

return players
end
Expand Down Expand Up @@ -961,14 +957,14 @@ function ESX.Game.SetVehicleProperties(vehicle, props)
end
end

function ESX.Game.Utils.DrawText3D(coords, text, size, font)
function ESX.Game.DrawText3D(coords, text, size, font)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)

local camCoords = GetFinalRenderedCamCoord()
local distance = #(vector - camCoords)

size = size or 1
font = font or 0
font = font or 0

local scale = (size / distance) * 2
local fov = (1 / GetGameplayCamFov()) * 100
Expand Down Expand Up @@ -1026,9 +1022,9 @@ function ESX.ShowInventory()
end
end

for i=1, #ESX.PlayerData.inventory do
for i=1, #ESX.PlayerData.inventory do
local v = ESX.PlayerData.inventory[i]
if v.count > 0 then
if v.count > 0 then
currentWeight = currentWeight + (v.weight * v.count)

elements[#elements + 1] = {
Expand All @@ -1041,8 +1037,8 @@ function ESX.ShowInventory()
rare = v.rare,
canRemove = v.canRemove
}
end
end
end
end

elements[1].title = TranslateCap('inventory', currentWeight, Config.MaxWeight)

Expand Down
10 changes: 5 additions & 5 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,13 @@ if not Config.OxInventory then

RegisterNetEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(item, count, showNotification)
for i=1, #ESX.PlayerData.inventory do
if ESX.PlayerData.inventory[i].name == item then
for i=1, #ESX.PlayerData.inventory do
if ESX.PlayerData.inventory[i].name == item then
ESX.UI.ShowInventoryItemNotification(false, ESX.PlayerData.inventory[i].label, ESX.PlayerData.inventory[i].count - count)
ESX.PlayerData.inventory[i].count = count
break
end
end
end
end

if showNotification then
ESX.UI.ShowInventoryItemNotification(false, item, count)
Expand Down Expand Up @@ -501,7 +501,7 @@ if not Config.OxInventory then
label = ('%s~n~%s'):format(label, TranslateCap('threw_pickup_prompt'))
end

ESX.Game.Utils.DrawText3D({
ESX.Game.DrawText3D({
x = pickup.coords.x,
y = pickup.coords.y,
z = pickup.coords.z + 0.25
Expand Down
28 changes: 14 additions & 14 deletions [core]/es_extended/client/modules/scaleform.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
local function requestScaleformMovie(movie)
local scaleform = RequestScaleformMovie(movie)

while not HasScaleformMovieLoaded(scaleform) do
Wait(0)
end

return scaleform
end

function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('MP_BIG_MESSAGE_FREEMODE')
local scaleform = requestScaleformMovie('MP_BIG_MESSAGE_FREEMODE')

BeginScaleformMovieMethod(scaleform, 'SHOW_SHARD_WASTED_MP_MESSAGE')
ScaleformMovieMethodAddParamTextureNameString(title)
Expand All @@ -17,7 +27,7 @@ function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec)
end

function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('BREAKING_NEWS')
local scaleform = requestScaleformMovie('BREAKING_NEWS')

BeginScaleformMovieMethod(scaleform, 'SET_TEXT')
ScaleformMovieMethodAddParamTextureNameString(msg)
Expand Down Expand Up @@ -48,7 +58,7 @@ function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec)
end

function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('POPUP_WARNING')
local scaleform = requestScaleformMovie('POPUP_WARNING')

BeginScaleformMovieMethod(scaleform, 'SHOW_POPUP_WARNING')

Expand All @@ -71,7 +81,7 @@ function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec)
end

function ESX.Scaleform.ShowTrafficMovie(sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('TRAFFIC_CAM')
local scaleform = requestScaleformMovie('TRAFFIC_CAM')

BeginScaleformMovieMethod(scaleform, 'PLAY_CAM_MOVIE')

Expand All @@ -86,13 +96,3 @@ function ESX.Scaleform.ShowTrafficMovie(sec)

SetScaleformMovieAsNoLongerNeeded(scaleform)
end

function ESX.Scaleform.Utils.RequestScaleformMovie(movie)
local scaleform = RequestScaleformMovie(movie)

while not HasScaleformMovieLoaded(scaleform) do
Wait(0)
end

return scaleform
end