Einheit-101 Posted March 4, 2011 Share Posted March 4, 2011 Hello again... Little Question. How to draw a StaticImage above each player`s head (like his nametag)? I want to make this looking like the chaticon resource (but it is no chaticon ) I hope anybody knows how to reaslize that! Link to comment
Castillo Posted March 4, 2011 Share Posted March 4, 2011 I would recommend using DX drawing for this. https://wiki.multitheftauto.com/wiki/DxDrawImage Link to comment
proracer Posted March 4, 2011 Share Posted March 4, 2011 Yes .. and there is an similiar example on Wiki: https://wiki.multitheftauto.com/wiki/GetPedBonePosition Link to comment
Einheit-101 Posted March 4, 2011 Author Share Posted March 4, 2011 is it possible to draw that image ONLY over the head of an admin player? addEventHandler("onClientRender",getRootElement(), function() local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix() for k, v in ipairs(getElementsByType("player")) do if(getElementData(v, "Admin") == true) then tx, ty, tz = getElementPosition(v) dist = math.sqrt((px - tx) ^ 2 + (py - ty) ^ 2 + (pz - tz) ^ 2) if dist < 30.0 then if isLineOfSightClear(px, py, pz, tx, ty, tz, true, false, false, true, false, false, getLocalPlayer()) then local sx, sy, sz = getPedBonePosition(v, 5) local x,y = getScreenFromWorldPosition(sx, sy, sz + 0.3) if x then dxDrawImage ( x, y, 140, 140, "rang/admin.png" ) end end end end end ) Thats what i have. Link to comment
Castillo Posted March 4, 2011 Share Posted March 4, 2011 And? does it work? any errors? Link to comment
Einheit-101 Posted March 4, 2011 Author Share Posted March 4, 2011 The Problem is that the rest of the script is not finished. I will be able to test it if the rest works. Rank system Link to comment
Ransom Posted March 4, 2011 Share Posted March 4, 2011 getScreenFromWorldPosition makes the illusion of 3D drawn images possible. All the rest is up to your specifications. Of course you can have a trigger to only draw for admin. I don't see why you can't test that... put it some temp setElementData and comment it as debug. Link to comment
Einheit-101 Posted March 5, 2011 Author Share Posted March 5, 2011 it still does not work... here is what ive done: function imagedraw() local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix() for k, v in ipairs(getElementsByType("player")) do if(getElementData(v, "Admin") == true) then tx, ty, tz = getElementPosition(v) dist = math.sqrt((px - tx) ^ 2 + (py - ty) ^ 2 + (pz - tz) ^ 2) if dist < 30.0 then if isLineOfSightClear(px, py, pz, tx, ty, tz, true, false, false, true, false, false, getLocalPlayer()) then local sx, sy, sz = getPedBonePosition(v, 5) local x,y = getScreenFromWorldPosition(sx, sy, sz + 0.3) if x then dxDrawImage ( x, y, 50, 50, "rang/admin.png" ) end end end end end end addEventHandler("onClientRender",getRootElement(),imagedraw) I have set the Element Data to admin in another script. Link to comment
Moderators Citizen Posted March 6, 2011 Moderators Share Posted March 6, 2011 Hi, It's very simple, at this line: local x,y = getScreenFromWorldPosition(sx, sy, sz + 0.3) The function returns the relative position and the dxDrawImage need the absolute position ! So you have to convert this relative position to an absolute position. The full script ( with some little modifications ): function imagedraw() local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix() for k, v in ipairs(getElementsByType("player")) do if(getElementData(v, "Admin") == true) then tx, ty, tz = getElementPosition(v) dist = getDistanceBetweenPoints3D( px, py, pz, tx, ty, tz ) if dist < 30.0 then if isLineOfSightClear(px, py, pz, tx, ty, tz, true, false, false, true, false, false, getLocalPlayer()) then local sx, sy, sz = getPedBonePosition(v, 5) local x,y = getScreenFromWorldPosition(sx, sy, sz+0.3) if ( x >= 0 and x <= 1 and y >= 0 and y <= 1 ) then x, y = AbsoluteToRelativ( x, y ) dxDrawImage ( x, y, 50, 50, "rang/admin.png" ) end end end end end end addEventHandler("onClientRender",getRootElement(),imagedraw) function AbsoluteToRelativ( X, Y ) local rX, rY = guiGetScreenSize() local x = X/rX local y = Y/rY return x, y end Except that I think that your script is correct. 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