diff --git a/README.md b/README.md index 84a7d3d..94e777d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # qb-spawn -qb-spawn design +qb-spawn design - updated for newest qbcore (Date of update: 25.05.2023) + +Updated by Metalholt#1942 ![](https://cdn.discordapp.com/attachments/797581154315927573/913605989880692827/unknown.png) #qb-multicharacter -https://github.com/marcostom32/qb-multicharacter +https://github.com/marcostom32/qb-multicharacter \ No newline at end of file diff --git a/client.lua b/client.lua index e25d00e..d4da51a 100644 --- a/client.lua +++ b/client.lua @@ -6,16 +6,25 @@ local pointCamCoords2 = 0 local cam1Time = 500 local cam2Time = 1000 local choosingSpawn = false -local cam, cam2 = nil, nil +local Houses = {} +local cam = nil +local cam2 = nil -- Functions local function SetDisplay(bool) + local translations = {} + for k in pairs(Lang.fallback and Lang.fallback.phrases or Lang.phrases) do + if k:sub(0, #'ui.') then + translations[k:sub(#'ui.' + 1)] = Lang:t(k) + end + end choosingSpawn = bool SetNuiFocus(bool, bool) SendNUIMessage({ - type = "ui", - status = bool + action = "showUi", + status = bool, + translations = translations }) end @@ -36,7 +45,7 @@ RegisterNetEvent('qb-spawn:client:openUI', function(value) end) RegisterNetEvent('qb-houses:client:setHouseConfig', function(houseConfig) - Config.Houses = houseConfig + Houses = houseConfig end) RegisterNetEvent('qb-spawn:client:setupSpawns', function(cData, new, apps) @@ -47,7 +56,7 @@ RegisterNetEvent('qb-spawn:client:setupSpawns', function(cData, new, apps) for i = 1, (#houses), 1 do myHouses[#myHouses+1] = { house = houses[i].house, - label = Config.Houses[houses[i].house].adress, + label = Houses[houses[i].house].adress, } end end @@ -57,30 +66,30 @@ RegisterNetEvent('qb-spawn:client:setupSpawns', function(cData, new, apps) action = "setupLocations", locations = QB.Spawns, houses = myHouses, + isNew = new }) end, cData.citizenid) elseif new then SendNUIMessage({ action = "setupAppartements", locations = apps, + isNew = new }) end end) -- NUI Callbacks -RegisterNUICallback("exit", function(data) +RegisterNUICallback("exit", function(_, cb) SetNuiFocus(false, false) SendNUIMessage({ - type = "ui", + action = "showUi", status = false }) choosingSpawn = false + cb("ok") end) -local cam = nil -local cam2 = nil - local function SetCam(campos) cam2 = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", campos.x, campos.y, campos.z + camZPlus1, 300.00,0.00,0.00, 110.00, false, 0) PointCamAtCoord(cam2, campos.x, campos.y, campos.z + pointCamCoords) @@ -96,36 +105,30 @@ local function SetCam(campos) SetEntityCoords(PlayerPedId(), campos.x, campos.y, campos.z) end -RegisterNUICallback('setCam', function(data) +RegisterNUICallback('setCam', function(data, cb) local location = tostring(data.posname) local type = tostring(data.type) - DoScreenFadeOut(200) Wait(500) DoScreenFadeIn(200) - - if DoesCamExist(cam) then - DestroyCam(cam, true) - end - - if DoesCamExist(cam2) then - DestroyCam(cam2, true) - end - + if DoesCamExist(cam) then DestroyCam(cam, true) end + if DoesCamExist(cam2) then DestroyCam(cam2, true) end if type == "current" then QBCore.Functions.GetPlayerData(function(PlayerData) SetCam(PlayerData.position) end) elseif type == "house" then - SetCam(Config.Houses[location].coords.enter) + SetCam(Houses[location].coords.enter) elseif type == "normal" then SetCam(QB.Spawns[location].coords) elseif type == "appartment" then SetCam(Apartments.Locations[location].coords.enter) end + cb('ok') end) -RegisterNUICallback('chooseAppa', function(data) +RegisterNUICallback('chooseAppa', function(data, cb) + local ped = PlayerPedId() local appaYeet = data.appType SetDisplay(false) DoScreenFadeOut(500) @@ -139,7 +142,8 @@ RegisterNUICallback('chooseAppa', function(data) DestroyCam(cam, true) SetCamActive(cam2, false) DestroyCam(cam2, true) - SetEntityVisible(PlayerPedId(), true) + SetEntityVisible(ped, true) + cb('ok') end) local function PreSpawnPlayer() @@ -160,19 +164,19 @@ local function PostSpawnPlayer(ped) DoScreenFadeIn(250) end -RegisterNUICallback('spawnplayer', function(data) +RegisterNUICallback('spawnplayer', function(data, cb) local location = tostring(data.spawnloc) local type = tostring(data.typeLoc) local ped = PlayerPedId() local PlayerData = QBCore.Functions.GetPlayerData() local insideMeta = PlayerData.metadata["inside"] - if type == "current" then PreSpawnPlayer() - QBCore.Functions.GetPlayerData(function(PlayerData) - SetEntityCoords(PlayerPedId(), PlayerData.position.x, PlayerData.position.y, PlayerData.position.z) - SetEntityHeading(PlayerPedId(), PlayerData.position.a) - FreezeEntityPosition(PlayerPedId(), false) + QBCore.Functions.GetPlayerData(function(pd) + ped = PlayerPedId() + SetEntityCoords(ped, pd.position.x, pd.position.y, pd.position.z) + SetEntityHeading(ped, pd.position.a) + FreezeEntityPosition(ped, false) end) if insideMeta.house ~= nil then @@ -207,6 +211,7 @@ RegisterNUICallback('spawnplayer', function(data) SetEntityHeading(ped, pos.w) PostSpawnPlayer() end + cb('ok') end) -- Threads diff --git a/fxmanifest.lua b/fxmanifest.lua index f2797d3..f5fce96 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,25 +1,32 @@ fx_version 'cerulean' game 'gta5' -description 'QB-Spawn' -version '1.0.0' +author "Designed by marcostom32" +description 'QB-Spawn Design - Updated by Metalholt#1942' +version '2.0.9' shared_scripts { - 'config.lua', - '@qb-houses/config.lua', - '@qb-apartments/config.lua' + '@qb-core/shared/locale.lua', + 'locales/en.lua', + 'locales/*.lua', + 'config.lua', + '@qb-apartments/config.lua', } client_script 'client.lua' -server_script 'server.lua' + +server_scripts { + '@oxmysql/lib/MySQL.lua', + 'server.lua' +} ui_page 'html/index.html' files { - 'html/index.html', - 'html/style.css', - 'html/script.js', - 'html/reset.css' + 'html/index.html', + 'html/style.css', + 'html/vue.js', + 'html/reset.css' } -lua54 'yes' \ No newline at end of file +lua54 'yes' diff --git a/locales/en.lua b/locales/en.lua new file mode 100644 index 0000000..90985b5 --- /dev/null +++ b/locales/en.lua @@ -0,0 +1,12 @@ +local Translations = { + ui = { + last_location = "Last Location", + confirm = "Confirm", + where_would_you_like_to_start = "Where would you like to start?", + } +} + +Lang = Lang or Locale:new({ + phrases = Translations, + warnOnMissing = true +}) \ No newline at end of file diff --git a/server.lua b/server.lua index a8b087e..84e793a 100644 --- a/server.lua +++ b/server.lua @@ -1,14 +1,14 @@ local QBCore = exports['qb-core']:GetCoreObject() -QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(source, cb, cid) +QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(_, cb, cid) if cid ~= nil then - local houses = exports.oxmysql:executeSync('SELECT * FROM player_houses WHERE citizenid = ?', {cid}) + local houses = MySQL.query.await('SELECT * FROM player_houses WHERE citizenid = ?', {cid}) if houses[1] ~= nil then cb(houses) else - cb(nil) + cb({}) end else - cb(nil) + cb({}) end end)