Skip to content

Commit

Permalink
fix: add shared file instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm committed Sep 24, 2024
1 parent c4f3175 commit f99ffc7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 1 addition & 5 deletions client/realtor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ local shell = 0
local playerCoords = vec3(0, 0, 0)
local isPreviewing = false

local function calculateOffsetCoords(propertyCoords, offset)
return vec4(propertyCoords.x + offset.x, propertyCoords.y + offset.y, (propertyCoords.z - sharedConfig.shellUndergroundOffset) + offset.z, propertyCoords.w or 0.0)
end

local function previewProperty(propertyIndex)
if DoesEntityExist(shell) then DeleteEntity(shell) end
if type(propertyIndex) == 'number' then
lib.requestModel(propertyIndex, 5000)
shell = CreateObject(propertyIndex, playerCoords.x, playerCoords.y, playerCoords.z - sharedConfig.shellUndergroundOffset, false, false, false)
FreezeEntityPosition(shell, true)
SetModelAsNoLongerNeeded(propertyIndex)
local teleportCoords = calculateOffsetCoords(playerCoords, sharedConfig.interiors[propertyIndex].exit)
local teleportCoords = CalculateOffsetCoords(playerCoords, sharedConfig.interiors[propertyIndex].exit)
SetEntityCoords(cache.ped, teleportCoords.x, teleportCoords.y, teleportCoords.z, false, false, false, false)
else
local teleportCoords = sharedConfig.interiors[propertyIndex].exit
Expand Down
1 change: 1 addition & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ox_lib 'locale'
shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/lib.lua',
'shared/main.lua',
}

client_scripts {
Expand Down
10 changes: 3 additions & 7 deletions server/property.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ local sql2 = LoadResourceFile(cache.resource, 'decorations.sql')
if sql1 then MySQL.query(sql1) end
if sql2 then MySQL.query(sql2) end

local function calculateOffsetCoords(propertyCoords, offset)
return vec4(propertyCoords.x + offset.x, propertyCoords.y + offset.y, (propertyCoords.z - sharedConfig.shellUndergroundOffset) + offset.z, propertyCoords.w or 0.0)
end

function EnterProperty(playerSource, id, isSpawn)
local property = MySQL.single.await('SELECT * FROM properties WHERE id = ?', {id})
local propertyCoords = json.decode(property.coords)
Expand All @@ -26,7 +22,7 @@ function EnterProperty(playerSource, id, isSpawn)
local isInteriorShell = tonumber(property.interior) ~= nil
local stashes = json.decode(property.stash_options)
for i = 1, #stashes do
local stashCoords = isInteriorShell and calculateOffsetCoords(propertyCoords, stashes[i].coords) or stashes[i].coords
local stashCoords = isInteriorShell and CalculateOffsetCoords(propertyCoords, stashes[i].coords) or stashes[i].coords
interactions[#interactions + 1] = {
type = 'stash',
coords = vec3(stashCoords.x, stashCoords.y, stashCoords.z)
Expand All @@ -40,7 +36,7 @@ function EnterProperty(playerSource, id, isSpawn)

local interactData = json.decode(property.interact_options)
for i = 1, #interactData do
local coords = isInteriorShell and calculateOffsetCoords(propertyCoords, interactData[i].coords) or interactData[i].coords
local coords = isInteriorShell and CalculateOffsetCoords(propertyCoords, interactData[i].coords) or interactData[i].coords
interactions[#interactions + 1] = {
type = interactData[i].type,
coords = vec3(coords.x, coords.y, coords.z)
Expand All @@ -61,7 +57,7 @@ function EnterProperty(playerSource, id, isSpawn)
local decorations = MySQL.query.await('SELECT `id`, `model`, `coords`, `rotation` FROM `properties_decorations` WHERE `property_id` = ?', {id})
for i = 1, #decorations do
local temp = json.decode(decorations[i].coords)
decorations[i].coords = isInteriorShell and calculateOffsetCoords(propertyCoords, vec3(temp.x, temp.y, temp.z)) or vec3(temp.x, temp.y, temp.z)
decorations[i].coords = isInteriorShell and CalculateOffsetCoords(propertyCoords, vec3(temp.x, temp.y, temp.z)) or vec3(temp.x, temp.y, temp.z)
temp = json.decode(decorations[i].rotation)
decorations[i].rotation = vec3(temp.x, temp.y, temp.z)
end
Expand Down
8 changes: 8 additions & 0 deletions shared/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local sharedConfig = require 'config.shared'

---@param propertyCoords vector3 | vector4
---@param offset vector3
---@return vector4
function CalculateOffsetCoords(propertyCoords, offset)
return vec4(propertyCoords.x + offset.x, propertyCoords.y + offset.y, (propertyCoords.z - sharedConfig.shellUndergroundOffset) + offset.z, propertyCoords.w or 0.0)
end

0 comments on commit f99ffc7

Please sign in to comment.