main Posted December 26, 2019 Posted December 26, 2019 Olá pessoal, estou tentando identificar o clique no porta-malas do veículo com a função processLineOfSight, porém sempre que clico no porta-malas do veículo retorna 4 identificando que o clique foi na parte de trás do carro. Eu acho que as posições que coloquei no parâmetro da função estejam erradas e não estou conseguindo solucionar isto. local vehicleClicked = nil function fClientClick(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if button == "left" and state == "up" then if not getPedOccupiedVehicle(localPlayer) and isElement(clickedElement) and getElementType(clickedElement) == "vehicle" then if getElementData(clickedElement, "Owner") == localPlayer then local cx, cy, cz = getVehicleComponentPosition(clickedElement, "boot_dummy", "world") if cx and cy and cz then local hit, x, y, z, hitElement, _, _, _, _, _, part = processLineOfSight(worldX, worldY, worldZ, cx, cy, cz) iprint(part) -- if not guiGetVisible(weaponWindow) then -- guiSetVisible(weaponWindow, true) -- triggerServerEvent("RefreshListWeapons", resourceRoot, getElementModel(clickedElement)) -- triggerServerEvent("OpenVehicleTrunk", resourceRoot, clickedElement, true) -- end -- vehicleClicked = clickedElement end end end end end addEventHandler("onClientClick", root, fClientClick)
Other Languages Moderators Lord Henry Posted December 26, 2019 Other Languages Moderators Posted December 26, 2019 (edited) processLineOfSight é meio bugado, além de ser pesado. Você pode verificar a posição do clique e compará-lo com a posição do porta-malas. Se clicou perto da posição do porta-malas, então considera como clicou no porta-malas. function fClientClick (button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if (button == "left") and (state == "up") then if not getPedOccupiedVehicle(localPlayer) and isElement(clickedElement) and getElementType(clickedElement) == "vehicle" then -- if getElementData(clickedElement, "Owner") == localPlayer then local cx, cy, cz = getVehicleComponentPosition(clickedElement, "boot_dummy", "world") -- Obtém a posição do porta-malas if (math.abs(cx - worldX) <= 1) and (math.abs(cy - worldY) <= 1) and (math.abs(cz - worldZ) <= 1) then -- Se a diferença entre a posição clicada e a posição do porta-malas for menor que 1 (clicou perto), então: print("Clicou no porta-malas!") else print("Não clicou no porta-malas.") end if (boot) then destroyElement (boot) end if (target) then destroyElement (target) end boot = createMarker (cx, cy, cz, "corona", 0.1) -- Somente para testes. Marca a posição do porta-malas em azul. target = createMarker (worldX, worldY, worldZ, "corona", 0.1, 255, 0, 0, 255) -- Somente para testes. Marca a posição clicada em vermelho. -- if not guiGetVisible(weaponWindow) then -- guiSetVisible(weaponWindow, true) -- triggerServerEvent("RefreshListWeapons", resourceRoot, getElementModel(clickedElement)) -- triggerServerEvent("OpenVehicleTrunk", resourceRoot, clickedElement, true) -- end -- vehicleClicked = clickedElement -- end end end end addEventHandler ("onClientClick", root, fClientClick) Se você quer que ele aceite cliques mais precisos, vc pode diminuir aqueles 1 da condição. Quanto menor o valor, mais perto do porta-malas precisa ser o clique para ser considerado no porta-malas. Edited December 26, 2019 by Lord Henry 1
main Posted December 26, 2019 Author Posted December 26, 2019 Entendi @Lord Henry, muito obrigado pela ajuda!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now