ber Posted June 7, 2020 Share Posted June 7, 2020 (edited) Hello everyone, this is my first time here on this forum, I have always managed to clarify my doubts without creating topics, just observing the others, but in this case it is very complicated and I can't find where I'm going wrong. I used this script before with just the click on the car and it was already running, but I started to have reports of players who clicked unintentionally and ended up losing 1 repair kit for nothing, so I decided to add a DX confirmation panel when the player clicks on the vehicle . This is the code I made, I have re-read it 10 times and I still haven't found where I may have gone wrong. Please, whoever can help me will be very grateful! (Caso algum BR veja isso, pode responder em português kkkk é nois ;D) ------------------------- SERVER ----------------------------------- function reparo() local veiculo = getElementData(source,"vehSelected") setElementFrozen(veiculo, true) setVehicleDoorOpenRatio(veiculo, 0, 1, 1000) setPedAnimation(source, "CAMERA", "piccrch_take", 14000, true, false, false, false) setTimer(function() fixVehicle(veiculo) setVehicleDamageProof(veiculo, false) setPedAnimation(source, "") setElementFrozen(veiculo, false) setVehicleDoorOpenRatio(veiculo, 0, 0, 1000) end, 14000, 1) end addEvent("reparando", true) addEventHandler("reparando", root, reparo) ------------------------- CLIENT ----------------------------------- addEventHandler("onClientClick", getRootElement(), function(button, state, _, _, _, _, _, veiculo) if button == "left" and state == "down" then if isElement(veiculo) then local x, y, z = getElementPosition(localPlayer) local ex, ey, ez = getElementPosition(veiculo) if getDistanceBetweenPoints3D(x, y, z, ex, ey, ez) <= 2.5 then if getElementType(veiculo) == "vehicle" then if getVehicleController(veiculo) == false then if isElementFrozen(veiculo) == false then triggerEvent("openPainel", root) end end end end end end end) function startRepair() local sound = playSound("repair.mp3") setElementData(localPlayer, "vehSelected", veiculo) setElementData(localPlayer, "AirNewSCR_Inventario_Kit_Reparo", Kit_Reparo - 1) exports._infobox:addNotification("-1 Kit de reparo", "info") triggerServerEvent("reparando", localPlayer) setTimer(function() exports._infobox:addNotification("Você reparou o veículo!", "success") end, 14000, 1) end addEvent("startRepair", true) addEventHandler("startRepair", root, startRepair) ---------------------------------------------------------------- local screenW, screenH = guiGetScreenSize() local Kit_Reparo = getElementData ( localPlayer, "AirNewSCR_Inventario_Kit_Reparo" ) painel = false function painelR() dxDrawRectangle(screenW * 0.5447, screenH * 0.4115, screenW * 0.1398, screenH * 0.1732, tocolor(0, 0, 0, 198), false) dxDrawRectangle(screenW * 0.5447, screenH * 0.3724, screenW * 0.1406, screenH * 0.0391, tocolor(0, 0, 0, 255), false) dxDrawLine(screenW * 0.5447, screenH * 0.4115, screenW * 0.6845, screenH * 0.4128, tocolor(174, 78, 14, 255), 2, false) dxDrawRectangle(screenW * 0.5490, screenH * 0.5247, screenW * 0.1318, screenH * 0.0521, tocolor(207, 0, 0, 139), false) dxDrawRectangle(screenW * 0.5490, screenH * 0.4648, screenW * 0.1318, screenH * 0.0521, tocolor(45, 146, 18, 139), false) dxDrawText("REPARAR", screenW * 0.5439, screenH * 0.3724, screenW * 0.6845, screenH * 0.4115, tocolor(184, 184, 184, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("KITs de reparo: "..Kit_Reparo.., screenW * 0.5483, screenH * 0.4128, screenW * 0.6808, screenH * 0.4648, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, false, false) dxDrawText("REPARAR", (screenW * 0.5490) - 1, (screenH * 0.4648) - 1, (screenW * 0.6808) - 1, (screenH * 0.5169) - 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("REPARAR", (screenW * 0.5490) + 1, (screenH * 0.4648) - 1, (screenW * 0.6808) + 1, (screenH * 0.5169) - 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("REPARAR", (screenW * 0.5490) - 1, (screenH * 0.4648) + 1, (screenW * 0.6808) - 1, (screenH * 0.5169) + 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("REPARAR", (screenW * 0.5490) + 1, (screenH * 0.4648) + 1, (screenW * 0.6808) + 1, (screenH * 0.5169) + 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("REPARAR", screenW * 0.5490, screenH * 0.4648, screenW * 0.6808, screenH * 0.5169, tocolor(255, 255, 255, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("CANCELAR", (screenW * 0.5490) - 1, (screenH * 0.5247) - 1, (screenW * 0.6808) - 1, (screenH * 0.5768) - 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("CANCELAR", (screenW * 0.5490) + 1, (screenH * 0.5247) - 1, (screenW * 0.6808) + 1, (screenH * 0.5768) - 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("CANCELAR", (screenW * 0.5490) - 1, (screenH * 0.5247) + 1, (screenW * 0.6808) - 1, (screenH * 0.5768) + 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("CANCELAR", (screenW * 0.5490) + 1, (screenH * 0.5247) + 1, (screenW * 0.6808) + 1, (screenH * 0.5768) + 1, tocolor(0, 0, 0, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("CANCELAR", screenW * 0.5490, screenH * 0.5247, screenW * 0.6808, screenH * 0.5768, tocolor(255, 255, 255, 255), 1.50, "default-bold", "center", "center", false, false, false, false, false) end function openPainel() addEventHandler("onClientRender", root, painelR) painel = true showCursor(true) end addEvent("openPainel", true) addEventHandler("openPainel", root, openPainel) function closePainel(_,state) if state == "down" then if isCursorOnElement(screenW * 0.5490, screenH * 0.4648, screenW * 0.6808, screenH * 0.5169) then removeEventHandler("onClientRender", root, painelR) painel = false showCursor(false) end end end addEventHandler("onClientClick", root, closePainel) function repair(_,state) if state == "down" then if isCursorOnElement(screenW * 0.5490, screenH * 0.4648, screenW * 0.6808, screenH * 0.5169) then if Kit_Reparo >= 1 then triggerEvent("startRepair", root) removeEventHandler("onClientRender", root, painelR) painel = false showCursor(false) else exports._infobox:addNotification("Você não possui kit de reparo!", "error") end end end end addEventHandler("onClientClick", root, repair) ------------------------------------------------------------------------------------- function isCursorOnElement ( x, y, w, h ) local mx, my = getCursorPosition () local fullx, fully = guiGetScreenSize () cursorx, cursory = mx*fullx, my*fully if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then return true else return false end end Edited June 7, 2020 by ber Link to comment
MrKAREEM Posted June 7, 2020 Share Posted June 7, 2020 13 hours ago, ber said: Hello everyone, this is my first time here on this forum, I have always managed to clarify my doubts without creating topics, just observing the others, but in this case it is very complicated and I can't find where I'm going wrong. I used this script before with just the click on the car and it was already running, but I started to have reports of players who clicked unintentionally and ended up losing 1 repair kit for nothing, so I decided to add a DX confirmation panel when the player clicks on the vehicle . This is the code I made, I have re-read it 10 times and I still haven't found where I may have gone wrong. Please, whoever can help me will be very grateful! (Caso algum BR veja isso, pode responder em português kkkk é nois ;D) ------------------------- SERVER ----------------------------------- function reparo() local veiculo = getElementData(source,"vehSelected") setElementFrozen(veiculo, true) setVehicleDoorOpenRatio(veiculo, 0, 1, 1000) setPedAnimation(source, "CAMERA", "piccrch_take", 14000, true, false, false, false) setTimer(function() fixVehicle(veiculo) setVehicleDamageProof(veiculo, false) setPedAnimation(source, "") setElementFrozen(veiculo, false) setVehicleDoorOpenRatio(veiculo, 0, 0, 1000) end, 14000, 1) end addEvent("reparando", true) addEventHandler("reparando", root, reparo) bro you try to use setElementFrozen , setVehicleDoorOpenRation, fixVehicle ect. on an Element Data ! Link to comment
ber Posted June 9, 2020 Author Share Posted June 9, 2020 On 07/06/2020 at 13:07, MrKAREEM said: bro you try to use setElementFrozen , setVehicleDoorOpenRation, fixVehicle ect. on an Element Data ! No friend, getElementData is just to get the vehicle that was clicked on the Client-Side script. Link to comment
Moderators IIYAMA Posted June 9, 2020 Moderators Share Posted June 9, 2020 On 07/06/2020 at 04:37, ber said: This is the code I made, I have re-read it 10 times and I still haven't found where I may have gone wrong. function repair(_,state) if state == "down" then if isCursorOnElement(screenW * 0.5490, screenH * 0.4648, screenW * 0.6808, screenH * 0.5169) then if Kit_Reparo >= 1 then triggerEvent("startRepair", root) removeEventHandler("onClientRender", root, painelR) painel = false showCursor(false) else exports._infobox:addNotification("Você não possui kit de reparo!", "error") end end end end addEventHandler("onClientClick", root, repair) This addEventHandler is always attached and there is no validation that checks if the panel is open/button is visible. Link to comment
ber Posted June 11, 2020 Author Share Posted June 11, 2020 Thank you all for your help, I managed to resolve. The problem was in the triggerServer / ClientEvent Link to comment
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