Turbesz Posted June 6, 2021 Posted June 6, 2021 I want to put a picture before players name in their nametag, and with a longer name fits well, but no with a sorter... What is the problem? Code: local width, height = (dxGetTextWidth(getPlayerName(v),1,settings.font,true)+270)*scale, 2*scale a picture of the problem: What if the only way not to feel bad, is to stop feeling, anything at all, forever? - Hannah Baker I cost a girl her life because I was afraid to love her... - Clay Jensen ~ 13 Reasons Why
Moderators IIYAMA Posted June 6, 2021 Moderators Posted June 6, 2021 8 hours ago, Turbesz said: What is the problem? What about dxGetTextWidth(getPlayerName(v), 1,settings.font,true) + 270 * scale -- or if the font is scaled: dxGetTextWidth(getPlayerName(v), scale,settings.font,true) + 270 * scale for the width. 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Turbesz Posted June 6, 2021 Author Posted June 6, 2021 45 minutes ago, IIYAMA said: What about dxGetTextWidth(getPlayerName(v), 1,settings.font,true) + 270 * scale -- or if the font is scaled: dxGetTextWidth(getPlayerName(v), scale,settings.font,true) + 270 * scale for the width. thank youuu so much 1 What if the only way not to feel bad, is to stop feeling, anything at all, forever? - Hannah Baker I cost a girl her life because I was afraid to love her... - Clay Jensen ~ 13 Reasons Why
Turbesz Posted June 6, 2021 Author Posted June 6, 2021 1 hour ago, IIYAMA said: What about dxGetTextWidth(getPlayerName(v), 1,settings.font,true) + 270 * scale -- or if the font is scaled: dxGetTextWidth(getPlayerName(v), scale,settings.font,true) + 270 * scale for the width. umm, another little problem. if i want to put another image after the player's name, again the same problem just in the other direction. with this code: local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) - 350 * scale, 2*scale What if the only way not to feel bad, is to stop feeling, anything at all, forever? - Hannah Baker I cost a girl her life because I was afraid to love her... - Clay Jensen ~ 13 Reasons Why
Moderators IIYAMA Posted June 6, 2021 Moderators Posted June 6, 2021 24 minutes ago, Turbesz said: umm, another little problem. if i want to put another image after the player's name, again the same problem just in the other direction. with this code: Normally you would calculate the position like this: -- The width local textWidth = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) local offset = scale * 50 -- Offset from the text -- Note: The text is centered!!! local positionX -- Before positionX = positionX - (textWidth / 2 + offset) -- After positionX = positionX + (textWidth / 2 + offset) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Turbesz Posted June 6, 2021 Author Posted June 6, 2021 19 minutes ago, IIYAMA said: Normally you would calculate the position like this: -- The width local textWidth = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) local offset = scale * 50 -- Offset from the text -- Note: The text is centered!!! local positionX -- Before positionX = positionX - (textWidth / 2 + offset) -- After positionX = positionX + (textWidth / 2 + offset) then if I understand correctly i have to change 'sx' to 'positionX' in my code? local scale = interpolateBetween(0.7, 0, 0, 0, 0, 0, progress, "OutQuad") local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) - 350 * scale, 2*scale local sx, sy = sx-width/2, sy-height dxDrawImage(sx, sy, 40, 40, "files/typing.png",0,0,0,tocolor(255,181,64,255)) What if the only way not to feel bad, is to stop feeling, anything at all, forever? - Hannah Baker I cost a girl her life because I was afraid to love her... - Clay Jensen ~ 13 Reasons Why
Moderators IIYAMA Posted June 6, 2021 Moderators Posted June 6, 2021 1 hour ago, Turbesz said: local scale = interpolateBetween(0.7, 0, 0, 0, 0, 0, progress, "OutQuad") local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) - 350 * scale, 2*scale local sx, sy = sx-width/2, sy-height dxDrawImage(sx, sy, 40, 40, "files/typing.png",0,0,0,tocolor(255,181,64,255)) An example: local scale = interpolateBetween(0.7, 0, 0, 0, 0, 0, progress, "OutQuad") local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true), 2*scale local imageSize = 40 * scale local offset = 40 * scale local sx, sy = sx - (width / 2 + imageSize + offset), sy-height dxDrawImage(sx, sy, imageSize, imageSize, "files/typing.png",0,0,0,tocolor(255,181,64,255)) -- no imageSize since the image is drawn from left to right local sx, sy = sx + (width / 2 + offset), sy-height dxDrawImage(sx, sy, imageSize, imageSize, "files/typing.png",0,0,0,tocolor(255,181,64,255)) Anyway, I am wondering why you use the value '350'. The image was only 40 pixels and unscaled. 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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