..:D&G:.. Posted February 16, 2015 Share Posted February 16, 2015 Hello, I am trying to make a function that adds a 3D, dxDrawn box with text on an object (id 2754) but next to it... function renderInteraction() local he = (getElementModel(source) == 2754) if(isElement(he)) and (isPedInVehicle(localPlayer) == false) then local x, y, z = getElementPosition(he) local sx, sy = getScreenFromWorldPosition(x, y, z, 500) local r, g, b = 255, 255, 255 if(sx) and (sy) then if(getElementType(he) == "object") then sx = sx-50 sy = sy-130 end -- sx = sx+100 local x2, y2, z2 = getElementPosition(localPlayer) local dis = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) -- RECTANGLE -- dxDrawRectangle(sx-70, sy, 100-(dis*10), 130-(dis*10), tocolor(0, 0, 0, 100)) dxDrawImage(sx-70, sy, 100-(dis*10), 130-(dis*10), "[wattz]realism-system/rahmen.png", 0, 0, 0, tocolor(255, 255, 255, 255)) -- Strich -- dxDrawRectangle(sx-70, sy+20, 100-(dis*10), 1, tocolor(0, 0, 0, 250)) -- TEXT -- local titel, beschreibung = "", "" if(getElementType(he) == "object") then titel = "Coins Exchange Machine" beschreibung = "Schimbă monedele în\nbani! (Click Dreapta)" r, g, b = 255, 255, 0 end local scale = 2/dis if(scale > 1) then scale = 1 end dxDrawText(titel, sx-60, sy+2, 100-(dis*10), 100-(dis*10), tocolor(r, g, b, 200), scale, "default-bold", "left", "top", false, true) dxDrawText(beschreibung, sx-60, sy+50, 100-(dis*10), 130-(dis*10), tocolor(255, 255, 255, 200), scale, "default-bold", "left", "top", false, true) end end end addEventHandler("onClientRender", getRootElement(), renderInteraction) There are not errors but it doesn't work. I know that local he = (getElementModel(source) == 2754) won't work, but what else can I use to get all the objects (2754) from the world and attach the box next to them? Thank you. Link to comment
JR10 Posted February 16, 2015 Share Posted February 16, 2015 If you're talking about created objects then this will loop through all the objects with model == 2754: for index, element in pairs(getElementsByType("object")) do if (getElementModel(element) == 2754) then --Do smth end end Link to comment
..:D&G:.. Posted February 17, 2015 Author Share Posted February 17, 2015 It worked, but now if I am far away from the objects, the boxes from every object gets bigger and on my screen instead of getting smaller and disappearing as I get away from the object Link to comment
Deepu Posted February 17, 2015 Share Posted February 17, 2015 you can use these functions for reducing offsets interpolateBetween getDistanceBetweenPoints3D -- uses pythagoras theorem. getCameraMatrix getElementPosition -- for both localPlayer and object and if you want all objects to do this, then loop it using... -- a new function.. function getElementsByModel (modelID) vehicles = getElementsByType("objects") for i=dakndakd dkasdnka end -- make something like that Link to comment
JR10 Posted February 17, 2015 Share Posted February 17, 2015 In getScreenFromWorldPosition, your edgeTolerence is 500, but it's expecting it to be relative to the screen. float float getScreenFromWorldPosition ( float x, float y, float z, [ float edgeTolerance=0, bool relative=true ] ) So, the fifth argument should be false. Also, 500 is kinda far from the object, you might want to decrease it. If this doesn't work, please post your updated code. Link to comment
..:D&G:.. Posted February 17, 2015 Author Share Posted February 17, 2015 That didn't change anything. Here is what I done: for index, he in pairs(getElementsByType("object")) do if (getElementModel(he) == 2754) then local x, y, z = getElementPosition(he) local sx, sy = getScreenFromWorldPosition(x, y, z, 200, false) local r, g, b = 255, 255, 255 if(sx) and (sy) then if(getElementType(he) == "object") then sx = sx-50 sy = sy-130 end -- sx = sx+100 local x2, y2, z2 = getElementPosition(localPlayer) local dis = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) But maybe there is something wrong with the dx part? local scale = 2/dis if(scale > 0.9) then scale = 0.95 end dxDrawText(titel, sx-65, sy+2, 100-(dis*10), 100-(dis*10), tocolor(r, g, b, 200), scale, "default-bold", "left", "top", false, true) dxDrawText(beschreibung, sx-65, sy+50, 100-(dis*10), 130-(dis*10), tocolor(255, 255, 255, 200), scale, "default-bold", "left", "top", false, true) end And here is a picture of what is happening: http://4stor.com/owWvH Link to comment
JR10 Posted February 17, 2015 Share Posted February 17, 2015 Post the full current code. This way, when someone wants to help you he can test it himself. Link to comment
..:D&G:.. Posted February 17, 2015 Author Share Posted February 17, 2015 Here: function renderInteraction() for index, he in pairs(getElementsByType("object")) do if (getElementModel(he) == 2754) then local x, y, z = getElementPosition(he) local sx, sy = getScreenFromWorldPosition(x, y, z, 200, false) local r, g, b = 255, 255, 255 if(sx) and (sy) then if(getElementType(he) == "object") then sx = sx-50 sy = sy-130 end -- sx = sx+100 local x2, y2, z2 = getElementPosition(localPlayer) local dis = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) -- RECTANGLE -- dxDrawRectangle(sx-70, sy, 130-(dis*10), 130-(dis*10), tocolor(0, 0, 0, 100)) dxDrawImage(sx-70, sy, 130-(dis*10), 130-(dis*10), "rahmen.png", 0, 0, 0, tocolor(255, 255, 255, 255)) -- Strich -- dxDrawRectangle(sx-70, sy+30, 130-(dis*10), 1, tocolor(0, 0, 0, 250)) -- TEXT -- local titel, beschreibung = "", "" if(getElementType(he) == "object") then titel = " Coins Exchange\n Machine" beschreibung = "Exchange coins into cash!" r, g, b = 255, 255, 0 end local scale = 2/dis if(scale > 0.9) then scale = 0.95 end dxDrawText(titel, sx-65, sy+2, 100-(dis*10), 100-(dis*10), tocolor(r, g, b, 200), scale, "default-bold", "left", "top", false, true) dxDrawText(beschreibung, sx-65, sy+50, 100-(dis*10), 130-(dis*10), tocolor(255, 255, 255, 200), scale, "default-bold", "left", "top", false, true) end end end end addEventHandler("onClientRender", getRootElement(), renderInteraction) 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