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

feat: spawn in property when logging out there #21

Merged
merged 2 commits into from
Aug 20, 2024
Merged
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
26 changes: 17 additions & 9 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ local function scaleformDetails(index)

BeginScaleformMovieMethod(scaleform, 'ADD_TEXT')
ScaleformMovieMethodAddParamInt(index)
ScaleformMovieMethodAddParamTextureNameString(locale(spawn.label))
ScaleformMovieMethodAddParamTextureNameString(spawn.label)
ScaleformMovieMethodAddParamFloat(spawn.coords.x)
ScaleformMovieMethodAddParamFloat(spawn.coords.y - 500)
ScaleformMovieMethodAddParamFloat(25 - math.random(0, 50))
Expand Down Expand Up @@ -215,34 +215,42 @@ local function inputHandler()
TriggerEvent('QBCore:Client:OnPlayerLoaded')
FreezeEntityPosition(cache.ped, false)

local coords = spawns[currentButtonID].coords
local spawnData = spawns[currentButtonID]
if spawnData.propertyId then
TriggerServerEvent('qbx_properties:server:enterProperty', { id = spawnData.propertyId, isSpawn = true })
else
SetEntityCoords(cache.ped, spawnData.coords.x, spawnData.coords.y, spawnData.coords.z, false, false, false, false)
SetEntityHeading(cache.ped, spawnData.coords.w or 0.0)
end

SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false)
SetEntityHeading(cache.ped, coords.w or 0.0)
DoScreenFadeIn(1000)

break
end

Wait(0)
end

stopCamera()
end

AddEventHandler('qb-spawn:client:setupSpawns', function()
spawns = {}

spawns[#spawns+1] = {
label = 'last_location',
coords = lib.callback.await('qbx_spawn:server:getLastLocation')
local lastCoords, lastPropertyId = lib.callback.await('qbx_spawn:server:getLastLocation')
spawns[#spawns + 1] = {
label = locale('last_location'),
coords = lastCoords,
propertyId = lastPropertyId
}

for i = 1, #config.spawns do
spawns[#spawns+1] = config.spawns[i]
spawns[#spawns + 1] = config.spawns[i]
end

local houses = lib.callback.await('qbx_spawn:server:getHouses')
for i = 1, #houses do
spawns[#spawns+1] = houses[i]
spawns[#spawns + 1] = houses[i]
end

Wait(400)
Expand Down
6 changes: 3 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib.callback.register('qbx_spawn:server:getLastLocation', function(source)
local player = exports.qbx_core:GetPlayer(source)
return json.decode(MySQL.single.await('SELECT position FROM players WHERE citizenid = ?', {player.PlayerData.citizenid}).position)
return json.decode(MySQL.single.await('SELECT position FROM players WHERE citizenid = ?', {player.PlayerData.citizenid}).position), player.PlayerData.metadata.currentPropertyId
end)

lib.callback.register('qbx_spawn:server:getHouses', function(source)
Expand All @@ -10,11 +10,11 @@ lib.callback.register('qbx_spawn:server:getHouses', function(source)
for i = 1, #playerHouses do
local name = playerHouses[i].house
local locationData = MySQL.single.await('SELECT `coords`, `label` FROM houselocations WHERE name = ?', {name})
houseData[#houseData+1] = {
houseData[#houseData + 1] = {
label = locationData.label,
coords = json.decode(locationData.coords).enter
}
end

return houseData
end)
end)