Skip to content

Commit

Permalink
feat: able to login in motels rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
renzuzu committed Apr 11, 2023
1 parent 9ae0eb6 commit 3510a62
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions bridge/framework/client/esx.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
if not ESX then return end
PlayerData = ESX.GetPlayerData()
local kvpname = GetCurrentServerEndpoint()..'_inshells'

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded',function(playerData)
PlayerData = playerData
local login = GetResourceKvpString(kvpname)
if not login then return end
local data = json.decode(login)
LocalPlayer.state:set('inshell',true,true)
LocalPlayer.state:set('lastloc',data.lastloc,false)
DoScreenFadeOut(0)
EnterShell(data,true)
end)

RegisterNetEvent('esx:setJob')
Expand Down
8 changes: 8 additions & 0 deletions bridge/framework/client/qbcore.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if not QBCORE then return end
PlayerData = QBCORE.Functions.GetPlayerData()
local kvpname = GetCurrentServerEndpoint()..'_inshells'

if PlayerData.job ~= nil then
PlayerData.job.grade = PlayerData.job.grade.level
Expand All @@ -20,6 +21,13 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
if PlayerData.identifier == nil then
PlayerData.identifier = PlayerData.citizenid
end
local login = GetResourceKvpString(kvpname)
if not login then return end
local data = json.decode(login)
LocalPlayer.state:set('inshell',true,true)
LocalPlayer.state:set('lastloc',data.lastloc,false)
DoScreenFadeOut(0)
EnterShell(data,true)
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
Expand Down
25 changes: 16 additions & 9 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

local kvpname = GetCurrentServerEndpoint()..'_inshells'
CreateBlips = function()
for k,v in pairs(config.motels) do
local blip = AddBlipForCoord(v.rentcoord.x,v.rentcoord.y,v.rentcoord.z)
Expand Down Expand Up @@ -809,12 +809,14 @@ function Teleport(x, y, z, h ,exit)
DeleteEntity(house)
lib.callback.await('renzu_motels:SetRouting',false,data,'exit')
shelzones = {}
DeleteResourceKvp(kvpname)
LocalPlayer.state:set('inshell',false,true)
end
end

EnterShell = function(data)
EnterShell = function(data,login)
local motels = GlobalState.Motels
if motels[data.motel].rooms[data.index].lock then
if motels[data.motel].rooms[data.index].lock and not login then
Notify('Door is Locked', 'error')
return false
end
Expand All @@ -826,7 +828,7 @@ EnterShell = function(data)
lib.callback.await('renzu_motels:SetRouting',false,data,'enter')
inhouse = true
Wait(1000)
local spawn = data.coord+vec3(0.0,0.0,1500.0)
local spawn = vec3(data.coord.x,data.coord.y,data.coord.z)+vec3(0.0,0.0,1500.0)
local offsets = shelldata.offsets
local model = shelldata.shell
DoScreenFadeOut(500)
Expand All @@ -839,14 +841,19 @@ EnterShell = function(data)
while not HasModelLoaded(model) do
Wait(1000)
end
local lastloc = GetEntityCoords(cache.ped)
house = CreateObject(model, spawn.x, spawn.y, spawn.z, false, false, false)
FreezeEntityPosition(house, true)
LocalPlayer.state:set('lastloc',GetEntityCoords(cache.ped),false)
LocalPlayer.state:set('inhouse',GetEntityCoords(cache.ped),true)
SendNUIMessage({
type = 'door'
})
LocalPlayer.state:set('lastloc',data.lastloc or lastloc,false)
data.lastloc = data.lastloc or lastloc
if not login then
SendNUIMessage({
type = 'door'
})
end
Teleport(spawn.x + offsets.exit.x, spawn.y + offsets.exit.y, spawn.z+0.1, offsets.exit.h)
SetResourceKvp(kvpname,json.encode(data))

Citizen.CreateThreadNow(function()
ShellTargets(data,offsets,spawn,house)
while inhouse do
Expand Down

0 comments on commit 3510a62

Please sign in to comment.