Jump to content

Draw Static Image above each Players head


Recommended Posts

Posted

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 :wink: )

I hope anybody knows how to reaslize that! :mrgreen:

Posted

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.

Posted

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.

Posted

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.

  • Moderators
Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...