Skip to content

Commit

Permalink
perf: table spawning & more
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyyy7666 committed Dec 3, 2023
1 parent e7db209 commit 5802460
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
8 changes: 0 additions & 8 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ cfg.tables = {
dealerHeading = 137.2609,
tablePos = vec3(1133.73, 266.694, -52.040),
tableHeading = -45.00,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01b`,
color = 3,
max = 50000,
Expand All @@ -27,7 +26,6 @@ cfg.tables = {
dealerHeading = 314.656,
tablePos = vec3(1129.406, 262.357, -52.0410),
tableHeading = 135.309,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01b`,
color = 3,
max = 50000,
Expand All @@ -40,7 +38,6 @@ cfg.tables = {
dealerHeading = 134.22,
tablePos = vec3(1148.739, 251.694, -52.040),
tableHeading = -45.00,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01b`,
color = 3,
max = 50000,
Expand All @@ -53,7 +50,6 @@ cfg.tables = {
dealerHeading = 314.16,
tablePos = vec3(1144.429, 247.335, -52.041),
tableHeading = 135.309,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01b`,
color = 3,
max = 50000,
Expand All @@ -67,7 +63,6 @@ cfg.tables = {
dealerHeading = 226.033,
tablePos = vec3(1146.329, 261.254, -52.841),
tableHeading = 45.00,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01`,
color = 0,
max = 1000,
Expand All @@ -79,7 +74,6 @@ cfg.tables = {
dealerHeading = 44.166,
tablePos = vec3(1143.338, 264.245, -52.841),
tableHeading = -135.00,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01`,
color = 0,
max = 1000,
Expand All @@ -91,7 +85,6 @@ cfg.tables = {
dealerHeading = 226.033,
tablePos = vec3(1151.840, 266.747, -52.841),
tableHeading = 45.00,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01`,
color = 0,
max = 1000,
Expand All @@ -103,7 +96,6 @@ cfg.tables = {
dealerHeading = 44.166,
tablePos = vec3(1148.837, 269.747, -52.841),
tableHeading = -135.00,
distance = 100.0,
prop = `vw_prop_casino_blckjack_01`,
color = 0,
max = 1000,
Expand Down
73 changes: 48 additions & 25 deletions source/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,55 @@ Citizen.CreateThread(function()
end
end)

Citizen.CreateThread(function()
while true do
local playerCoords = GetEntityCoords(PlayerPedId())
closeToCasino = false
for k,v in pairs(cfg.blackjackTables) do
cfg.blackjackTables[k].distance = #(playerCoords-cfg.blackjackTables[k].tablePos)
if cfg.blackjackTables[k].distance < 100.0 then
closeToCasino = true
local function clearCasino()
for _, v in pairs(cfg.blackjackTables) do
local obj = v.entity
if obj and DoesEntityExist(obj) then
DeleteEntity(obj)
end
end
end

local function createCasino()
for _, v in pairs(cfg.blackjackTables) do
local coords = v.tablePos
for num=1, #casinoTableList do
local _model = casinoTableList[num]
local obj = GetClosestObjectOfType(coords.x, coords.y, coords.z, 1.0, _model, false, false, false)
if obj and DoesEntityExist(obj) then
SetEntityCoords(obj, coords.x, coords.y, coords.z-2.0)
DeleteEntity(obj)
end
end

RequestModel(v.prop)
local blackjackTableObj = CreateObject(v.prop, coords.x, coords.y, coords.z, false, false, false)
SetEntityHeading(blackjackTableObj, v.tableHeading)
SetObjectTextureVariation(blackjackTableObj, v.color)
v.entity = blackjackTableObj
end
end

local function isCloseToCasino()
local playerCoords = GetEntityCoords(PlayerPedId())
for _, v in pairs(cfg.blackjackTables) do
v.distance = #(playerCoords-v.tablePos)
if v.distance < 100.0 then
return true
end
end
end

Citizen.CreateThread(function()
while true do
local close = isCloseToCasino()
if not closeToCasino and close then
createCasino()
closeToCasino = true
elseif closeToCasino and not close then
clearCasino()
closeToCasino = false
end
Wait(1000)
end
end)
Expand Down Expand Up @@ -1376,22 +1415,6 @@ function blackjack_func_348(iParam0) --GetVectorFromChairId
local x,y,z = getTableCoords(tableId)
local model = cfg.blackjackTables[tableId].prop
blackjackTableObj = GetClosestObjectOfType(x, y, z, 1.0, model, 0, 0, 0)
if not blackjackTableObj or not DoesEntityExist(blackjackTableObj) then
for num=1, #casinoTableList do
local _model = casinoTableList[num]
local obj = GetClosestObjectOfType(x, y, z, 1.0, _model, false, false, false)
if obj and DoesEntityExist(obj) then
SetEntityCoords(obj, x, y, z-2.0)
DeleteEntity(obj)
end
end
RequestModel(model)
blackjackTableObj = CreateObject(model, x, y, z, false, false, false)
SetEntityHeading(blackjackTableObj, cfg.blackjackTables[tableId].tableHeading)
SetObjectTextureVariation(blackjackTableObj, cfg.blackjackTables[tableId].color)
elseif GetObjectTextureVariation(blackjackTableObj) ~= cfg.blackjackTables[tableId].color then
SetObjectTextureVariation(blackjackTableObj, cfg.blackjackTables[tableId].color)
end

if DoesEntityExist(blackjackTableObj) and DoesEntityHaveDrawable(blackjackTableObj) then
local localChairId = getLocalChairIndexFromGlobalChairId(iParam0)
Expand Down Expand Up @@ -3023,7 +3046,7 @@ Citizen.CreateThread(function()
end
--print("closestChair = ",closestChair)
end
Wait(100)
Wait(250)
end
end)

Expand Down

0 comments on commit 5802460

Please sign in to comment.