Skip to content

Commit

Permalink
feat(client): Utilize ox_lib cache system (#263)
Browse files Browse the repository at this point in the history
* Utilize ox lib cache system

* idk what happened here

* update stuff

* Reverse this again

idk why this one dont like me

* Update client.lua
  • Loading branch information
FjamZoo authored Mar 4, 2023
1 parent 37974ae commit c2c73df
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 144 deletions.
2 changes: 1 addition & 1 deletion client/blips.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ local function ShowNearestShopBlip()
Blips[k] = 0
end
while true do
local coords = GetEntityCoords(PlayerPedId())
local coords = GetEntityCoords(cache.ped)
for shopType, blipConfig in pairs(Config.Blips) do
local closest = 1000000
local closestCoords
Expand Down
52 changes: 22 additions & 30 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ end
function SetInitialClothes(initial)
client.setPlayerModel(initial.Model)
-- Fix for tattoo's appearing when creating a new character
local ped = PlayerPedId()
local ped = cache.ped
client.setPedTattoos(ped, {})
client.setPedComponents(ped, initial.Components)
client.setPedProps(ped, initial.Props)
Expand Down Expand Up @@ -393,7 +393,7 @@ RegisterNetEvent("illenium-appearance:client:saveOutfit", function()
end

local outfitName = response[1]
if outfitName ~= nil then
if outfitName then
Wait(500)
lib.callback("illenium-appearance:server:getOutfits", false, function(outfits)
local outfitExists = false
Expand All @@ -414,10 +414,9 @@ RegisterNetEvent("illenium-appearance:client:saveOutfit", function()
return
end

local playerPed = PlayerPedId()
local pedModel = client.getPedModel(playerPed)
local pedComponents = client.getPedComponents(playerPed)
local pedProps = client.getPedProps(playerPed)
local pedModel = client.getPedModel(cache.ped)
local pedComponents = client.getPedComponents(cache.ped)
local pedProps = client.getPedProps(cache.ped)

TriggerServerEvent("illenium-appearance:server:saveOutfit", outfitName, pedModel, pedComponents, pedProps)
end)
Expand All @@ -426,7 +425,7 @@ end)

RegisterNetEvent('illenium-appearance:client:updateOutfit', function(outfitID)
if not outfitID then return end

lib.callback("illenium-appearance:server:getOutfits", false, function(outfits)
local outfitExists = false
for i = 1, #outfits, 1 do
Expand All @@ -446,10 +445,9 @@ RegisterNetEvent('illenium-appearance:client:updateOutfit', function(outfitID)
return
end

local playerPed = PlayerPedId()
local pedModel = client.getPedModel(playerPed)
local pedComponents = client.getPedComponents(playerPed)
local pedProps = client.getPedProps(playerPed)
local pedModel = client.getPedModel(cache.ped)
local pedComponents = client.getPedComponents(cache.ped)
local pedProps = client.getPedProps(cache.ped)

TriggerServerEvent("illenium-appearance:server:updateOutfit", outfitID, pedModel, pedComponents, pedProps)
end)
Expand Down Expand Up @@ -481,7 +479,7 @@ local function RegisterChangeOutfitMenu(id, parent, outfits, mType)
table.sort(changeOutfitMenu.options, function(a, b)
return a.title < b.title
end)

lib.registerContext(changeOutfitMenu)
end

Expand All @@ -504,7 +502,7 @@ local function RegisterUpdateOutfitMenu(id, parent, outfits)
table.sort(updateOutfitMenu.options, function(a, b)
return a.title < b.title
end)

lib.registerContext(updateOutfitMenu)
end

Expand Down Expand Up @@ -597,12 +595,11 @@ RegisterNetEvent("illenium-appearance:client:OutfitManagementMenu", function(arg
end)

RegisterNetEvent("illenium-appearance:client:SaveManagementOutfit", function(mType)
local playerPed = PlayerPedId()
local outfitData = {
Type = mType,
Model = client.getPedModel(playerPed),
Components = client.getPedComponents(playerPed),
Props = client.getPedProps(playerPed)
Model = client.getPedModel(cache.ped),
Components = client.getPedComponents(cache.ped),
Props = client.getPedProps(cache.ped)
}

local rankValues
Expand Down Expand Up @@ -791,8 +788,7 @@ RegisterNetEvent("illenium-appearance:client:OpenSurgeonShop", function()
end)

RegisterNetEvent("illenium-appearance:client:changeOutfit", function(data)
local playerPed = PlayerPedId()
local pedModel = client.getPedModel(playerPed)
local pedModel = client.getPedModel(cache.ped)
local appearanceDB
if pedModel ~= data.model then
local p = promise.new()
Expand All @@ -813,21 +809,20 @@ RegisterNetEvent("illenium-appearance:client:changeOutfit", function(data)
end, data.model)
appearanceDB = Citizen.Await(p)
else
appearanceDB = client.getPedAppearance(playerPed)
appearanceDB = client.getPedAppearance(cache.ped)
end
if appearanceDB then
playerPed = PlayerPedId()
client.setPedComponents(playerPed, data.components)
client.setPedProps(playerPed, data.props)
client.setPedHair(playerPed, appearanceDB.hair, appearanceDB.tattoos)
client.setPedComponents(cache.ped, data.components)
client.setPedProps(cache.ped, data.props)
client.setPedHair(cache.ped, appearanceDB.hair, appearanceDB.tattoos)

if data.disableSave then
TriggerServerEvent("illenium-appearance:server:syncUniform", {
type = data.type,
name = data.name
}) -- Is a uniform
else
local appearance = client.getPedAppearance(playerPed)
local appearance = client.getPedAppearance(cache.ped)
TriggerServerEvent("illenium-appearance:server:saveAppearance", appearance)
end
Framework.CachePed()
Expand Down Expand Up @@ -863,9 +858,7 @@ local function InCooldown()
end

RegisterNetEvent("illenium-appearance:client:reloadSkin", function()
local playerPed = PlayerPedId()

if InCooldown() or Framework.CheckPlayerMeta() or IsPedInAnyVehicle(playerPed, true) or IsPedFalling(playerPed) then
if InCooldown() or Framework.CheckPlayerMeta() or cache.vehicle or IsPedFalling(cache.ped) then
lib.notify({
title = _L("commands.reloadskin.failure.title"),
description = _L("commands.reloadskin.failure.description"),
Expand Down Expand Up @@ -902,10 +895,9 @@ RegisterNetEvent("illenium-appearance:client:ClearStuckProps", function()
end

reloadSkinTimer = GetGameTimer()
local playerPed = PlayerPedId()

for _, v in pairs(GetGamePool("CObject")) do
if IsEntityAttachedToEntity(playerPed, v) then
if IsEntityAttachedToEntity(cache.ped, v) then
SetEntityAsMissionEntity(v, true, true)
DeleteObject(v)
DeleteEntity(v)
Expand Down
9 changes: 4 additions & 5 deletions client/framework/esx/compatibility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ RegisterNetEvent("skinchanger:loadSkin", function(skin, cb)
end)

RegisterNetEvent("skinchanger:loadClothes", function(_, clothes)
local playerPed = PlayerPedId()
local components = Framework.ConvertComponents(clothes, client.getPedComponents(playerPed))
local props = Framework.ConvertProps(clothes, client.getPedProps(playerPed))
local components = Framework.ConvertComponents(clothes, client.getPedComponents(cache.ped))
local props = Framework.ConvertProps(clothes, client.getPedProps(cache.ped))

client.setPedComponents(playerPed, components)
client.setPedProps(playerPed, props)
client.setPedComponents(cache.ped, components)
client.setPedProps(cache.ped, props)
end)

RegisterNetEvent("esx_skin:openSaveableMenu", function(onSubmit, onCancel)
Expand Down
2 changes: 1 addition & 1 deletion client/framework/esx/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Framework.GetGangGrade()
end

function Framework.CachePed()
ESX.SetPlayerData("ped", PlayerPedId())
ESX.SetPlayerData("ped", cache.ped)
end

function Framework.RestorePlayerArmour()
Expand Down
2 changes: 1 addition & 1 deletion client/framework/framework.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function Framework.GetGender(isNew)
return Framework.GetPlayerGender()
end

local model = client.getPedModel(PlayerPedId())
local model = client.getPedModel(cache.ped)
if model == "mp_f_freemode_01" then
return "Female"
end
Expand Down
5 changes: 2 additions & 3 deletions client/framework/qb/compatibility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ end)
RegisterNetEvent("qb-clothing:client:loadOutfit", LoadJobOutfit)

RegisterNetEvent("qb-multicharacter:client:chooseChar", function()
local ped = PlayerPedId()
client.setPedTattoos(ped, {})
ClearPedDecorations(ped)
client.setPedTattoos(cache.ped, {})
ClearPedDecorations(cache.ped)

TriggerServerEvent("illenium-appearance:server:resetOutfitCache")
end)
3 changes: 1 addition & 2 deletions client/framework/qb/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ end
function Framework.RestorePlayerArmour()
if PlayerData then
Wait(1000)
local playerPed = PlayerPedId()
SetPedArmour(playerPed, PlayerData.metadata["armor"])
SetPedArmour(cache.ped, PlayerData.metadata["armor"])
end
end
15 changes: 6 additions & 9 deletions client/framework/qb/migrate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ RegisterNetEvent("illenium-appearance:client:migration:load-qb-clothing-skin", f
local model = playerSkin.model
model = model ~= nil and tonumber(model) or false
Citizen.CreateThread(function()
RequestModel(model)
while not HasModelLoaded(model) do
RequestModel(model)
Citizen.Wait(0)
end
SetPlayerModel(PlayerId(), model)
SetPedComponentVariation(PlayerPedId(), 0, 0, 0, 2)
TriggerEvent("illenium-appearance:client:migration:load-qb-clothing-clothes", playerSkin, PlayerPedId())
lib.requestModel(model, 1000)
SetPlayerModel(cache.playerId, model)
SetPedComponentVariation(cache.ped, 0, 0, 0, 2)
TriggerEvent("illenium-appearance:client:migration:load-qb-clothing-clothes", playerSkin, cache.ped)
SetModelAsNoLongerNeeded(model)
end)
end)

RegisterNetEvent("illenium-appearance:client:migration:load-qb-clothing-clothes", function(playerSkin, ped)
local data = json.decode(playerSkin.skin)
if ped == nil then ped = PlayerPedId() end
if ped == nil then ped = cache.ped end

for i = 0, 11 do
SetPedComponentVariation(ped, i, 0, 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion client/outfits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local function typeof(var)
end

function LoadJobOutfit(oData)
local ped = PlayerPedId()
local ped = cache.ped

local data = oData.outfitData

Expand Down
19 changes: 5 additions & 14 deletions client/props.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
if Config.AlwaysKeepProps then
local lastped = nil

CreateThread(function()
SetPedCanLosePropsOnDamage(PlayerPedId(), false, 0)
while true do
if PlayerPedId() ~= lastped then
lastped = PlayerPedId()
SetPedCanLosePropsOnDamage(PlayerPedId(), false, 0)
end
Wait(1000)
end
end)
end
lib.onCache('ped', function(value)
if Config.AlwaysKeepProps then
SetPedCanLosePropsOnDamage(value, false, 0)
end
end)
17 changes: 7 additions & 10 deletions client/stats.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
local stats = nil

local function ResetRechargeMultipliers()
local player = PlayerId()
SetPlayerHealthRechargeMultiplier(player, 0.0)
SetPlayerHealthRechargeLimit(player, 0.0)
SetPlayerHealthRechargeMultiplier(cache.playerId, 0.0)
SetPlayerHealthRechargeLimit(cache.playerId, 0.0)
end

function BackupPlayerStats()
local playerPed = PlayerPedId()
stats = {
health = GetEntityHealth(playerPed),
armour = GetPedArmour(playerPed)
health = GetEntityHealth(cache.ped),
armour = GetPedArmour(cache.ped)
}
end

function RestorePlayerStats()
if stats then
local playerPed = PlayerPedId()
SetEntityMaxHealth(playerPed, 200)
SetEntityMaxHealth(cache.ped, 200)
Wait(1000) -- Safety Delay
SetEntityHealth(playerPed, stats.health)
SetPedArmour(playerPed, stats.armour)
SetEntityHealth(cache.ped, stats.health)
SetPedArmour(cache.ped, stats.armour)
ResetRechargeMultipliers()
stats = nil
return
Expand Down
Loading

0 comments on commit c2c73df

Please sign in to comment.