BriGhtx3 Posted April 9, 2012 Share Posted April 9, 2012 Hey, I still have the same problem as before. I want three "nametags" for one player. The first should contain the name. The second should contain a simple text. And the third an image. I use the standard race nametag resource. I think the problem is the offset. If someone created something like this before, could he just post a snippet how he created it? Or at least explain how I can adjust the offset (they should be underneath each others and not overlap). Thanks Link to comment
unknooooown Posted April 9, 2012 Share Posted April 9, 2012 Hey,I still have the same problem as before. I want three "nametags" for one player. The first should contain the name. The second should contain a simple text. And the third an image. I use the standard race nametag resource. I think the problem is the offset. If someone created something like this before, could he just post a snippet how he created it? Or at least explain how I can adjust the offset (they should be underneath each others and not overlap). Thanks Post a screen and your code. Then we can probably help you. Link to comment
BriGhtx3 Posted April 9, 2012 Author Share Posted April 9, 2012 g_Root = getRootElement() g_ResRoot = getResourceRootElement(getThisResource()) g_Players = getElementsByType('player') g_Me = getLocalPlayer() nametag = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = false local NAMETAG_SCALE = 0.3 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 25 --Distance to start fading out local NAMETAG_DISTANCE = 25 --Distance until we're gone local NAMETAG_ALPHA = 120 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2 local NAMETAG_WIDTH = 50 local NAMETAG_HEIGHT = 5 local NAMETAG_TEXTSIZE = 0.9 local NAMETAG_OUTLINE_THICKNESS = 1.3 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY -- Ensure the name tag doesn't get too big local maxScaleCurve = { {0, 0}, {3, 3}, {13, 5} } -- Ensure the text doesn't get too small/unreadable local textScaleCurve = { {0, 0.8}, {0.8, 1.2}, {99, 99} } -- Make the text a bit brighter and fade more gradually local textAlphaCurve = { {0, 0}, {25, 100}, {120, 190}, {255, 190} } function nametagcreate ( player ) nametags[player] = true end function nametagdestroy ( player ) nametags[player] = nil end addEventHandler ( "onClientRender", g_Root, function() -- Hideous quick fix -- for i,player in ipairs(g_Players) do if isElement(player) then if player ~= g_Me then setPlayerNametagShowing ( player, false ) if not nametags[player] then nametagcreate ( player ) end end end end if bHideNametags then return end local x,y,z = getCameraMatrix() for player in pairs(nametags) do while true do if not isElement(player) then break end if getElementDimension(player) ~= getElementDimension(g_Me) then break end local px,py,pz = getElementPosition ( player ) if processLineOfSight(x, y, z, px, py, pz, true, false, false, true, false, true) then break end local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) if pdistance <= NAMETAG_DISTANCE then --Get screenposition local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ POSI OF STATUS ---------------------------------------------- --------------------------------------------------------------------------------------------------------------------- local sxStat,syStat = getScreenFromWorldPosition ( px, py, pz+0.85, 0.06 ) if not sx or not sy then break end if not sxStat or not syStat then break end --Calculate our components local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) scale = math.evalCurve(maxScaleCurve,scale) local textscale = math.evalCurve(textScaleCurve,scale) local textalpha = math.evalCurve(textAlphaCurve,alpha) local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) --Draw our text local health local p local r,g health = getElementHealth ( player ) health = math.max(health, 0)/100 p = -510*(health^2) r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ STATUS ------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- dxDrawText ( "DER STATUS", sxStat, syStat - offset, sxStat, syStat - offset, tocolor(10,10,10,255), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) if health <= 0 then --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ IMAGE -------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- dxDrawImage ( sx - offset, sy - offset, 20, 20, 'images/tt.png' ) dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(0,0,0,textalpha), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) else dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,0,textalpha), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) end end break end end end ) ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', g_ResRoot, function() for i,player in ipairs(getElementsByType("player")) do if player ~= g_Me then nametagcreate ( player ) end end end ) addEventHandler ( "onClientPlayerJoin", g_Root, function() if source == g_Me then return end setPlayerNametagShowing ( source, false ) nametagcreate ( source ) end ) addEventHandler ( "onClientPlayerQuit", g_Root, function() nametagdestroy ( source ) end ) -- Math functions function math.lerp(from,to,alpha) return from + (to-from) * alpha end -- curve is { {x1, y1}, {x2, y2}, {x3, y3} ... } function math.evalCurve( curve, input ) -- First value if input[1][1] then return curve[1][2] end -- Interp value for idx=2,#curve do if input[idx][1] then local x1 = curve[idx-1][1] local y1 = curve[idx-1][2] local x2 = curve[idx][1] local y2 = curve[idx][2] -- Find pos between input points local alpha = (input - x1)/(x2 - x1); -- Map to output points return math.lerp(y1,y2,alpha) end end -- Last value return curve[#curve][2] end The name-position is right. The text "Der Status"-position is wrong because it overlaps. And I didn't create the image, because at first I wanted to create the right text above. But when the player dies, an image appears which position is partly wrong. Link to comment
BriGhtx3 Posted April 10, 2012 Author Share Posted April 10, 2012 Would be nice if somebody could help me Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 Would be nice if somebody could help me Sorry, I still don't know what you want here... Plus, I'm going to have to go on my computer to edit this code... Link to comment
BriGhtx3 Posted April 10, 2012 Author Share Posted April 10, 2012 Ok, let me explain better ;D I have a player. Over his name should be three things like this: And in my code, this three things overlap. But they should be underneath each others. Thanks Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 try this: g_Players = getElementsByType('player') nametag = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = false local NAMETAG_SCALE = 0.3 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 25 --Distance to start fading out local NAMETAG_DISTANCE = 25 --Distance until we're gone local NAMETAG_ALPHA = 120 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2 local NAMETAG_WIDTH = 50 local NAMETAG_HEIGHT = 5 local NAMETAG_TEXTSIZE = 0.9 local NAMETAG_OUTLINE_THICKNESS = 1.3 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY -- Ensure the name tag doesn't get too big local maxScaleCurve = { {0, 0}, {3, 3}, {13, 5} } -- Ensure the text doesn't get too small/unreadable local textScaleCurve = { {0, 0.8}, {0.8, 1.2}, {99, 99} } -- Make the text a bit brighter and fade more gradually local textAlphaCurve = { {0, 0}, {25, 100}, {120, 190}, {255, 190} } function nametagcreate ( player ) nametags[player] = true end function nametagdestroy ( player ) nametags[player] = nil end addEventHandler ( "onClientRender", root, function() -- Hideous quick fix -- for i,player in ipairs(g_Players) do if isElement(player) then if player ~= localPlayer then setPlayerNametagShowing ( player, false ) if not nametags[player] then nametagcreate ( player ) end end end end if bHideNametags then return end local x,y,z = getCameraMatrix() for player in pairs(nametags) do while true do if not isElement(player) then break end if getElementDimension(player) ~= getElementDimension(localPlayer) then break end local px,py,pz = getElementPosition ( player ) if processLineOfSight(x, y, z, px, py, pz, true, false, false, true, false, true) then break end local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) if pdistance <= NAMETAG_DISTANCE then --Get screenposition local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ POSI OF STATUS ---------------------------------------------- --------------------------------------------------------------------------------------------------------------------- local sxStat,syStat = getScreenFromWorldPosition ( px, py, pz+0.85, 0.06 ) if not sx or not sy then break end if not sxStat or not syStat then break end --Calculate our components local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) scale = math.evalCurve(maxScaleCurve,scale) local textscale = math.evalCurve(textScaleCurve,scale) local textalpha = math.evalCurve(textAlphaCurve,alpha) local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) --Draw our text local health local p local r,g health = getElementHealth ( player ) health = math.max(health, 0)/100 p = -510*(health^2) r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ STATUS ------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- dxDrawText ( "DER STATUS", sxStat, syStat - offset, sxStat, syStat - offset, tocolor(10,10,10,255), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) if health <= 0 then --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ IMAGE -------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- dxDrawImage ( sx - offset, sy - offset, 20, 20, 'images/tt.png' ) dxDrawText ( getPlayerName(player), sx, sy - offset+3, sx, sy - offset+3, tocolor(0,0,0,textalpha), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) else dxDrawText ( getPlayerName(player), sx, sy - offset+3, sx, sy - offset+3, tocolor(r,g,0,textalpha), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) end end break end end end ) ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', resourceRoot, function() for i,player in ipairs(g_Players) do if player ~= localPlayer then nametagcreate ( player ) end end end ) addEventHandler ( "onClientPlayerJoin", root, function() if source == localPlayer then return end setPlayerNametagShowing ( source, false ) nametagcreate ( source ) end ) addEventHandler ( "onClientPlayerQuit", root, function() nametagdestroy ( source ) end ) -- Math functions function math.lerp(from,to,alpha) return from + (to-from) * alpha end -- curve is { {x1, y1}, {x2, y2}, {x3, y3} ... } function math.evalCurve( curve, input ) -- First value if input[1][1] then return curve[1][2] end -- Interp value for idx=2,#curve do if input[idx][1] then local x1 = curve[idx-1][1] local y1 = curve[idx-1][2] local x2 = curve[idx][1] local y2 = curve[idx][2] -- Find pos between input points local alpha = (input - x1)/(x2 - x1); -- Map to output points return math.lerp(y1,y2,alpha) end end -- Last value return curve[#curve][2] end Link to comment
BriGhtx3 Posted April 10, 2012 Author Share Posted April 10, 2012 They still overlap: Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 Can I test this script on my server please? I'm not going to steal it, trust me Link to comment
BriGhtx3 Posted April 10, 2012 Author Share Posted April 10, 2012 Which script do you mean? oO If you mean this nametag script, of course^^ It is the race nametag-resource which I modified^^ Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 oh, i can't see it on my self Can I go on your server to see? Link to comment
BriGhtx3 Posted April 10, 2012 Author Share Posted April 10, 2012 I script on a local server If you tell me how to put it online (because of the ports etc.) you can see it. Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 nah, you could tell me your ip and port then I'll go on it BTW, Pm me it so no one else comes Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 this is the last script I have: g_Players = getElementsByType('player') nametag = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = false local NAMETAG_SCALE = 0.3 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 25 --Distance to start fading out local NAMETAG_DISTANCE = 25 --Distance until we're gone local NAMETAG_ALPHA = 120 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2 local NAMETAG_WIDTH = 50 local NAMETAG_HEIGHT = 5 local NAMETAG_TEXTSIZE = 0.9 local NAMETAG_OUTLINE_THICKNESS = 1.3 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY -- Ensure the name tag doesn't get too big local maxScaleCurve = { {0, 0}, {3, 3}, {13, 5} } -- Ensure the text doesn't get too small/unreadable local textScaleCurve = { {0, 0.8}, {0.8, 1.2}, {99, 99} } -- Make the text a bit brighter and fade more gradually local textAlphaCurve = { {0, 0}, {25, 100}, {120, 190}, {255, 190} } function nametagcreate ( player ) nametags[player] = true end function nametagdestroy ( player ) nametags[player] = nil end addEventHandler ( "onClientRender", root, function() -- Hideous quick fix -- for i,player in ipairs(g_Players) do if isElement(player) then if player ~= localPlayer then setPlayerNametagShowing ( player, false ) if not nametags[player] then nametagcreate ( player ) end end end end if bHideNametags then return end local x,y,z = getCameraMatrix() for player in pairs(nametags) do while true do if not isElement(player) then break end if getElementDimension(player) ~= getElementDimension(localPlayer) then break end local px,py,pz = getElementPosition ( player ) if processLineOfSight(x, y, z, px, py, pz, true, false, false, true, false, true) then break end local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) if pdistance <= NAMETAG_DISTANCE then --Get screenposition local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ POSI OF STATUS ---------------------------------------------- --------------------------------------------------------------------------------------------------------------------- local sxStat,syStat = getScreenFromWorldPosition ( px, py, pz+0.85, 0.06 ) if not sx or not sy then break end if not sxStat or not syStat then break end --Calculate our components local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) scale = math.evalCurve(maxScaleCurve,scale) local textscale = math.evalCurve(textScaleCurve,scale) local textalpha = math.evalCurve(textAlphaCurve,alpha) local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) --Draw our text local health local p local r,g health = getElementHealth ( player ) health = math.max(health, 0)/100 p = -510*(health^2) r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ STATUS ------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- dxDrawText ( "DER STATUS", sxStat, syStat - offset, sxStat, syStat - offset, tocolor(10,10,10,255), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) if health <= 0 then --------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ IMAGE -------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- dxDrawImage ( sx - offset, sy - offset, 20, 20, 'images/tt.png' ) dxDrawText ( getPlayerName(player), sx, sy - offset+3, sx, sy - offset+3, tocolor(0,0,0,textalpha), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) else dxDrawText ( getPlayerName(player), sx, sy - offset+3, sx, sy - offset+3, tocolor(r,g,0,textalpha), (textscale*NAMETAG_TEXTSIZE)-0.3, "default", "center", "bottom", false, false, false ) end end break end end end ) ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', resourceRoot, function() for i,player in ipairs(g_Players) do if player ~= localPlayer then nametagcreate ( player ) end end end ) addEventHandler ( "onClientPlayerJoin", root, function() if source == localPlayer then return end setPlayerNametagShowing ( source, false ) nametagcreate ( source ) end ) addEventHandler ( "onClientPlayerQuit", root, function() nametagdestroy ( source ) end ) -- Math functions function math.lerp(from,to,alpha) return from + (to-from) * alpha end -- curve is { {x1, y1}, {x2, y2}, {x3, y3} ... } function math.evalCurve( curve, input ) -- First value if input[1][1] then return curve[1][2] end -- Interp value for idx=2,#curve do if input[idx][1] then local x1 = curve[idx-1][1] local y1 = curve[idx-1][2] local x2 = curve[idx][1] local y2 = curve[idx][2] -- Find pos between input points local alpha = (input - x1)/(x2 - x1); -- Map to output points return math.lerp(y1,y2,alpha) end end -- Last value return curve[#curve][2] end Link to comment
drk Posted April 10, 2012 Share Posted April 10, 2012 nah, you could tell me your ip and port then I'll go on itBTW, Pm me it so no one else comes As I understood, he don't have the ports open. You can't enter the server. Link to comment
BriGhtx3 Posted April 10, 2012 Author Share Posted April 10, 2012 It still overlaps. But thank you for your help 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