TrickyTommy Posted August 17, 2017 Posted August 17, 2017 Hi! I am trying to make two things on my server: -license plates above cars, and rectangles above them too. -player nametags, and my nametag should not be visible for myself. I have problems with both:-the rectrangle is not getting drawn above the car -i don't know how sould i make my nametag not visible for myself. Current progress: function Draw() local vehs = getElementsByType("vehicle") for k,v in ipairs(vehs) do dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2) local x, y, z = getElementPosition (v) dxDrawRectangle3D (x+1, y+1, z+1, 100, 25, tocolor(255, 0, 0, 0)) end local players = getElementsByType("player") for k,v in ipairs(players) do dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1) end end addEventHandler ("onClientRender", getRootElement(), Draw)
N3xT Posted August 17, 2017 Posted August 17, 2017 try that, If doesn't work perfectly screenshot please. function Draw() local vehs = getElementsByType("vehicle") for k,v in ipairs(vehs) do dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2) local x, y, z = getElementPosition (v) local width = 100 local hight = 50 dxDrawRectangle3D (x, y, z+, width, hight, tocolor(255, 0, 0, 0)) end local players = getElementsByType("player") for k,v in ipairs(players) do if v ~= localPlayer then dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1) end end end addEventHandler ("onClientRender", getRootElement(), Draw)
TrickyTommy Posted August 17, 2017 Author Posted August 17, 2017 6 hours ago, N3xT said: try that, If doesn't work perfectly screenshot please. function Draw() local vehs = getElementsByType("vehicle") for k,v in ipairs(vehs) do dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2) local x, y, z = getElementPosition (v) local width = 100 local hight = 50 dxDrawRectangle3D (x, y, z+, width, hight, tocolor(255, 0, 0, 0)) end local players = getElementsByType("player") for k,v in ipairs(players) do if v ~= localPlayer then dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1) end end end addEventHandler ("onClientRender", getRootElement(), Draw) think the solution for the nametag works, yet the rectangle is not visible....
_DrXenon Posted August 17, 2017 Posted August 17, 2017 The rectangle's alpha is set to 0. dxDrawRectangle3D (x, y, z+, width, hight, tocolor(255, 0, 0, 0)) change the tocolor arg into this; tocolor(255,0,0,255).
TrickyTommy Posted August 17, 2017 Author Posted August 17, 2017 as i know, the first one is the argument for alpha. anyways, still not working dxDrawRectangle3D (x, y, z+1, 100, 50, tocolor(255, 255, 255, 255))
N3xT Posted August 18, 2017 Posted August 18, 2017 did you put the source code of the useful functions?
Mr.Loki Posted August 18, 2017 Posted August 18, 2017 I modified the custom function a bit... but this is what it does. I hope this helps. Also added another arg to set the background colour or hide it. https://gfycat.com/UnimportantHiddenIberianmole function Draw() local vehs = getElementsByType("vehicle") local players = getElementsByType("player") for k,v in ipairs(vehs) do if getPedOccupiedVehicle( localPlayer ) ~= v then dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2, _, tocolor(0,0,0,255)) end end for k,v in ipairs(players) do if v ~= localPlayer then dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1) end end end addEventHandler ("onClientRender", getRootElement(), Draw) function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,bgColor,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement) local x, y, z = getElementPosition(TheElement) local x2, y2, z2 = getCameraMatrix() local distance = distance or 20 local height = height or 1 local checkBuildings = checkBuildings or true local checkVehicles = checkVehicles or false local checkPeds = checkPeds or false local checkObjects = checkObjects or true local checkDummies = checkDummies or true local seeThroughStuff = seeThroughStuff or false local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false local ignoredElement = ignoredElement or nil if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then local sx, sy = getScreenFromWorldPosition(x, y, z+height) if(sx) and (sy) then local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) if(distanceBetweenPoints < distance) then if bgColor then local tw = dxGetTextWidth( text, size or 1, font or "arial" ) local tw = tw-((distanceBetweenPoints / distance)*(tw/2)) local th = (12*size)-((distanceBetweenPoints / distance)*12) dxDrawRectangle( sx-(tw/2)-1, sy-(th/2)-1, tw+3, th+3 , bgColor) end dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center") end end end end
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