Jump to content

Jayceon

Members
  • Posts

    91
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Jayceon

  1. We can not use findRotation, because we need left or right angles (it can be -10>n then it's a left turn, if it's 10<n then it's a right turn, if it's between -10 and 10 it is nothing) We have a table with precalculated values (the need field is what we need), but we get different numbers (got field) function getAngle(x1, y1, x2, y2) local angle = math.atan2(x1, y1) - math.atan2(x2, y2) if angle <= -math.pi then angle = angle + 2 * math.pi usedAlg = "hoz" else if angle + 2 * math.pi <= math.pi then angle = angle - 2 * math.pi usedAlg = "min" end end return -math.deg(angle) end pass fail || need: 13.532079523427 || got: -346.46792047657 fail || need: 368.80375654813 || got: 8.8037565481247 fail || need: 270 || got: -90 fail || need: -85.150542731867 || got: -85.150542731865 pass fail || need: 13.532079523427 || got: -346.46792047657 pass pass pass pass but it does not work
  2. Yes.. works perfectly, but not for my code. (Don't get all directions (left/right - like highways exit)
  3. Hello dear reader! I'm searching a math function to get the perfect angle. I have one function, but it not whole. function getAngle(x1, y1, x2, y2) while true do while true do if math.atan2(x2, y2) - math.atan2(x1, y1) <= -math.pi then end end end while true do if math.atan2(x2, y2) - math.atan2(x1, y1) + 2 * math.pi > math.pi then end end return math.atan2(x2, y2) - math.atan2(x1, y1) + 2 * math.pi - 2 * math.pi end Thanks the replies. (The findRotation and other simple functions not good for me.)
  4. I'm now tried the module in MTA SA 1.4 server and successfully loaded. What the problem with 1.5.4 server?
  5. I'm using it in client side, but tried it in server side. Every side return the "attempt to call" I don't know what the problem. I'm using Windows 10 Pro 64 bit, MTA SA server 1.5.4. The console show the module successfully loaded.
  6. I see the message in console. I tried to add mtaconf. Start server and the module is loaded, and tried the loadmodule command but nothing changes. The functions dont work.
  7. Yes. The console/debugscript didn't write anything error message. I tried the 32 and 64 bit modules, but same problem.
  8. I'm loaded the module, but i get "attempt to call global" error when i try to use those functions.
  9. Try this: nitroShader = dxCreateShader("nitro.fx", 0, 100, false, "vehicle")
  10. Jayceon

    Lights

    Yes, and this shader makes it. Only scripting needed.
  11. Jayceon

    Lights

    https://community.multitheftauto.com/index.php?p=resources&s=details&id=9398 But it require strong PC.
  12. -- Use custom font and set antialiased. dxCreateFont("path.format", size, false, "antialiased") -- for me work all times very good with my responsive multiplier
  13. I'm tried to compile vehicle nodes because i'm curious.
  14. No errors. I see other server compiled 5mb lua file (vehiclenodes). The compiler gives this: ERROR Could not read file
  15. Hello reader. I tried today to compile one big lua file (2 to 5 MB) but every luac compiler return error. I tried the https://luac.multitheftauto.com/ and the Windows batch file, but the result not changed. Thanks any answer.
  16. Hmm.. My code is work very well for myself.
  17. -- if doesCollide(firstRectangleX, firstRectangleY, firstRectangleWidth, firstRectangleHeight, secondRectangleX,secondRectangleY, secondRectangleWidth, secondRectangleHeight) then ... function doesCollide(x1, y1, w1, h1, x2, y2, w2, h2) local horizontal = (x1 < x2) ~= (x1 < x2 + w2) or (x1 + w1 < x2) ~= (x1 + w1 < x2 + w2) or (x1 < x2) ~= (x1 + w1 < x2) or (x1 < x2 + w2) ~= (x1 + w1 < x2 + w2) local vertical = (y1 < y2) ~= (y1 < y2 + h2) or (y1 + h1 < y2) ~= (y1 + h1 < y2 + h2) or (y1 < y2) ~= (y1 + h1 < y2) or (y1 < y2 + h2) ~= (y1 + h1 < y2 + h2) return (horizontal and vertical) end
  18. Hello dear reader! A few days ago i'm tried to make the Object Editor by XYZ Axle by cursor. But when i'm rotate camera to other side, like Y axle and i'm try to move X axle gets fail. I dont know how to get this perfect. Demonstration image: (red - X axle; green - Y axle; blue - Z axle) The code: local screenX, screenY = guiGetScreenSize() local editorFont = dxCreateFont("files/fonts/Roboto.ttf", 8, false, "antialiased") local editorTable = nil local editorMenu = { {"move", "Move"}, {"rotate", "Rotate"}, {"scale", "Scale"}, {"save", "Save"} } local iconSize = 16 local iconHalfSize = iconSize / 2 local axisLineThickness = 1.5 local editorColors = { axisX = {200, 50, 60}, axisY = {50, 200, 60}, axisZ = {50, 60, 200}, activeMode = {255, 150, 0}, inactiveMode = {255, 255, 255} } bindKey("F4", "down", -- Editor test function () local x, y, z = getElementPosition(localPlayer) local obj = createObject(2867, x, y, z) setElementCollisionsEnabled(obj, false) attachElements(obj, localPlayer, 0, 0, 0, 0, 0, 0) toggleEditor(obj, false) end ) addEventHandler("onClientRender", getRootElement(), function () if not editorTable then return end local absX, absY = 0, 0 if isCursorShowing() then if not isMTAWindowActive() then local relX, relY = getCursorPosition() absX, absY = relX * screenX, relY * screenY end end local elementX, elementY, elementZ = getElementPosition(editorTable["element"]) local startX, startY = getScreenFromWorldPosition(elementX, elementY, elementZ, 128) local xX, xY, xZ = getPositionFromElementOffset(editorTable["element"], editorTable["elementRadius"], 0, 0) local yX, yY, yZ = getPositionFromElementOffset(editorTable["element"], 0, editorTable["elementRadius"], 0) local zX, zY, zZ = getPositionFromElementOffset(editorTable["element"], 0, 0, editorTable["elementRadius"]) endXX, endXY = getScreenFromWorldPosition(xX, xY, xZ, 128) endYX, endYY = getScreenFromWorldPosition(yX, yY, yZ, 128) endZX, endZY = getScreenFromWorldPosition(zX, zY, zZ, 128) if not endXX or not endYX or not endZX or not endXY or not endYY or not endZY then return end dxDrawLine(startX, startY, endXX, endXY, tocolor(editorColors["axisX"][1], editorColors["axisX"][2], editorColors["axisX"][3], 255), axisLineThickness, false) dxDrawLine(startX, startY, endYX, endYY, tocolor(editorColors["axisY"][1], editorColors["axisY"][2], editorColors["axisY"][3], 255), axisLineThickness, false) dxDrawLine(startX, startY, endZX, endZY, tocolor(editorColors["axisZ"][1], editorColors["axisZ"][2], editorColors["axisZ"][3], 255), axisLineThickness, false) dxDrawRectangle(endXX - iconHalfSize, endXY - iconHalfSize, iconSize, iconSize, tocolor(editorColors["axisX"][1], editorColors["axisX"][2], editorColors["axisX"][3], 255)) dxDrawRectangle(endYX - iconHalfSize, endYY - iconHalfSize, iconSize, iconSize, tocolor(editorColors["axisY"][1], editorColors["axisY"][2], editorColors["axisY"][3], 255)) dxDrawRectangle(endZX - iconHalfSize, endZY - iconHalfSize, iconSize, iconSize, tocolor(editorColors["axisZ"][1], editorColors["axisZ"][2], editorColors["axisZ"][3], 255)) dxDrawImage(endXX - iconHalfSize, endXY - iconHalfSize, iconSize, iconSize, "files/images/" .. editorTable["currentMode"] .. ".png") dxDrawImage(endYX - iconHalfSize, endYY - iconHalfSize, iconSize, iconSize, "files/images/" .. editorTable["currentMode"] .. ".png") dxDrawImage(endZX - iconHalfSize, endZY - iconHalfSize, iconSize, iconSize, "files/images/" .. editorTable["currentMode"] .. ".png") if editorTable["hoveredMenuIcon"] then editorTable["hoveredMenuIcon"] = false end if not editorTable["activeAxis"] then for i = 1, #editorMenu do local currentColor = editorColors["inactiveMode"] if editorTable["currentMode"] == editorMenu[i][1] then currentColor = editorColors["activeMode"] end local iconX = ((startX - iconHalfSize) + ((i - 1) * (iconSize + 5))) + 32 local iconY = (startY - iconHalfSize) + 32 dxDrawRectangle(iconX, iconY, iconSize, iconSize, tocolor(currentColor[1], currentColor[2], currentColor[3], 255)) dxDrawImage(iconX, iconY, iconSize, iconSize, "files/images/" .. editorMenu[i][1] .. ".png") if absX >= iconX and absX <= iconX + iconSize and absY >= iconY and absY <= iconY + iconSize then editorTable["hoveredMenuIcon"] = i end end end if editorTable["hoveredMenuIcon"] then local tooltipWidth = dxGetTextWidth(editorMenu[editorTable["hoveredMenuIcon"]][2], 1.0, editorFont) + 10 local tooltipHeight = dxGetFontHeight(1.0, editorFont) + 10 dxDrawRectangle(absX + 10, absY, tooltipWidth, tooltipHeight, tocolor(0, 0, 0, 200)) dxDrawText(editorMenu[editorTable["hoveredMenuIcon"]][2], absX + 10, absY, absX + 10 + tooltipWidth, absY + tooltipHeight, tocolor(255, 255, 255, 255), 1.0, editorFont, "center", "center") if getKeyState("mouse1") then local hoveredMenuIcon = editorMenu[editorTable["hoveredMenuIcon"]][1] if editorTable["currentMode"] ~= hoveredMenuIcon then if hoveredMenuIcon ~= "save" then editorTable["currentMode"] = hoveredMenuIcon else saveEditorElementChanges() end end end end if editorTable and editorTable["hoveredMode"] then editorTable["hoveredMode"] = false end if absX >= endXX - iconHalfSize and absX <= endXX - iconHalfSize + iconSize and absY >= endXY - iconHalfSize and absY <= endXY - iconHalfSize + iconSize then editorTable["hoveredMode"] = "X" elseif absX >= endYX - iconHalfSize and absX <= endYX - iconHalfSize + iconSize and absY >= endYY - iconHalfSize and absY <= endYY - iconHalfSize + iconSize then editorTable["hoveredMode"] = "Y" elseif absX >= endZX - iconHalfSize and absX <= endZX - iconHalfSize + iconSize and absY >= endZY - iconHalfSize and absY <= endZY - iconHalfSize + iconSize then editorTable["hoveredMode"] = "Z" end -- OBJECT MOVE BY AXLES/CURSOR if editorTable and editorTable["activeAxis"] then if isCursorShowing() and getKeyState("mouse1") then local relX, relY = getCursorPosition() local cameraRotation = getCameraRotation() local elementX, elementY, elementZ = 0, 0, 0 local elementRX, elementRY, elementRZ = 0, 0, 0 local elementSX, elementSY, elementSZ = 0, 0, 0 if isElementAttached(editorTable["element"]) then elementX, elementY, elementZ, elementRX, elementRY, elementRZ = getElementAttachedOffsets(editorTable["element"]) local attachedElementRX, attachedElementRY, attachedElementRZ = getElementRotation(getElementAttachedTo(editorTable["element"])) cameraRotation = cameraRotation + attachedElementRZ else elementX, elementY, elementZ = getElementPosition(editorTable["element"]) elementRX, elementRY, elementRZ = getElementRotation(editorTable["element"]) end if getElementType(editorTable["element"]) == "object" then elementSX, elementSY, elementSZ = getObjectScale(editorTable["element"]) end if editorTable["currentMode"] == "move" then if editorTable["activeAxis"] == "X" then elementX = getInFrontOf(elementX, false, -(cameraRotation + 90), ((relX - 0.5) * 5)) elseif editorTable["activeAxis"] == "Y" then elementY = getInFrontOf(false, elementY, -cameraRotation, -((relY - 0.5) * 5)) elseif editorTable["activeAxis"] == "Z" then elementZ = elementZ - ((relY - 0.5) * 5) end elseif editorTable["currentMode"] == "rotate" then if editorTable["activeAxis"] == "X" then elementRX = getInFrontOf(elementRX, false, -(cameraRotation + 90), ((relY - 0.5) * 15)) elseif editorTable["activeAxis"] == "Y" then elementRY = getInFrontOf(false, elementRY, -cameraRotation, ((relX - 0.5) * 15)) elseif editorTable["activeAxis"] == "Z" then elementRZ = getInFrontOf(elementRZ, false, -(cameraRotation + 90), -((relX - 0.5) * 15)) end elseif editorTable["currentMode"] == "scale" then if editorTable["activeAxis"] == "X" then elementSX = getInFrontOf(elementSX, false, -(cameraRotation + 90), ((relX - 0.5) * 5)) elseif editorTable["activeAxis"] == "Y" then elementSY = getInFrontOf(false, elementSY, -cameraRotation, ((relY - 0.5) * 5)) elseif editorTable["activeAxis"] == "Z" then elementSZ = elementSZ - ((relY - 0.5) * 5) end end if isElementAttached(editorTable["element"]) then setElementAttachedOffsets(editorTable["element"], elementX, elementY, elementZ, elementRX, elementRY, elementRZ) else setElementPosition(editorTable["element"], elementX, elementY, elementZ) setElementRotation(editorTable["element"], elementRX, elementRY, elementRZ) end if getElementType(editorTable["element"]) == "object" then elementSX = math.max(0.25, math.min(3.0, elementSX)) elementSY = math.max(0.25, math.min(3.0, elementSY)) elementSZ = math.max(0.25, math.min(3.0, elementSZ)) setObjectScale(editorTable["element"], elementSX, elementSY, elementSZ) end setCursorPosition(screenX / 2, screenY / 2) setCursorAlpha(0) else if editorTable["activeAxis"] then editorTable["activeAxis"] = false setCursorAlpha(255) end end end end ) addEventHandler("onClientClick", getRootElement(), function (button, state, absX, absY) if not editorTable then return end if button == "left" then if state == "down" then if editorTable["hoveredMode"] then setCursorPosition(screenX / 2, screenY / 2) setCursorAlpha(0) editorTable["activeAxis"] = editorTable["hoveredMode"] end elseif state == "up" then local oldActiveAxis = editorTable["activeAxis"] if oldActiveAxis then editorTable["activeAxis"] = false if oldActiveAxis == "X" then setCursorPosition(endXX, endXY) elseif oldActiveAxis == "Y" then setCursorPosition(endYX, endYY) elseif oldActiveAxis == "Z" then setCursorPosition(endZX, endZY) end setCursorAlpha(255) end end end end ) function toggleEditor(element, saveFunction, ...) if element then editorTable = { element = element, elementRadius = getElementRadius(element) * 1.25, saveFunction = saveFunction, others = {...}, currentMode = "move", hoveredMode = false, hoveredMenuIcon = false, activeAxis = false, } else editorTable = nil setCursorAlpha(255) end end function saveEditorElementChanges() if not editorTable then return end if not editorTable["element"] or not isElement(editorTable["element"]) then return end if editorTable["saveFunction"] then if isElementAttached(editorTable["element"]) then local x, y, z, rx, ry, rz = getElementAttachedOffsets(editorTable["element"]) triggerEvent(editorTable["saveFunction"], localPlayer, {{x, y, z}, {rx, ry, rz}, {getObjectScale(editorTable["element"])}}, unpack(editorTable["others"])) else triggerEvent(editorTable["saveFunction"], localPlayer, {{getElementPosition(editorTable["element"])}, {getElementRotation(editorTable["element"])}, {getObjectScale(editorTable["element"])}}, unpack(editorTable["others"])) end end toggleEditor(false) end function getPositionFromElementOffset(element, offsetX, offsetY, offsetZ) local elementMatrix = getElementMatrix(element, false) local elementX = offsetX * elementMatrix[1][1] + offsetY * elementMatrix[2][1] + offsetZ * elementMatrix[3][1] + elementMatrix[4][1] local elementY = offsetX * elementMatrix[1][2] + offsetY * elementMatrix[2][2] + offsetZ * elementMatrix[3][2] + elementMatrix[4][2] local elementZ = offsetX * elementMatrix[1][3] + offsetY * elementMatrix[2][3] + offsetZ * elementMatrix[3][3] + elementMatrix[4][3] return elementX, elementY, elementZ end function getInFrontOf(x, y, angle, distance) distance = distance or 1 if x and not y then return x + distance * math.sin(math.rad(-angle)) elseif not x and y then return y + distance * math.cos(math.rad(-angle)) elseif x and y then return x + distance * math.sin(math.rad(-angle)), y + distance * math.cos(math.rad(-angle)) end end function getCameraRotation() local cx, cy, _, tx, ty = getCameraMatrix() return math.deg(math.atan2(tx - cx, ty - cy)) end Thanks the replies.
  19. Nem kell mindenkinek telepítenie.
  20. Thanks your answer, but this function is same problem. I now try to add previous road angle to every next road angle and then calculate it.
  21. I tried it, but the same problem.
  22. Hello. I started to create a real GPS with sound effects (like -> turn left, turn right, go x meters and turn left/right), but when i'm try to get the road angles the left/right turns fails. function createGPSRoute(x, y) local occupiedVehicle = getPedOccupiedVehicle(localPlayer) if occupiedVehicle then local vehicleX, vehicleY, vehicleZ = getElementPosition(occupiedVehicle) local _, _, vehicleRotation = getElementRotation(occupiedVehicle) gpsRoute = calculatePathByCoords(vehicleX, vehicleY, vehicleZ, x, y, 0) gpsWaypoints = {} if #gpsRoute ~= 0 then local possibleRoutes = {} for k, v in pairs(gpsRoute) do --[[ -- -- First attempt -- local nextNodeID = k + 1 local nextNode = gpsRoute[nextNodeID] if nextNode then table.insert(possibleRoutes, {k, nextNodeID}) end ]] local previousNodeID = k - 1 local previousNode = gpsRoute[previousNodeID] if previousNode then table.insert(possibleRoutes, {k, previousNodeID}) end end local turns = {} -- only the gps gui, turn left/right, go x meters.. local previousRoadAngle = 0 local previousRoadDirection = "" local forwardRoadCount = 0 local forwardRoadDistance = 750 for k, v in pairs(possibleRoutes) do local roadAngle = getAngle(gpsRoute[v[2]].x, gpsRoute[v[2]].y, gpsRoute[v[1]].x, gpsRoute[v[1]].y) local roadDirection = "N/A" local roadDistance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, gpsRoute[v[1]].x, gpsRoute[v[1]].y, gpsRoute[v[1]].z) if roadAngle <= 360 and roadAngle >= 180 then roadDirection = "right" elseif roadAngle >= 0 and roadAngle <= 180 then roadDirection = "left" end if k == 1 then previousRoadAngle = roadAngle previousRoadDirection = roadDirection end local nextNode = possibleRoutes[k + 1] table.insert(gpsWaypoints, {k, roadDirection, roadDistance, roadAngle}) -- this table for render to visible nodes and for the minimap lines if nextNode then local isTurnRoad = false if previousRoadAngle ~= roadAngle or roadDirection ~= previousRoadDirection then local angleDifference = getAnglesDifference(previousRoadAngle, roadAngle) if angleDifference ~= 0 then if angleDifference <= -12 or angleDifference >= 12 then table.insert(turns, {k, roadDirection, roadDistance}) isTurnRoad = true end end end if not isTurnRoad then if roadDistance >= forwardRoadDistance then -- add every 750 meters isForwardRoad = true forwardRoadDistance = forwardRoadDistance + 750 table.insert(turns, {k, "forward", roadDistance}) end end previousRoadAngle = roadAngle previousRoadDirection = roadDirection end if k == #possibleRoutes then table.insert(turns, {"end", "end", roadDistance}) -- the last node, when reach it the gps destination switch off end end outputConsole(inspect(turns)) -- print the possible turns/directions. format: {table id, direction (left/right/forward), distance between) end end end function getAnglesDifference(angle1, angle2) angle1 = angle1 % 360 angle2 = angle2 % 360 local difference = (angle1 - angle2) % 360 if difference <= 180 then return difference else return -(360 - difference) end end function getAngle(x1, y1, x2, y2) local angle = -math.deg(math.atan2(x2 - x1, y2 - y1)) if angle < 0 then angle = angle + 360 end return angle end --[[ -- I tried the next function, but the same problem function getAngle(x1, y1, x2, y2) return (360 - math.deg(math.atan2((x2 - x1), (y2 - y1)))) % 360 end]] Thanks the replies.
  23. Jayceon

    Crossroad

    Hello. I tried to get the crossroad and crossroad angles but i don't know how. I'm using the vehicle nodes path and i have small code to get road nodes angle but it get all nodes and i'm only need the crossroads. The current code: function createGPSRoute(x, y, x2, y2) local occupiedVehicle = getPedOccupiedVehicle(localPlayer) local vehicleX, vehicleY, vehicleZ = getElementPosition(occupiedVehicle) if occupiedVehicle then local startNode = findNodePosition(x, y) local endNode = findNodePosition(x2, y2) local gpsRoute = getNodePath(startNode, endNode) if #gpsRoute ~= 0 then local gpsWaypoints = {} for k, v in pairs(gpsRoute) do local nextNode = gpsRoute[k + 1] if nextNode then local roadRotation = (360 - math.deg(math.atan2((nextNode.x - vehicleX), (nextNode.y - vehicleY)))) % 360 local _, _, vehicleRotation = getElementRotation(occupiedVehicle) local vehicleRotation = vehicleRotation or 0 local roadAngle = (roadRotation - vehicleRotation) % 360 local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, nextNode.x, nextNode.y, nextNode.z) local accuracy = distance < 7 and 20 or 6 if roadAngle > -accuracy and roadAngle < accuracy then table.insert(gpsWaypoints, {nextNode.neighbours, "forward", distance}) elseif roadAngle <= 360 and roadAngle >= 180 then table.insert(gpsWaypoints, {nextNode.neighbours, "right", distance}) elseif roadAngle >= 0 and roadAngle <= 180 then table.insert(gpsWaypoints, {nextNode.neighbours, "left", distance}) end end end outputConsole(inspect(gpsWaypoints)) -- debug to console end end end Thanks the replies.
×
×
  • Create New...