403403-- Player objects
404404function RemoveBuildingForPlayer (model , x , y , z , radius )
405405 if model == - 1 then
406- for i = 550 ,20000 do -- Remove all world models if they sent -1
407- removeWorldModel (i ,20000 , 0 , 0 , 0 )
406+ for i = 550 ,20000 do -- Remove all world models around radius if they sent -1
407+ removeWorldModel (i , radius , x , y , z )
408408 end
409409 return true -- Don't run the rest of the code
410410 end
@@ -790,26 +790,64 @@ local textDrawColorMapping = {
790790}
791791
792792local textDrawFonts = {
793- [0 ] = { font = ' beckett' , lsizemul = 3 }, -- TextDraw letter size -> dxDrawText scale multiplier
794- [1 ] = { font = ' default-bold' , lsizemul = 3 },
795- [2 ] = { font = ' bankgothic' , lsizemul = 2 },
796- [3 ] = { font = ' default-bold' , lsizemul = 3 }
793+ [0 ] = { font = ' beckett' , lsizemul = 1.25 }, -- TextDraw letter size -> dxDrawText scale multiplier
794+ [1 ] = { font = ' default-bold' , lsizemul = 1.25 },
795+ [2 ] = { font = ' bankgothic' , lsizemul = 1.5 },
796+ [3 ] = { font = ' default-bold' , lsizemul = 1.25 }
797797}
798798
799+ function visibleTextDrawsExist ()
800+ for name ,amx in pairs (g_AMXs ) do
801+ if table .find (amx .textdraws , ' visible' , true ) then
802+ return true
803+ end
804+ end
805+ return false
806+ end
807+
808+ function showTextDraw (textdraw )
809+ if not visibleTextDrawsExist () then
810+ addEventHandler (' onClientRender' , root , renderTextDraws )
811+ end
812+ textdraw .visible = true
813+ end
814+
815+ function hideTextDraw (textdraw )
816+ textdraw .visible = false
817+ if not visibleTextDrawsExist () then
818+ removeEventHandler (' onClientRender' , root , renderTextDraws )
819+ end
820+ end
821+
822+ function hudGetVerticalScale ()
823+ return 0.002232143
824+ end
825+
826+ function hudGetHorizontalScale ()
827+ return 0.0015625
828+ end
829+
799830function initTextDraw (textdraw )
800831 local amx = textdraw .amx
801832 textdraw .id = textdraw .id or (# amx .textdraws + 1 )
802833 amx .textdraws [textdraw .id ] = textdraw
803834
804- local lineHeight = 60 * (textdraw .lsize or 0.5 )
835+ local scale = (textdraw .lwidth or 0.5 )
836+ local tWidth , tHeight = dxGetTextSize (textdraw .text , scale )
837+ local lineHeight = (tHeight or 0.25 ) / 2 -- space between lines (vertical) also used to calculate size of the box if any
838+ local lineWidth = (textdraw .lwidth or 0.25 ) -- space between words (horizontal)
805839
840+ -- Set the height based on the text size
841+ textdraw .theight = tHeight
842+ textdraw .twidth = tWidth
843+
806844 local text = textdraw .text :gsub (' ~k~~(.-)~' , getSAMPBoundKey )
807845 local lines = {}
808846 local pos , stop , c
809847 stop = 0
810848 while true do
811849 pos , stop , c = text :find (' ~(%a)~' , stop + 1 )
812- if c == ' n' then
850+ if c == ' n' then -- If we found a new line
813851 lines [# lines + 1 ] = text :sub (1 , pos - 1 )
814852 text = text :sub (stop + 1 )
815853 stop = 0
@@ -825,12 +863,12 @@ function initTextDraw(textdraw)
825863 textdraw .parts = {}
826864 textdraw .width = 0
827865 local font = textDrawFonts [textdraw .font and textdraw .font >= 0 and textdraw .font <= # textDrawFonts and textdraw .font or 0 ]
828- local scale = (textdraw .lsize or 0.5 ) * font .lsizemul
829866 font = font .font
830867
831- local curX
832- local curY = textdraw .y or screenHeight / 2 - # lines * lineHeight / 2
868+ local TDXPos = textdraw . x or 640 - # lines * lineWidth
869+ local TDYPos = textdraw .y or 448 - # lines * lineHeight
833870
871+ -- Process the lines we previously found
834872 for i ,line in ipairs (lines ) do
835873 local colorpos = 1
836874 local color
@@ -871,13 +909,14 @@ function initTextDraw(textdraw)
871909 textdraw .width = math.max (textdraw .width , textWidth )
872910 if textdraw .align == 1 then
873911 -- left
874- curX = textdraw .x
912+ TDXPos = textdraw .x
875913 elseif textdraw .align == 2 or not textdraw .align then
876914 -- center
877- curX = screenWidth / 2 - textWidth / 2
915+ -- outputConsole(string.format("Got centered text %d %d %s", TDXPos, TDYPos, textdraw.text))
916+ TDXPos = 640 / 2 - textWidth / 2
878917 elseif textdraw .align == 3 then
879918 -- right
880- curX = textdraw .x - textWidth
919+ TDXPos = textdraw .x - textWidth
881920 end
882921
883922 color = textdraw .color or tocolor (255 , 255 , 255 )
@@ -890,65 +929,61 @@ function initTextDraw(textdraw)
890929 colorpos = colorpos + 7
891930 end
892931 nextcolorpos = line :find (' #%x%x%x%x%x%x' , colorpos ) or line :len () + 1
893- local part = { text = line :sub (colorpos , nextcolorpos - 1 ), x = curX , y = curY , color = color }
932+ local part = { text = line :sub (colorpos , nextcolorpos - 1 ), x = TDXPos , y = TDYPos , color = color }
894933 table.insert (textdraw .parts , part )
895- curX = curX + dxGetTextWidth (part .text , scale , font )
934+ TDXPos = TDXPos + dxGetTextWidth (part .text , scale , font )
896935 colorpos = nextcolorpos
897936 end
898- curY = curY + lineHeight
899- end
900- textdraw .absheight = lineHeight *# lines
901- end
902-
903- function visibleTextDrawsExist ()
904- for name ,amx in pairs (g_AMXs ) do
905- if table .find (amx .textdraws , ' visible' , true ) then
906- return true
907- end
908- end
909- return false
910- end
911-
912- function showTextDraw (textdraw )
913- if not visibleTextDrawsExist () then
914- addEventHandler (' onClientRender' , root , renderTextDraws )
915- end
916- textdraw .visible = true
917- end
918-
919- function hideTextDraw (textdraw )
920- textdraw .visible = false
921- if not visibleTextDrawsExist () then
922- removeEventHandler (' onClientRender' , root , renderTextDraws )
937+ TDYPos = TDYPos + lineHeight
923938 end
939+ textdraw .absheight = tHeight *# lines
924940end
925941
926942function renderTextDraws ()
927943 for name ,amx in pairs (g_AMXs ) do
928944 for id ,textdraw in pairs (amx .textdraws ) do
929- if textdraw .visible and textdraw .parts and not (textdraw .text :match (' ^%s*$' ) and not textdraw .usebox ) then
945+ if textdraw .visible and textdraw .parts and not (textdraw .text :match (' ^%s*$' )) then -- and not textdraw.usebox) then
930946 local font = textDrawFonts [textdraw .font and textdraw .font >= 0 and textdraw .font <= # textDrawFonts and textdraw .font or 0 ]
931- local scale = (textdraw .lsize or 0.5 ) * font .lsizemul
947+ if textdraw .upscalex == nil then
948+ textdraw .upscalex = 1.0
949+ end
950+ if textdraw .upscaley == nil then
951+ textdraw .upscaley = 1.0
952+ end
953+
954+ local letterHeight = (textdraw .lheight * textdraw .upscaley or 0.25 )
955+ local letterWidth = (textdraw .lwidth * textdraw .upscalex or 0.5 )
956+
957+ local vertHudScale = hudGetVerticalScale ()
958+ local horHudScale = hudGetHorizontalScale ()
959+
960+ local scaley = SCREEN_SCALE_Y (screenHeight * vertHudScale * letterHeight * 0.175 ) -- This should replicate what the game does
961+ local scalex = SCREEN_SCALE_X (screenWidth * horHudScale * letterWidth * 0.35 )
962+
963+ local sourceY = screenHeight - ((DEFAULT_SCREEN_HEIGHT - textdraw .y ) * (screenHeight * vertHudScale ))
964+ local sourceX = screenWidth - ((DEFAULT_SCREEN_WIDTH - textdraw .x ) * (screenWidth * horHudScale ))
965+
932966 font = font .font
967+ -- Process box alignments
933968 if textdraw .usebox then
934969 local boxcolor = textdraw .boxcolor or tocolor (0 , 0 , 0 , 120 * (textdraw .alpha or 1 ))
935970 local x , y , w , h
936- if textdraw .align == 1 then
971+ if textdraw .align == 1 then -- left
937972 x = textdraw .x
938973 if textdraw .boxsize then
939- w = textdraw .boxsize [1 ] - x
974+ w = textdraw .boxsize [1 ]-- - x
940975 else
941976 w = textdraw .width
942977 end
943- elseif textdraw .align == 2 then
978+ elseif textdraw .align == 2 then -- centered
944979 if textdraw .boxsize then
945- x = screenWidth / 2 - textdraw .boxsize [1 ]/ 2
980+ x = textdraw .boxsize [1 ]/ 2
946981 w = textdraw .boxsize [1 ]
947982 else
948983 x = textdraw .x
949984 w = textdraw .width
950985 end
951- elseif textdraw .align == 3 then
986+ elseif textdraw .align == 3 then -- right
952987 if textdraw .boxsize then
953988 w = textdraw .x - textdraw .boxsize [1 ]
954989 else
@@ -957,21 +992,33 @@ function renderTextDraws()
957992 x = textdraw .x - w
958993 end
959994 y = textdraw .y
995+
996+ -- Calculates box height
960997 if textdraw .boxsize and textdraw .text :match (' ^%s*$' ) then
961998 h = textdraw .boxsize [2 ]
962999 else
9631000 h = textdraw .absheight
9641001 end
965- dxDrawRectangle (x - 3 , y - 3 , w + 6 , h + 6 , boxcolor )
1002+
1003+ dxDrawRectangle (sourceX , sourceY , w * getAspectRatio (), h * getAspectRatio (), boxcolor )
1004+ -- outputConsole(string.format("Drawing textdraw box: sourceX: %f, sourceY: %f", sourceX, sourceY))
9661005 end
1006+
9671007 for i ,part in pairs (textdraw .parts ) do
968- if textdraw .shade and textdraw .shade > 0 then
969- dxDrawText (part .text , part .x + 5 , part .y + 5 , part .x + 5 , part .y + 5 , tocolor (0 , 0 , 0 , 100 * (textdraw .alpha or 1 )), scale , font )
1008+
1009+ sourceY = screenHeight - ((DEFAULT_SCREEN_HEIGHT - part .y ) * (screenHeight * vertHudScale ))
1010+ sourceX = screenWidth - ((DEFAULT_SCREEN_WIDTH - part .x ) * (screenWidth * horHudScale ))
1011+
1012+ -- outputConsole(string.format("text: %s partx: %f, party: %f sourceX: %f, sourceY: %f", part.text, part.x, part.y, sourceX, sourceY))
1013+
1014+ if textdraw .shade and textdraw .shade > 0 then -- Draw the shadow
1015+ dxDrawText (part .text , sourceX + 5 , sourceY + 5 , sourceX + 5 , sourceY + 5 , tocolor (0 , 0 , 0 , 100 * (textdraw .alpha or 1 )), scalex , scaley , font )
9701016 end
1017+ -- Draw the actual text
9711018 drawBorderText (
972- part .text , part . x , part . y ,
1019+ part .text , sourceX , sourceY ,
9731020 textdraw .alpha and setcoloralpha (part .color , math.floor (textdraw .alpha * 255 )) or part .color ,
974- scale , font , math.ceil (( textdraw .outlinesize or ( font == ' bankgothic ' and 2 or 1 )) * scale ) ,
1021+ scalex , scaley , font , textdraw .outlinesize ,
9751022 textdraw .outlinecolor
9761023 )
9771024 end
@@ -996,12 +1043,29 @@ function GameTextForPlayer(amxName, text, time, style)
9961043 end
9971044 local amx = g_AMXs [amxName ]
9981045 gameText = { amx = amx , text = text , font = 2 }
999- if style == 2 then
1000- gameText .x = 0.9 * screenWidth
1001- gameText .y = 0.7 * screenHeight
1046+ if style == 1 then
1047+ gameText .x = 0.9 * 640
1048+ gameText .y = 0.8 * 448
1049+ gameText .lheight = 0.5
1050+ gameText .lwidth = 1.0
1051+ gameText .align = 3
1052+ gameText .upscaley = 3.0
1053+ gameText .upscalex = 1.0
1054+ time = 8000 -- Fades out after 8 seconds regardless of time set according to the wiki
1055+ elseif style == 2 then
1056+ gameText .x = 0.9 * 640
1057+ gameText .y = 0.7 * 448
10021058 gameText .align = 3
1003- elseif style == 6 then
1004- gameText .y = 0.2 * screenHeight
1059+ elseif style >= 3 then
1060+ -- ★
1061+ -- GTA replaces these with stars
1062+ gameText .text = string.gsub (text , " ]" , " ★" )
1063+ gameText .x = 0.5 * 640
1064+ gameText .y = 0.2 * 448
1065+ gameText .lheight = 0.5
1066+ gameText .lwidth = 1.0
1067+ gameText .align = 2
1068+ gameText .upscaley = 2.5
10051069 end
10061070 initTextDraw (gameText )
10071071 showTextDraw (gameText )
@@ -1103,8 +1167,8 @@ function TextDrawCreate(amxName, id, textdraw)
11031167 textdraw .id = id
11041168 amx .textdraws [id ] = textdraw
11051169 if textdraw .x then
1106- textdraw .x = textdraw .x * screenWidth
1107- textdraw .y = textdraw .y * screenHeight
1170+ textdraw .x = textdraw .x
1171+ textdraw .y = textdraw .y
11081172 end
11091173 for prop ,val in pairs (textdraw ) do
11101174 TextDrawPropertyChanged (amxName , id , prop , val , true )
@@ -1124,8 +1188,8 @@ function TextDrawPropertyChanged(amxName, id, prop, newval, skipInit)
11241188 local textdraw = g_AMXs [amxName ].textdraws [id ]
11251189 textdraw [prop ] = newval
11261190 if prop == ' boxsize' then
1127- textdraw .boxsize [1 ] = textdraw .boxsize [1 ]* screenWidth
1128- textdraw .boxsize [2 ] = textdraw .boxsize [2 ]* screenHeight
1191+ textdraw .boxsize [1 ] = textdraw .boxsize [1 ]
1192+ textdraw .boxsize [2 ] = textdraw .boxsize [2 ]
11291193 elseif prop :match (' color' ) then
11301194 textdraw [prop ] = tocolor (unpack (newval ))
11311195 end
0 commit comments