Jump to content

Error in script


dima3367

Recommended Posts

Hello! I have a resource responsible for the teleportation of the player to his garage where he gets to choose his car. 
But there is a small bug that appears very rarely, but nevertheless it appears the players, namely that of the player after entering the garage and exiting beams are not the same direction from which he came, and under the texture in the field. 
It is accompanied by this error:

jpeg&tknv=v2&size=1280x660

Here is the send part of the code, tell me, what could be and how to fix it, I would be very grateful.

addEvent("tws-serverGarageEnter", true)
addEvent("tws-serverGarageExit", true)

addEventHandler("tws-serverGarageEnter", resourceRoot,
	function(garagePosition)
		local playerAccount = getPlayerAccount(client)
		if isGuestAccount(playerAccount) then
			triggerClientEvent(player, "tws-clientGarageEnter", resourceRoot, false, "Вы не залогинены")
			return
		end
		-- Массив машин игрока
		local playerVehiclesJSON = getAccountData(playerAccount, "vehicles")
		if not playerVehiclesJSON then
			triggerClientEvent(player, "tws-clientGarageEnter", resourceRoot, false, "Не удалось получить список ваших автомобилей")
			return
		end

		-- Координаты игрока перед входом в гараж
		local garageEnterInfo = {
			position = client.position,
			rotation = client.rotation
		}

		local vehicleToShow = 1

		if isElement(client.vehicle) then
			-- Если игрок в машине, запоминаем координаты машины
			garageEnterInfo.position = client.vehicle.position
			garageEnterInfo.rotation = client.vehicle.rotation

			-- Если игрок в машине, принадлежащей ему, отправляем её в гараж
			if exports["tws-vehicles"]:isVehicleOwnedByPlayer(client.vehicle, client) then
				vehicleToShow = exports["tws-vehicles"]:getVehicleGarageID(client.vehicle)
				exports["tws-vehicles"]:returnVehicleToGarage(client.vehicle)
				removePedFromVehicle(client)
			end
		end

		local playerVehiclesTable = fromJSON(playerVehiclesJSON)
		if playerVehiclesTable then
			local spawnedVehicles = exports["tws-vehicles"]:getPlayerSpawnedVehicles(client)
			for k,v in pairs(spawnedVehicles) do
				playerVehiclesTable[k].spawned = true
			end
		else
			triggerClientEvent(player, "tws-clientGarageEnter", resourceRoot, false, "Ошибка получения списка ваших автомобилей")
			return
		end

		-- Кладём координаты в дату
		client:setData("tws-garageEnterInfo", garageEnterInfo)

		client:setData("tws-inGarage", true)
		client.interior = 0
		client.dimension = exports["tws-main"]:getPlayerID(client)
		client:setPosition(unpack(garagePosition))
		client.position = client.position + Vector3(0, 0, 10)

		triggerClientEvent(client, "tws-clientGarageEnter", resourceRoot, true, toJSON(playerVehiclesTable), vehicleToShow)
	end
)

addEventHandler("tws-serverGarageExit", resourceRoot,
	function(selectedVehicleID)
		if client:getData("tws-inGarage") == false then
			return
		end

		client:setData("tws-inGarage", false)
		client.dimension = 0
		client.interior = 0

		if selectedVehicleID then
			local vehicle = exports["tws-vehicles"]:spawnPlayerVehicle(client, selectedVehicleID, 0, 0, 0)
			removePedFromVehicle(client)
			warpPedIntoVehicle(client, vehicle)
			setCameraTarget(client)
		end

		local garageEnterInfo = client:getData("tws-garageEnterInfo")
	 	if not garageEnterInfo then
		 	garageEnterInfo = {position: Vector3(0, 0, 0), rotation: Vector3(0, 0, 0)}
	    end
 
		if isElement(client.vehicle) then
			client.vehicle.position = garageEnterInfo.position
		 	client.vehicle.position = garageEnterInfo.position
	 	else
		 	client.position = garageEnterInfo.position
            client.position = garageEnterInfo.position
	 	end

	 	triggerClientEvent(client, "tws-clientGarageExit", resourceRoot)
 	end
)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...