Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.7 kB
4
Indexable
Never
RegisterNetEvent('hospital:server:RespawnAtHospital', function()
	local src = source
	local Player = QBCore.Functions.GetPlayer(src)
	if Player.PlayerData.metadata["injail"] > 0 then
		for k, v in pairs(Config.Locations["jailbeds"]) do
			if not v.taken then
				TriggerClientEvent('hospital:client:SendToBed', src, k, v, true)
				TriggerClientEvent('hospital:client:SetBed2', -1, k, true)
				local players = QBCore.Functions.GetQBPlayers()
				for _, x in pairs(players) do
					if x.PlayerData.job.name == 'ambulance' and x.PlayerData.job.onduty then
						Player.Functions.ClearInventory()
						MySQL.update('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode({}), Player.PlayerData.citizenid })
						TriggerClientEvent('QBCore:Notify', src, Lang:t('error.possessions_taken'), 'error')
					end
				end
				Player.Functions.RemoveMoney("bank", Config.BillCost, "respawned-at-hospital")
					exports['qb-management']:AddMoney("ambulance", Config.BillCost)
				TriggerClientEvent('hospital:client:SendBillEmail', src, Config.BillCost)
				return
			end
		end

		TriggerClientEvent('hospital:client:SendToBed', src, 1, Config.Locations["jailbeds"][1], true)
		TriggerClientEvent('hospital:client:SetBed', -1, 1, true)
		local players = QBCore.Functions.GetQBPlayers()
		for _, x in pairs(players) do
			if x.PlayerData.job.name == 'ambulance' and x.PlayerData.job.onduty then
				Player.Functions.ClearInventory()
				MySQL.update('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode({}), Player.PlayerData.citizenid })
				TriggerClientEvent('QBCore:Notify', src, Lang:t('error.possessions_taken'), 'error')
			end
		end
		Player.Functions.RemoveMoney("bank", Config.BillCost, "respawned-at-hospital")
			exports['qb-management']:AddMoney("ambulance", Config.BillCost)
		TriggerClientEvent('hospital:client:SendBillEmail', src, Config.BillCost)
    else
		for k, v in pairs(Config.Locations["beds"]) do
			if not v.taken then
				TriggerClientEvent('hospital:client:SendToBed', src, k, v, true)
				TriggerClientEvent('hospital:client:SetBed', -1, k, true)
				local players = QBCore.Functions.GetQBPlayers()
				for _, x in pairs(players) do
					if x.PlayerData.job.name == 'ambulance' and x.PlayerData.job.onduty then
						Player.Functions.ClearInventory()
						MySQL.update('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode({}), Player.PlayerData.citizenid })
						TriggerClientEvent('QBCore:Notify', src, Lang:t('error.possessions_taken'), 'error')
					end
				end
				Player.Functions.RemoveMoney("bank", Config.BillCost, "respawned-at-hospital")
					exports['qb-management']:AddMoney("ambulance", Config.BillCost)
				TriggerClientEvent('hospital:client:SendBillEmail', src, Config.BillCost)
				return
			end
		end

		TriggerClientEvent('hospital:client:SendToBed', src, 1, Config.Locations["beds"][1], true)
		TriggerClientEvent('hospital:client:SetBed', -1, 1, true)
		local players = QBCore.Functions.GetQBPlayers()
		for _, x in pairs(players) do
			if x.PlayerData.job.name == 'ambulance' and x.PlayerData.job.onduty then
				Player.Functions.ClearInventory()
				MySQL.update('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode({}), Player.PlayerData.citizenid })
				TriggerClientEvent('QBCore:Notify', src, Lang:t('error.possessions_taken'), 'error')
			end
		end
		Player.Functions.RemoveMoney("bank", Config.BillCost, "respawned-at-hospital")
			exports['qb-management']:AddMoney("ambulance", Config.BillCost)
		TriggerClientEvent('hospital:client:SendBillEmail', src, Config.BillCost)
	end
end)