đŸ–Ĩī¸Compatibilities

okokGarage

Search this event on sv_utils:

Config.EventPrefix..":TransferVehicle"
RegisterNetEvent(Config.EventPrefix..":TransferVehicle", function(pID, plate, toSociety)
	local source = source
	local xPlayer = QBCore.Functions.GetPlayer(source)
	if not toSociety then
		pID = tonumber(pID)
	end
	if oldOwner ~= nil then
		source = oldOwner
	end

	if pID ~= nil and plate ~= nil then
		if toSociety then
			MySQLfetchAll('SELECT *, cast(`state` as signed) as `stored` FROM player_vehicles WHERE citizenid = @owner AND plate = @plate', {
				['@owner'] = xPlayer.PlayerData.citizenid,
				['@plate'] = plate:match( "^%s*(.-)%s*$" )
			}, function(vehicle)
				if vehicle[1] ~= nil then
					vehicle[1].sharedwith = {}
					MySQLexecute('UPDATE player_vehicles SET `citizenid` = @newowner, `license` = @license, `sharedwith` = @sharedwith, favourite = 0, garage = @garage WHERE citizenid = @owner AND plate = @plate', {
						['@owner'] = xPlayer.PlayerData.citizenid,
						['@plate'] = plate:match( "^%s*(.-)%s*$" ),
						['@newowner'] = pID,
						['@license'] = pID,
						['@sharedwith'] = json.encode(vehicle[1].sharedwith),
						['@garage'] = nil
					}, function (rowsChanged)
						if rowsChanged > 0 then
							TriggerClientEvent(Config.EventPrefix..':notification', source, _L('vehicle_transferred_to_other').title, _L('vehicle_transferred_to_other').text, _L('vehicle_transferred_to_other').time, _L('vehicle_transferred_to_other').type)

							if Webhook ~= "" then
								data = {
									playerid = source,
									type = "transfer-vehicle",
									info = plate:match( "^%s*(.-)%s*$" ),
								}

								discordWebhook(data)
							end
						end
					end)
				else
					TriggerClientEvent(Config.EventPrefix..':notification', source, _L('not_the_owner').title, _L('not_the_owner').text, _L('not_the_owner').time, _L('not_the_owner').type)
				end
			end)
		else
			if GetPlayerPing(pID) > 0 then
				local targetXPlayer = QBCore.Functions.GetPlayer(pID)
				MySQLfetchAll('SELECT *, cast(`state` as signed) as `stored` FROM player_vehicles WHERE citizenid = @owner AND plate = @plate OR citizenid = @society AND plate = @plate', {
					['@owner'] = xPlayer.PlayerData.citizenid,
					['@society'] = xPlayer.PlayerData.job.name:lower(),
					['@plate'] = plate:match( "^%s*(.-)%s*$" )
				}, function(vehicle)
					if vehicle[1] ~= nil then
						vehicle[1].sharedwith = {}
						MySQLexecute('UPDATE player_vehicles SET `citizenid` = @newowner, `sharedwith` = @sharedwith, favourite = 0, license = @license WHERE citizenid = @owner AND plate = @plate OR citizenid = @society AND plate = @plate', {
							['@owner'] = xPlayer.PlayerData.citizenid,
							['@society'] = xPlayer.PlayerData.job.name:lower(),
							['@plate'] = plate:match( "^%s*(.-)%s*$" ),
							['@newowner'] = targetXPlayer.PlayerData.citizenid,
							['@sharedwith'] = json.encode(vehicle[1].sharedwith),
							['@license'] = targetXPlayer.PlayerData.license
						}, function (rowsChanged)
							if rowsChanged > 0 then
								TriggerClientEvent(Config.EventPrefix..':notification', source, _L('vehicle_transferred_to_other').title, _L('vehicle_transferred_to_other').text, _L('vehicle_transferred_to_other').time, _L('vehicle_transferred_to_other').type)
								TriggerClientEvent(Config.EventPrefix..':notification', pID, _L('vehicle_transferred').title, _L('vehicle_transferred').text, _L('vehicle_transferred').time, _L('vehicle_transferred').type)

								if Webhook ~= "" then
									data = {
										playerid = source,
										type = "transfer-vehicle",
										info = plate:match( "^%s*(.-)%s*$" ),
									}

									discordWebhook(data)
								end
							end
						end)
					else
						TriggerClientEvent(Config.EventPrefix..':notification', source, _L('not_the_owner').title, _L('not_the_owner').text, _L('not_the_owner').time, _L('not_the_owner').type)
					end
				end)
			else
				TriggerClientEvent(Config.EventPrefix..':notification', source, _L('player_not_online').title, _L('player_not_online').text, _L('player_not_online').time, _L('player_not_online').type)
			end
		end
	end
end)

Last updated