Skip to content

Commit

Permalink
feat: default spawn to last location (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manason authored Oct 4, 2023
1 parent e4c3336 commit ef4e19c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
32 changes: 30 additions & 2 deletions client/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,32 @@ local function spawnDefault() -- We use a callback to make the server wait on th
TriggerEvent('qb-clothes:client:CreateFirstCharacter')
end

local function spawnLastLocation()
DoScreenFadeOut(500)

while not IsScreenFadedOut() do
Wait(0)
end

destroyPreviewCam()

pcall(function() exports.spawnmanager:spawnPlayer({
x = QBX.PlayerData.position.x,
y = QBX.PlayerData.position.y,
z = QBX.PlayerData.position.z,
heading = QBX.PlayerData.position.w
}) end)

TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
TriggerEvent('QBCore:Client:OnPlayerLoaded')
TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)

while not IsScreenFadedIn() do
Wait(0)
end
end

---@param cid integer
---@return boolean
local function createCharacter(cid)
Expand Down Expand Up @@ -210,7 +236,7 @@ local function createCharacter(cid)
cid = cid
})

if GetResourceState('qbx-spawn') == 'missing' then
if GetResourceState('qbx_spawn') == 'missing' then
spawnDefault()
TriggerEvent('qb-clothes:client:CreateFirstCharacter')
else
Expand Down Expand Up @@ -294,9 +320,11 @@ local function chooseCharacter()
lib.callback.await('qbx_core:server:loadCharacter', false, character.citizenid)
if GetResourceState('qbx-apartments'):find('start') then
TriggerEvent('apartments:client:setupSpawnUI', { citizenid = character.citizenid })
else
elseif GetResourceState('qbx_spawn'):find('start') then
TriggerEvent('qb-spawn:client:setupSpawns', { citizenid = character.citizenid })
TriggerEvent('qb-spawn:client:openUI', true)
else
spawnLastLocation()
end
destroyPreviewCam()
end
Expand Down
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Config.StatusInterval = 5 -- how often to check hunger/thirst status in minutes
Config.Characters = {}
Config.Characters.UseExternalCharacters = false -- Whether you have an external character management resource. (If true, disables the character management inside the core)
Config.Characters.EnableDeleteButton = true -- Whether players should be able to delete characters themselves.
Config.Characters.StartingApartment = true -- If set to false, skips apartment choice in the beginning (requires qbx-spawn if true)
Config.Characters.StartingApartment = true -- If set to false, skips apartment choice in the beginning (requires qbx_spawn if true)
Config.Characters.DefaultNumberOfCharacters = 3 -- Define maximum amount of default characters (maximum 3 characters defined by default)
Config.Characters.PlayersNumberOfCharacters = { -- Define maximum amount of player characters by rockstar license (you can find this license in your server's database in the player table)
['license2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'] = 5,
Expand Down
2 changes: 1 addition & 1 deletion server/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ lib.callback.register('qbx_core:server:createCharacter', function(source, data)
if not player then return end

giveStarterItems(source)
if GetResourceState('qbx-spawn') == 'missing' then
if GetResourceState('qbx_spawn') == 'missing' then
SetPlayerRoutingBucket(source, 0)
end

Expand Down

0 comments on commit ef4e19c

Please sign in to comment.