Jump to content

Dzsozi (h03)

Members
  • Posts

    696
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Dzsozi (h03)

  1. I suggest you using https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision
  2. A possibility to change/replace some object textures and some default extra stuff like walls from SA:MP or something like that to make custom interior and house mapping more supported? I would really like to see that advanced mapping oppurtinity in MTA:SA and that would be really useful for custom stuff.
  3. 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 )
  4. 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)
  5. 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.
  6. 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!
  7. I do not know how to write shader files.
  8. 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 )
  9. And how do I do that? I don't know.
  10. 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.
  11. 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
  12. 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. Maybe a custom map editor to support self-customised JStreamer maps? Would be 10/10
  15. And better performance is what I am trying to achieve.
  16. I found this logo I made a while back on my computer while I was deleting unwanted files. I thought this might be useful for others who want to make a custom logo for their servers or just photoshop something. For example, this is the final logo I created it for: Original sizes Horizontal: 1900 x 350 Square: 1250 x 1250 DOWNLOAD (.rar file containing the full size original .png files. No quality loss.)
  17. First I was thinking about a custom launcher as well, and I wanted to do that but I don't know how. But what do you mean by it is useless? Can I do everything without making a custom launcher or anything, just by modifying MTA settings or what? Could you explain it a little bit better?
  18. Oh, alright, sorry I didn't know that. Could a moderator move this topic to the correct section?
  19. Thank you for your reply, but this is still not the effect I would like to reach. There's the cartoon shader, it has an outline shader that is being applied for everything, I just need to know how can I get this outline and apply it to an element I choose.
  20. Hi! I would like to do a custom MTA client. Here's the reason why I was thinking about it: I would like to change the map from SA to a different one, I know it is possibble with scripting, but I would like to go a little bit deeper and replace it in the "engine" if you know what I mean. I was thinking about replacing the gta3.img files and other ipl and xml and such files with the default ones, but I don't know how I should start doing it. I never did something like this. How I could achieve that MTA would load a different gta3.img for example, with the modded objects and vehicles and such, so whenever I start my custom client, I could only join to my own server and it wouldn't download and load the custom map, since the downloaded custom client already has the files by default and it loads it first, instead of the SA map. I would really appreciate if somebody could help me out which way I should start looking forward to do it or how to do it. I know that the SA:MP client requires you to choose the default GTA SA folder, and it also puts some stuff in there, maybe an img file if I remember correctly, since SAMP uses some custom objects. Also, that way (with the custom client/launcher) it may be possibble to add extra models/objects to the game in MTA? It would be nice if someone more experienced scripter or programmer could provide some information in connection with this. EDIT: I am also interested if using custom img and definition files for coordinates is more PC and FPS friendly than just using simple lua scripts in MTA SA to replace objects.
  21. I wouldn't have opened a topic here if I could do it by myself. That doesn't help me out much.
×
×
  • Create New...