-.Paradox.- Posted June 27, 2013 Share Posted June 27, 2013 Hello, i have a name tag script but i want to add some thing to it i maked 3 logo's, here's the lua : srfont = dxCreateFont("DFHEIMDU_id.ttf",16) 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 = 50 --Distance to start fading out local NAMETAG_DISTANCE = 100 --Distance until we're gone local NAMETAG_ALPHA = 255 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 1 local NAMETAG_WIDTH = 50 local NAMETAG_HEIGHT = 5 local NAMETAG_TEXTSIZE = 0.3 local NAMETAG_OUTLINE_THICKNESS = 1.2 -- 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} } setPedTargetingMarkerEnabled ( false ) function nametag.create ( player ) nametags[player] = true end function nametag.destroy ( player ) nametags[player] = nil end addEventHandler ( "onClientPreRender", g_Root, function() if getElementData(getLocalPlayer(), "state.hud") == "disabled" then return end -- 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 nametag.create ( 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 not isLineOfSightClear(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 ) if not sx or not sy 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 playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x","") local r,g,b = getPlayerNametagColor(player) local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 local w = dxGetTextWidth(playerName, textscale * NAMETAG_TEXTSIZE, srfont) / 2 dxDrawText ( playerName, sx, sy - offset, sx, sy - offset, tocolor(0,0,0,255), textscale*NAMETAG_TEXTSIZE, srfont, "center", "bottom", false, false, false, true, true ) dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, srfont, "center", "bottom", false, false, false, true, true ) local drawX = sx - NAMETAG_WIDTH*scale/2 drawY = sy + offset local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale local imageSize = dxGetFontHeight ( textscale*NAMETAG_TEXTSIZE, srfont ) local imageWidth = dxGetTextWidth ( playerName, textscale*NAMETAG_TEXTSIZE, srfont )/2 if getElementData(player, "reputation.class") and fileExists ( ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) then dxDrawImage ( sx - imageWidth - imageSize - 1*scale, sy - imageSize, imageSize, imageSize, ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) end dxDrawRectangle ( drawX, drawY, width, height, tocolor(0,0,0,50) ) --Next the inner background 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) if health > 1.0 then health = 1.0 end dxDrawRectangle ( drawX + outlineThickness, drawY + outlineThickness, width - outlineThickness*2, height - outlineThickness*2, tocolor(0,0,0,50) ) --Finally, the actual health dxDrawRectangle ( drawX + outlineThickness, drawY + outlineThickness, health*(width - outlineThickness*2), height - outlineThickness*2, tocolor(255,0,0,150) ) end break end end end ) ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', g_Root, function() for i,player in ipairs(getElementsByType"player") do if player ~= g_Me then nametag.create ( player ) end end end ) addEventHandler ( "onClientPlayerJoin", g_Root, function() if source == g_Me then return end setPlayerNametagShowing ( source, false ) nametag.create ( source ) end ) addEventHandler ( "onClientPlayerQuit", g_Root, function() nametag.destroy ( 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 function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) ax = ax + w color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) end last = e+1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) end end here's the part that i added but not working local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale local imageSize = dxGetFontHeight ( textscale*NAMETAG_TEXTSIZE, srfont ) local imageWidth = dxGetTextWidth ( playerName, textscale*NAMETAG_TEXTSIZE, srfont )/2 if getElementData(player, "reputation.class") and fileExists ( ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) then dxDrawImage ( sx - imageWidth - imageSize - 1*scale, sy - imageSize, imageSize, imageSize, ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) end please help here is the logo like Example if player was in Admin acl then show this logo next to his nametag http://postimg.org/image/mlsia4nov/0d437f50/ If it was moderator then show this logo: http://postimg.org/image/5roqdsazd/698b7c5f/ if it was a normal player then show this logo : http://postimg.org/image/683p3drnn/c7512e0a/ please help here is a simple picture about the script http://postimg.org/image/k3cbjzkz1/ Thanks Link to comment
Booo Posted June 27, 2013 Share Posted June 27, 2013 No helps ? u must used loadstring Link to comment
-.Paradox.- Posted June 27, 2013 Author Share Posted June 27, 2013 i already tryed it, actually i guess it need a lua too Link to comment
Booo Posted June 27, 2013 Share Posted June 27, 2013 i already tryed it, actually i guess it need a lua too your code ? Link to comment
-.Paradox.- Posted June 27, 2013 Author Share Posted June 27, 2013 I'll ask castillo he always find errors on this things Link to comment
-.Paradox.- Posted July 4, 2013 Author Share Posted July 4, 2013 Hello, i have a name tag script but i want to add some thing to it i maked 3 logo's,here's the lua : srfont = dxCreateFont("DFHEIMDU_id.ttf",16) 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 = 50 --Distance to start fading out local NAMETAG_DISTANCE = 100 --Distance until we're gone local NAMETAG_ALPHA = 255 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 1 local NAMETAG_WIDTH = 50 local NAMETAG_HEIGHT = 5 local NAMETAG_TEXTSIZE = 0.3 local NAMETAG_OUTLINE_THICKNESS = 1.2 -- 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} } setPedTargetingMarkerEnabled ( false ) function nametag.create ( player ) nametags[player] = true end function nametag.destroy ( player ) nametags[player] = nil end addEventHandler ( "onClientPreRender", g_Root, function() if getElementData(getLocalPlayer(), "state.hud") == "disabled" then return end -- 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 nametag.create ( 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 not isLineOfSightClear(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 ) if not sx or not sy 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 playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x","") local r,g,b = getPlayerNametagColor(player) local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 local w = dxGetTextWidth(playerName, textscale * NAMETAG_TEXTSIZE, srfont) / 2 dxDrawText ( playerName, sx, sy - offset, sx, sy - offset, tocolor(0,0,0,255), textscale*NAMETAG_TEXTSIZE, srfont, "center", "bottom", false, false, false, true, true ) dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, srfont, "center", "bottom", false, false, false, true, true ) local drawX = sx - NAMETAG_WIDTH*scale/2 drawY = sy + offset local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale local imageSize = dxGetFontHeight ( textscale*NAMETAG_TEXTSIZE, srfont ) local imageWidth = dxGetTextWidth ( playerName, textscale*NAMETAG_TEXTSIZE, srfont )/2 if getElementData(player, "reputation.class") and fileExists ( ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) then dxDrawImage ( sx - imageWidth - imageSize - 1*scale, sy - imageSize, imageSize, imageSize, ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) end dxDrawRectangle ( drawX, drawY, width, height, tocolor(0,0,0,50) ) --Next the inner background 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) if health > 1.0 then health = 1.0 end dxDrawRectangle ( drawX + outlineThickness, drawY + outlineThickness, width - outlineThickness*2, height - outlineThickness*2, tocolor(0,0,0,50) ) --Finally, the actual health dxDrawRectangle ( drawX + outlineThickness, drawY + outlineThickness, health*(width - outlineThickness*2), height - outlineThickness*2, tocolor(255,0,0,150) ) end break end end end ) ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', g_Root, function() for i,player in ipairs(getElementsByType"player") do if player ~= g_Me then nametag.create ( player ) end end end ) addEventHandler ( "onClientPlayerJoin", g_Root, function() if source == g_Me then return end setPlayerNametagShowing ( source, false ) nametag.create ( source ) end ) addEventHandler ( "onClientPlayerQuit", g_Root, function() nametag.destroy ( 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 function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) ax = ax + w color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) end last = e+1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) end end here's the part that i added but not working local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale local imageSize = dxGetFontHeight ( textscale*NAMETAG_TEXTSIZE, srfont ) local imageWidth = dxGetTextWidth ( playerName, textscale*NAMETAG_TEXTSIZE, srfont )/2 if getElementData(player, "reputation.class") and fileExists ( ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) then dxDrawImage ( sx - imageWidth - imageSize - 1*scale, sy - imageSize, imageSize, imageSize, ":reputation/class/classicon_"..getElementData(player, "reputation.class")..".png" ) end please help here is the logo like Example if player was in Admin acl then show this logo next to his nametag http://postimg.org/image/mlsia4nov/0d437f50/ If it was moderator then show this logo: http://postimg.org/image/5roqdsazd/698b7c5f/ if it was a normal player then show this logo : http://postimg.org/image/683p3drnn/c7512e0a/ please help here is a simple picture about the script http://postimg.org/image/k3cbjzkz1/ Thanks Link to comment
ixjf Posted July 4, 2013 Share Posted July 4, 2013 No helps ? u must used loadstring Makes no sense. Link to comment
iMr.3a[Z]eF Posted July 28, 2013 Share Posted July 28, 2013 No errors in debugscript? Link to comment
-.Paradox.- Posted July 28, 2013 Author Share Posted July 28, 2013 I didn't made yet i was thinking about using local acc = getPlayerAccount( player ) if acc and not isGuestAccount( acc ) then if isObjectInACLGroup ( "user.".. getAccountName( acc ), aclGetGroup ( "Admin" ) ) then and dxDrawImage But i dont know what event i must add. Link to comment
iMr.3a[Z]eF Posted July 28, 2013 Share Posted July 28, 2013 For dx use onClientRender Link to comment
-.Paradox.- Posted July 28, 2013 Author Share Posted July 28, 2013 Ok, what about using attachobject Link to comment
Castillo Posted July 28, 2013 Share Posted July 28, 2013 Do this: When the player logins, check his/her ACL group, then set the element data, then on the client side you can use that element data to see if the player is an admin/moderator/etc. Link to comment
-.Paradox.- Posted July 28, 2013 Author Share Posted July 28, 2013 Ok, and can you help me with a code or some functions i could use for. Link to comment
Castillo Posted July 28, 2013 Share Posted July 28, 2013 Functions/events: Functions: getAccountName isObjectInACLGroup setElementData getElementData Events: onPlayerLogin onPlayerLogout Link to comment
-.Paradox.- Posted July 28, 2013 Author Share Posted July 28, 2013 Why cant use dxDraw image? Link to comment
Castillo Posted July 28, 2013 Share Posted July 28, 2013 You need to use dxDrawImage as well. Link to comment
-.Paradox.- Posted August 5, 2013 Author Share Posted August 5, 2013 I tryed to make it but i guess there is something missing, here is the code addEventHandler("onPlayerLogin", root, function ( thePlayer ) local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then setElementData(source, "Classicon", tostring(":experience\Class\Classicon_admin.png" )) end if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Moderator" ) ) then setElementData(source, "Classicon", tostring(":experience\Class\Classicon_mod.png" )) end if isGuestAccount ( account ) then setElementData(source, "Classicon",":experience\Class\Classicon_player.png") end end Link to comment
DNL291 Posted August 5, 2013 Share Posted August 5, 2013 thePlayer at line 3 will return the player's previous account. Use source instead. Link to comment
-.Paradox.- Posted August 5, 2013 Author Share Posted August 5, 2013 Like that? addEventHandler("onPlayerLogin", root, function ( thePlayer ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then setElementData(source, "Classicon", tostring(":experience\class\classicon_admin.png" )) end if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Moderator" ) ) then setElementData(source, "Classicon", tostring(":experience\class\classicon_mod.png" )) end if isGuestAccount ( account ) then setElementData(source, "Classicon",":experience\class\classicon_player.png") end end And thank you Link to comment
-.Paradox.- Posted August 5, 2013 Author Share Posted August 5, 2013 Not working please help Link to comment
golanu21 Posted August 5, 2013 Share Posted August 5, 2013 You need to use dxDrawImage as well. Soldsnake14 say you to use dxDrawImage... dxDrawImage -- for it , you need triggerClientEvent onClientRender 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