Use https://wiki.multitheftauto.com/wiki/DxGetTextWidth to get the text's width and draw the text half the width the text to the left of the head. Replace your dxDrawText with these 4:
local scale = 0.85+(15-dist)*0.02;
local playerName = getPlayerName( v );
local w = dxGetTextWidth( playerName, scale, "bankgothic" );
dxDrawText(playerName,x-w/2,y,x,y,tocolor(150,50,0),scale,"bankgothic")