Dzsozi (h03)

Members
  • Content count

    570
  • Joined

  • Last visited

  • Days Won

    1

Dzsozi (h03) last won the day on December 25 2017

Dzsozi (h03) had the most liked content!

Community Reputation

54 Popular

About Dzsozi (h03)

  • Rank
    Mack

Details

  • Location
    Hungary

Recent Profile Visitors

2,617 profile views
  1. checkpoint

    Try it this way, since you are trying to make the marker disappear in a vehicle on the picture, but the hitElement must be the localPlayer based on the previous code. addEventHandler( "onClientMarkerHit", resourceRoot, function (hitElement, dim) if (curMarker and source == curMarker and (hitElement == localPlayer or hitElement == getPedOccupiedVehicle(localPlayer)) and dim) then ID = ID + 1 if ID > #markers then ID = 1 end createCheckpoint( ID ) -- create the next checkpoint end end ) Or just try deleting it and then test if and see if it works. addEventHandler( "onClientMarkerHit", resourceRoot, function (hitElement, dim) if (curMarker and source == curMarker and dim) then ID = ID + 1 if ID > #markers then ID = 1 end createCheckpoint( ID ) -- create the next checkpoint end end )
  2. Get perfect positions based on rotation

    Thank you, I managed to fix it that way: local xa, ya, za = getPositionFromElementOffset(matching.element,matching.pos.x, matching.pos.y+data.size, 0) local xb, yb, zb = getPositionFromElementOffset(matching.element,matching.pos.x, matching.pos.y-data.size, 0)
  3. Get perfect positions based on rotation

    This is not working out really well. Here's my full code, it would be awesome if you could help me! Client: local lightShadowVisibleDistance = 50 --local tailLightShadow = dxCreateTexture("files/images/groundLightShadow.png") local lightShadowTypes = { ["pointlight"] = dxCreateTexture("files/images/pointlight.png"), ["taillight"] = dxCreateTexture("files/images/taillight.png"), } local groundLightShadows = {} local attachedGroundLightShadows = {} function createLightShadow(x, y, z, shadowType, size, r,g,b,a) local vehicleLightShadow = createElement("vehicleLightShadow") local groundPosition = getGroundPosition(x, y, z) setElementPosition(vehicleLightShadow, x, y, groundPosition+0.03) if not r then r = 255 end if not g then g = 255 end if not b then b = 255 end if not a then a = 255 end if not size then size = 2 end if not shadowType then shadowType = "normal" end local array = {} array.color = {r,g,b,a} array.size = size --local renderTarget = dxCreateRenderTarget(512, 512, true) --[[dxSetRenderTarget(renderTarget, true) local width, height = dxGetMaterialSize(renderTarget) dxSetBlendMode("add") dxDrawImage(width, height, width-width*2, height-height*2, tailLightShadow, 0, 0, 0, tocolor(255,255,255,255)) dxSetBlendMode("blend") dxSetRenderTarget()]] --array.texture = renderTarget --if array.texture and isElement(array.texture) then -- setElementParent(array.texture, vehicleLightShadow) --end array.lightShadow = vehicleLightShadow array.lightShadowType = shadowType groundLightShadows[vehicleLightShadow] = array return vehicleLightShadow end function attachGroundLightShadow(lightShadow, element, pos) attachedGroundLightShadows[lightShadow] = { lightShadow = lightShadow, element = element, pos = pos } addEventHandler("onClientElementDestroy", lightShadow, function() attachedGroundLightShadows[lightShadow] = nil end) addEventHandler("onClientElementDestroy", element, function() attachedGroundLightShadows[lightShadow] = nil end) return true end local function getPositionInFront(element,meters,component) local x,y,z = getVehicleComponentPosition(element, component, "world") local a,b,r = getVehicleComponentRotation(element, component, "world") x = x - math.sin(math.rad(r)) * meters y = y + math.cos(math.rad(r)) * meters return x,y end addEventHandler("onClientPreRender", root, function() local cameraX, cameraY, cameraZ = getCameraMatrix() for groundLightShadow, info in pairs(attachedGroundLightShadows) do local x, y, z = getPositionFromElementOffset(info.element, info.pos.x, info.pos.y, info.pos.z) setElementPosition(groundLightShadow, x, y, z) end for k, data in pairs(groundLightShadows) do if data.lightShadow and isElement(data.lightShadow) then local worldX, worldY, worldZ = getElementPosition(data.lightShadow) local groundPosition = getGroundPosition(worldX, worldY, worldZ) local fixedGroundPosition = groundPosition+0.03 local onScreenX, onScreenY = getScreenFromWorldPosition(worldX, worldY, fixedGroundPosition, 20) if onScreenX and onScreenY then local lightColor = data.color local distance = getDistanceBetweenPoints3D(worldX, worldY, fixedGroundPosition, cameraX, cameraY, cameraZ) if distance <= lightShadowVisibleDistance then if isLineOfSightClear(cameraX, cameraY, cameraZ, worldX, worldY, fixedGroundPosition, true, false, false, false, false, true) then --local renderTarget = data.texture --dxSetRenderTarget(renderTarget, true) --local width, height = dxGetMaterialSize(renderTarget) --dxSetBlendMode("add") --dxDrawImage(width, height, width-width*2, height-height*2, tailLightShadow, 0, 0, 0, tocolor(255,255,255,255)) --dxSetBlendMode("blend") --dxSetRenderTarget() --local width, height = dxGetMaterialSize(data.texture) --dxSetRenderTarget(data.renderTarget, true) --dxSetBlendMode("add") --dxDrawImage(0, 0, width, height, data.texture, 0, 0, 0, tocolor(255,255,255,255)) --dxSetBlendMode("blend") --dxSetRenderTarget() local matching = attachedGroundLightShadows[data.lightShadow] if matching then local elementX, elementY, elementZ = getElementPosition(matching.element) local rx, ry, rz = getElementRotation(matching.element) local facez = getGroundPosition(elementX, elementY, elementZ + 5000000) local x, y, z = getPositionFromElementOffset(matching.element, matching.pos.x, matching.pos.y, facez) if elementZ <= fixedGroundPosition+2 then dxSetBlendMode("add") dxDrawMaterialLine3D(worldX, worldY-data.size, fixedGroundPosition, worldX, worldY+data.size, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), x, y, z) dxSetBlendMode("blend") end else dxSetBlendMode("add") dxDrawMaterialLine3D(worldX, worldY-data.size, fixedGroundPosition, worldX, worldY+data.size, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), x, y, z) dxSetBlendMode("blend") end end end end end end end, true, "low-1" ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end collectgarbage("collect") --local xddd = createLightShadow(1957.5991210938,-2288.2802734375,13.546875, 245,140,20,255) And here are the images I am currently using: https://imgur.com/a/MUYXbnq My problem is that the images doesn't rotate with the vehicle when I use the "attachGroundLightShadow" function in an other script. I would like to make the attached light shadows rotate with the vehicle in the direction the vehicle facing, or it would be even better if I could change the rotation when calling the "createLightShadow" function. Hope you understand me and you can help me.
  4. Get perfect positions based on rotation

    Hello! I am working on a "low-quality" way of light shadows, working with dx functions. I want to use it for my vehicle system. I have a problem with this function's position calculations. I would like to make the shadow always rotate in the direction as the attached element, in this case the vehicle. The function uses dxDrawMaterialLine3D drawing function, so I guess I would have to get the left and the right side of the element (vehicle), and get a rotation based on that, and then use math.cos and math.sin? Maybe, I am not so sure, I was trying something like this but it was not working. Here's the part of the code mentioned: local matching = attachedGroundLightShadows[data.lightShadow] if matching then local elementX, elementY, elementZ = getElementPosition(matching.element) local rx, ry, rz = getElementRotation(matching.element) local facez = getGroundPosition(elementX, elementY, elementZ + 5000000) local x, y, z = getPositionFromElementOffset(matching.element, matching.pos.x, matching.pos.y, facez) if elementZ <= fixedGroundPosition+2 then dxSetBlendMode("add") dxDrawMaterialLine3D(worldX, worldY-data.size, fixedGroundPosition, worldX, worldY+data.size, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), x, y, z) dxSetBlendMode("blend") end else dxSetBlendMode("add") dxDrawMaterialLine3D(worldX, worldY-data.size, fixedGroundPosition, worldX, worldY+data.size, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), x, y, z) dxSetBlendMode("blend") end And here's the current results: This would be the good rotation for the image: But the problem is that the image always has the same rotation, doesn't matter what's the vehicle's rotation: I would like to ask for help with the position and rotation calculations for this script, I don't know how to fix it!
  5. Green screen shader

    I do not know how to write shader files.
  6. [Help] Arrow that targeting one position

    I am not sure, but try changing the rotation by adding + 90 or so values, since the default object rotation might not fit your needs. setElementRotation( object, rx, ry, rz + 90 )
  7. Green screen shader

    And how do I do that? I don't know.
  8. Green screen shader

    Sorry for bringing up this topic. Can you help me out with that? I can't do it by myself, I am not a shader expert.
  9. [Help] Arrow that targeting one position

    Maybe these functions can help you. I don't know which way you want to do your thing, 2D or 3D. https://wiki.multitheftauto.com/wiki/FindRotation3D - for a 3D pickup https://wiki.multitheftauto.com/wiki/GetScreenRotationFromWorldPosition - for a dxDraw image
  10. Check if something is within four given points

    Thank you so much for your help!
  11. Help DxRetangle

    Anytime!
  12. Help DxRetangle

    Try this. 📋 local screenW, screenH = guiGetScreenSize() -- you don't have to get the screen size inside the render function local disappearTime = 10 -- seconds function renderPanel() dxDrawLine((screenW * 0.4281) - 1, (screenH * 0.1380) - 1, (screenW * 0.4281) - 1, screenH * 0.4232, tocolor(0, 0, 0, 255), 1, false) dxDrawLine(screenW * 0.5594, (screenH * 0.1380) - 1, (screenW * 0.4281) - 1, (screenH * 0.1380) - 1, tocolor(0, 0, 0, 255), 1, false) dxDrawLine((screenW * 0.4281) - 1, screenH * 0.4232, screenW * 0.5594, screenH * 0.4232, tocolor(0, 0, 0, 255), 1, false) dxDrawLine(screenW * 0.5594, screenH * 0.4232, screenW * 0.5594, (screenH * 0.1380) - 1, tocolor(0, 0, 0, 255), 1, false) dxDrawRectangle(screenW * 0.4281, screenH * 0.1380, screenW * 0.1313, screenH * 0.2852, tocolor(0, 0, 0, 98), false) end function handlePanelRender(state) removeEventHandler("onClientRender",getRootElement(),renderPanel) if state then addEventHandler("onClientRender",getRootElement(),renderPanel) end -- if you want the timer solution then just delete the --[[ and the ]] at the end and delete the code above --[[ removeEventHandler("onClientRender",getRootElement(),renderPanel) -- add this so there won't be errors in debugscript about event is being already handled addEventHandler("onClientRender",getRootElement(),renderPanel) setTimer(function() removeEventHandler("onClientRender",getRootElement(),renderPanel) end, disappearTime*1000, 1) ]] end addEvent ("onSpecialEvent", true) addEventHandler ("onSpecialEvent", root, handlePanelRender) ---Server triggerClientEvent(player,"onSpecialEvent",player, true) -- change true to false if you want to make the panel disappear
  13. Hello! I am trying to do a boundary system based on coordinates, so no col shapes or anything. Unfortunately I'm not that good at math, but I tried doing it based on found results on the internet. My problem is that this whole script is not working how it should, check it for yourself, it has debug outputs and visible markers for corners and the center. Why does the width and height return a much bigger number than the calculatedX and calculatedY? Why does the calculatedX and calculatedY return always the same? Why does the width and height change values as I move around? I would be really grateful if somebody could help me, this is for a community project, so others would be too! Here's my current full code: Global: customBoundaries = { -- this boundary is between the big brown building(s) and the skatepark on the road in LS ["test"] = { point1 = {x = 1842.2908935547, y = -1412.469360351}, point2 = {x = 1856.8596191406, y = -1412.555664062}, point3 = {x = 1851.5925292969, y = -1436.5225830078}, point4 = {x = 1842.0438232422, y = -1424.5217285156}, }, } Client: local debugEnabled = true function sum(n) return ((n+1) * n) / 2 end function isElementWithinBoundary(element, boundary) if element and isElement(element) then local elementX, elementY, elementZ = getElementPosition(element) boundary = tostring(boundary) if boundary and type(boundary) == "string" then if customBoundaries and customBoundaries[boundary] then local corner1 = {customBoundaries[boundary].point1.x, customBoundaries[boundary].point1.y} local corner2 = {customBoundaries[boundary].point2.x, customBoundaries[boundary].point2.y} local corner3 = {customBoundaries[boundary].point3.x, customBoundaries[boundary].point3.y} local corner4 = {customBoundaries[boundary].point4.x, customBoundaries[boundary].point4.y} local centerX, centerY = (corner1[1] + corner2[1] + corner3[1] + corner4[1])/4, (corner1[2] + corner2[2] + corner3[2] + corner4[2])/4 local originX, originY = elementX - corner1[1], elementY - corner1[2] local width = math.sqrt((corner2[1] - originX)^2 + (corner2[2] - originY)^2) local height = math.sqrt((corner4[1] - originX)^2 + (corner4[2] - originY)^2) local calculatedX = originX * (corner2[1] - originX)/width + originY * (corner2[2] - originY)/height local calculatedY = originX * (corner4[1] - originX)/width + originY * (corner4[2] - originY)/height outputChatBox("X: " .. math.floor(calculatedX) .. " | width: " .. math.floor(width)) outputChatBox("Y: " .. math.floor(calculatedY) .. " | height: " .. math.floor(height)) if (0 <= calculatedX and calculatedX <= width) and (0 <= calculatedY and calculatedY <= height) then outputChatBox("XD") end if debugEnabled then for points, coordinates in pairs(customBoundaries[boundary]) do local cornerMarker = createMarker(coordinates.x, coordinates.y, getGroundPosition(coordinates.x, coordinates.y, elementZ), "cylinder", 2, 140, 245, 20, 150) local centerMarker = createMarker(centerX, centerY, getGroundPosition(centerX, centerY, elementZ)+2, "arrow", 1, 245, 140, 20, 150) end end end end end end isElementWithinBoundary(localPlayer, "test") Here's the calculation I was trying to copy and make it work based on: https://math.stackexchange.com/a/190257 I hope you understand my problem, thank you for your reply in advance!
  14. [JS]Converted Maps

    Maybe a custom map editor to support self-customised JStreamer maps? Would be 10/10
  15. Custom Client

    And better performance is what I am trying to achieve.