403
403
-- Player objects
404
404
function RemoveBuildingForPlayer (model , x , y , z , radius )
405
405
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 )
408
408
end
409
409
return true -- Don't run the rest of the code
410
410
end
@@ -790,26 +790,64 @@ local textDrawColorMapping = {
790
790
}
791
791
792
792
local 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 }
797
797
}
798
798
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
+
799
830
function initTextDraw (textdraw )
800
831
local amx = textdraw .amx
801
832
textdraw .id = textdraw .id or (# amx .textdraws + 1 )
802
833
amx .textdraws [textdraw .id ] = textdraw
803
834
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)
805
839
840
+ -- Set the height based on the text size
841
+ textdraw .theight = tHeight
842
+ textdraw .twidth = tWidth
843
+
806
844
local text = textdraw .text :gsub (' ~k~~(.-)~' , getSAMPBoundKey )
807
845
local lines = {}
808
846
local pos , stop , c
809
847
stop = 0
810
848
while true do
811
849
pos , stop , c = text :find (' ~(%a)~' , stop + 1 )
812
- if c == ' n' then
850
+ if c == ' n' then -- If we found a new line
813
851
lines [# lines + 1 ] = text :sub (1 , pos - 1 )
814
852
text = text :sub (stop + 1 )
815
853
stop = 0
@@ -825,12 +863,12 @@ function initTextDraw(textdraw)
825
863
textdraw .parts = {}
826
864
textdraw .width = 0
827
865
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
829
866
font = font .font
830
867
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
833
870
871
+ -- Process the lines we previously found
834
872
for i ,line in ipairs (lines ) do
835
873
local colorpos = 1
836
874
local color
@@ -871,13 +909,14 @@ function initTextDraw(textdraw)
871
909
textdraw .width = math.max (textdraw .width , textWidth )
872
910
if textdraw .align == 1 then
873
911
-- left
874
- curX = textdraw .x
912
+ TDXPos = textdraw .x
875
913
elseif textdraw .align == 2 or not textdraw .align then
876
914
-- 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
878
917
elseif textdraw .align == 3 then
879
918
-- right
880
- curX = textdraw .x - textWidth
919
+ TDXPos = textdraw .x - textWidth
881
920
end
882
921
883
922
color = textdraw .color or tocolor (255 , 255 , 255 )
@@ -890,65 +929,61 @@ function initTextDraw(textdraw)
890
929
colorpos = colorpos + 7
891
930
end
892
931
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 }
894
933
table.insert (textdraw .parts , part )
895
- curX = curX + dxGetTextWidth (part .text , scale , font )
934
+ TDXPos = TDXPos + dxGetTextWidth (part .text , scale , font )
896
935
colorpos = nextcolorpos
897
936
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
923
938
end
939
+ textdraw .absheight = tHeight *# lines
924
940
end
925
941
926
942
function renderTextDraws ()
927
943
for name ,amx in pairs (g_AMXs ) do
928
944
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
930
946
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
+
932
966
font = font .font
967
+ -- Process box alignments
933
968
if textdraw .usebox then
934
969
local boxcolor = textdraw .boxcolor or tocolor (0 , 0 , 0 , 120 * (textdraw .alpha or 1 ))
935
970
local x , y , w , h
936
- if textdraw .align == 1 then
971
+ if textdraw .align == 1 then -- left
937
972
x = textdraw .x
938
973
if textdraw .boxsize then
939
- w = textdraw .boxsize [1 ] - x
974
+ w = textdraw .boxsize [1 ]-- - x
940
975
else
941
976
w = textdraw .width
942
977
end
943
- elseif textdraw .align == 2 then
978
+ elseif textdraw .align == 2 then -- centered
944
979
if textdraw .boxsize then
945
- x = screenWidth / 2 - textdraw .boxsize [1 ]/ 2
980
+ x = textdraw .boxsize [1 ]/ 2
946
981
w = textdraw .boxsize [1 ]
947
982
else
948
983
x = textdraw .x
949
984
w = textdraw .width
950
985
end
951
- elseif textdraw .align == 3 then
986
+ elseif textdraw .align == 3 then -- right
952
987
if textdraw .boxsize then
953
988
w = textdraw .x - textdraw .boxsize [1 ]
954
989
else
@@ -957,21 +992,33 @@ function renderTextDraws()
957
992
x = textdraw .x - w
958
993
end
959
994
y = textdraw .y
995
+
996
+ -- Calculates box height
960
997
if textdraw .boxsize and textdraw .text :match (' ^%s*$' ) then
961
998
h = textdraw .boxsize [2 ]
962
999
else
963
1000
h = textdraw .absheight
964
1001
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))
966
1005
end
1006
+
967
1007
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 )
970
1016
end
1017
+ -- Draw the actual text
971
1018
drawBorderText (
972
- part .text , part . x , part . y ,
1019
+ part .text , sourceX , sourceY ,
973
1020
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 ,
975
1022
textdraw .outlinecolor
976
1023
)
977
1024
end
@@ -996,12 +1043,29 @@ function GameTextForPlayer(amxName, text, time, style)
996
1043
end
997
1044
local amx = g_AMXs [amxName ]
998
1045
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
1002
1058
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
1005
1069
end
1006
1070
initTextDraw (gameText )
1007
1071
showTextDraw (gameText )
@@ -1103,8 +1167,8 @@ function TextDrawCreate(amxName, id, textdraw)
1103
1167
textdraw .id = id
1104
1168
amx .textdraws [id ] = textdraw
1105
1169
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
1108
1172
end
1109
1173
for prop ,val in pairs (textdraw ) do
1110
1174
TextDrawPropertyChanged (amxName , id , prop , val , true )
@@ -1124,8 +1188,8 @@ function TextDrawPropertyChanged(amxName, id, prop, newval, skipInit)
1124
1188
local textdraw = g_AMXs [amxName ].textdraws [id ]
1125
1189
textdraw [prop ] = newval
1126
1190
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 ]
1129
1193
elseif prop :match (' color' ) then
1130
1194
textdraw [prop ] = tocolor (unpack (newval ))
1131
1195
end
0 commit comments