diff --git a/config.lua b/config.lua index 03e1ef6..cee3681 100644 --- a/config.lua +++ b/config.lua @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/source/client.lua b/source/client.lua index b73f651..cac4611 100644 --- a/source/client.lua +++ b/source/client.lua @@ -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) @@ -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) @@ -3023,7 +3046,7 @@ Citizen.CreateThread(function() end --print("closestChair = ",closestChair) end - Wait(100) + Wait(250) end end)