@@ -1547,54 +1547,163 @@ function TextDrawCreate(amx, x, y, text)
15471547end
15481548
15491549-- Mainly just wrappers to the other non-player functions
1550- function PlayerTextDrawDestroy (amx , playerid , textdrawID )
1551- TextDrawDestroy (amx , textdrawID )
1550+ function PlayerTextDrawDestroy (amx , player , textdrawID )
1551+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1552+ return false
1553+ end
1554+ clientCall (player , ' TextDrawDestroy' , amx .name , textdrawID )
1555+ amx .playertextdraws [player ][textdrawID ] = nil
15521556end
1553- function PlayerTextDrawShow (amx , playerid , textdrawID )
1554- TextDrawShowForPlayer (amx , playerid , textdrawID )
1557+ function PlayerTextDrawShow (amx , player , textdrawID )
1558+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1559+ return false
1560+ end
1561+ local textdraw = amx .playertextdraws [player ][textdrawID ]
1562+ local playerdata = g_Players [getElemID (player )]
1563+ playerdata .visibletextdraws = playerdata .visibletextdraws or {}
1564+ if not textdraw or playerdata .visibletextdraws [textdraw ] then
1565+ return
1566+ end
1567+ clientCall (player , ' TextDrawShowForPlayer' , amx .name , textdrawID )
1568+ playerdata .visibletextdraws [textdraw ] = true
1569+ return true
15551570end
1556- function PlayerTextDrawHide (amx , playerid , textdrawID )
1557- TextDrawHideForPlayer (amx , playerid , textdrawID )
1571+ function PlayerTextDrawHide (amx , player , textdrawID )
1572+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1573+ return false
1574+ end
1575+ local textdraw = amx .playertextdraws [player ][textdrawID ]
1576+ local playerdata = g_Players [getElemID (player )]
1577+ playerdata .visibletextdraws = playerdata .visibletextdraws or {}
1578+ if not textdraw or not playerdata .visibletextdraws [textdraw ] then
1579+ return
1580+ end
1581+ clientCall (player , ' TextDrawHideForPlayer' , amx .name , textdrawID )
1582+ playerdata .visibletextdraws [textdraw ] = nil
15581583end
1559- function PlayerTextDrawBoxColor (amx , playerid , textdrawID , r , g , b , a )
1560- TextDrawBoxColor (amx , textdrawID , r , g , b , a )
1584+ function PlayerTextDrawBoxColor (amx , player , textdrawID , r , g , b , a )
1585+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1586+ return false
1587+ end
1588+ amx .playertextdraws [player ][textdrawID ].boxcolor = { r , g , b , a }
15611589end
1562- function PlayerTextDrawUseBox (amx , playerid , textdrawID , usebox )
1563- TextDrawUseBox (amx , textdrawID , usebox )
1590+ function PlayerTextDrawUseBox (amx , player , textdrawID , usebox )
1591+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1592+ return false
1593+ end
1594+ amx .playertextdraws [player ][textdrawID ].usebox = usebox
1595+ return true
15641596end
1565- function PlayerTextDrawTextSize (amx , playerid , textdrawID , x , y )
1566- TextDrawTextSize (amx , textdrawID , x , y )
1597+ function PlayerTextDrawTextSize (amx , player , textdrawID , x , y )
1598+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1599+ return false
1600+ end
1601+ amx .playertextdraws [player ][textdrawID ].boxsize = { x , y }
1602+ return true
15671603end
1568- function PlayerTextDrawLetterSize (amx , playerid , textdrawID , x , y )
1569- TextDrawLetterSize (amx , textdrawID , width , height )
1604+ function PlayerTextDrawLetterSize (amx , player , textdrawID , x , y )
1605+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1606+ return false
1607+ end
1608+ amx .playertextdraws [player ][textdrawID ].lwidth = width
1609+ amx .playertextdraws [player ][textdrawID ].lheight = height
1610+ return true
15701611end
1571- function CreatePlayerTextDraw (amx , playerid , x , y , text )
1572- TextDrawCreate (amx , x , y , text )
1612+ function IsPlayerTextDrawValid (amx , player , textdrawID )
1613+ if not amx .playertextdraws [player ] then
1614+ return false
1615+ end
1616+ local textdraw = amx .playertextdraws [player ] and amx .playertextdraws [player ][textdrawID ]
1617+ if not textdraw then
1618+ return false
1619+ end
1620+ return true
1621+ end
1622+ function CreatePlayerTextDraw (amx , player , x , y , text )
1623+ if not amx .playertextdraws [player ] then
1624+ amx .playertextdraws [player ] = {}
1625+ end
1626+ outputDebugString (' CreatePlayerTextDraw called with args ' .. x .. ' ' .. y .. ' ' .. text )
1627+ local textdraw = { x = x , y = y , shadow = {align = 1 , text = text , font = 1 , lwidth = 0.5 , lheight = 0.5 } }
1628+ local id = # amx .textdraws + table.insert (amx .playertextdraws [player ], textdraw ) -- I want the ids to always be greater than the other textdraws so they don't collide when trying to use certain functions to hide them
1629+ setmetatable (
1630+ textdraw ,
1631+ {
1632+ __index = textdraw .shadow ,
1633+ __newindex = function (t , k , v )
1634+ local different
1635+ if not t .shadow [k ] then
1636+ different = true
1637+ else
1638+ if type (v ) == ' table' then
1639+ different = not table .cmp (v , t .shadow [k ])
1640+ else
1641+ different = v ~= t .shadow [k ]
1642+ end
1643+ end
1644+ if different then
1645+ clientCall (player , ' TextDrawPropertyChanged' , amx .name , id , k , v )
1646+ t .shadow [k ] = v
1647+ end
1648+ end
1649+ }
1650+ )
1651+ clientCall (player , ' TextDrawCreate' , amx .name , id , table .deshadowize (textdraw , true ))
1652+ return id
15731653end
15741654function PlayerTextDrawAlignment (amx , playerid , textdrawID , align )
1575- TextDrawAlignment (amx , textdrawID , align )
1655+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1656+ return false
1657+ end
1658+ amx .playertextdraws [player ][textdrawID ].align = (align == 0 and 1 or align )
1659+ return true
15761660end
1577- function PlayerTextDrawBackgroundColor (amx , playerid , textdraw , r , g , b , a )
1578- TextDrawBackgroundColor (amx , textdraw , r , g , b , a )
1661+ function PlayerTextDrawBackgroundColor (amx , playerid , textdrawID , r , g , b , a )
1662+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1663+ return false
1664+ end
1665+ amx .playertextdraws [player ][textdrawID ].outlinecolor = { r , g , b , a }
1666+ return true
15791667end
1580- function PlayerTextDrawFont (amx , playerid , textdraw , font )
1581- TextDrawFont (amx , textdraw , font )
1668+ function PlayerTextDrawFont (amx , playerid , textdrawID , font )
1669+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1670+ return false
1671+ end
1672+ amx .playertextdraws [player ][textdrawID ].font = font
1673+ return true
15821674end
1583- function PlayerTextDrawColor (amx , playerid , textdraw , r , g , b , a )
1584- TextDrawColor (amx , textdraw , r , g , b , a )
1675+ function PlayerTextDrawColor (amx , playerid , textdrawID , r , g , b , a )
1676+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1677+ return false
1678+ end
1679+ amx .playertextdraws [player ][textdrawID ].color = { r , g , b }
1680+ return true
15851681end
1586- function PlayerTextDrawSetOutline (amx , playerid , textdraw , size )
1587- TextDrawSetOutline (amx , textdraw , size )
1682+ function PlayerTextDrawSetOutline (amx , playerid , textdrawID , size )
1683+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1684+ return false
1685+ end
1686+ amx .playertextdraws [player ][textdrawID ].outlinesize = size
1687+ return true
15881688end
1589- function PlayerTextDrawSetProportional (amx , playerid , textdraw , proportional )
1590- TextDrawSetProportional (amx , textdraw , proportional )
1689+ function PlayerTextDrawSetProportional (amx , playerid , textdrawID , proportional )
1690+ -- TextDrawSetProportional(amx, textdraw, proportional)
15911691end
1592- function PlayerTextDrawSetShadow (amx , playerid , textdraw , size )
1593- TextDrawSetShadow (amx , textdraw , size )
1692+ function PlayerTextDrawSetShadow (amx , playerid , textdrawID , size )
1693+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1694+ return false
1695+ end
1696+ amx .playertextdraws [player ][textdrawID ].shade = size
1697+ return true
15941698end
1595- function PlayerTextDrawSetString (amx , playerid , textdraw , str )
1596- TextDrawSetString (amx , textdraw , str )
1699+ function PlayerTextDrawSetString (amx , playerid , textdrawID , str )
1700+ if not IsPlayerTextDrawValid (amx , player , textdrawID ) then
1701+ return false
1702+ end
1703+ amx .playertextdraws [player ][textdrawID ].text = str
1704+ return true
15971705end
1706+ -- End of player textdraws
15981707function TextDrawDestroy (amx , textdrawID )
15991708 if not amx .textdraws [textdrawID ] then
16001709 return
@@ -3045,24 +3154,24 @@ g_SAMPSyscallPrototypes = {
30453154 TextDrawUseBox = {' x' , ' b' },
30463155 -- Player textdraws
30473156 PlayerTextDrawDestroy = {' p' , ' s' },
3048- PlayerTextDrawShow = {' p' , ' x ' },
3049- PlayerTextDrawHide = {' p' , ' x ' },
3050- PlayerTextDrawBoxColor = {' p' , ' x ' , ' c' },
3051- PlayerTextDrawUseBox = {' p' , ' x ' , ' i' },
3052- PlayerTextDrawTextSize = {' p' , ' x ' , ' f' , ' f' },
3053- PlayerTextDrawLetterSize = {' p' , ' x ' , ' f' , ' f' },
3054- PlayerTextDrawAlignment = {' p' , ' x ' , ' i' },
3055- PlayerTextDrawBackgroundColor = {' p' , ' x ' , ' c' },
3056- PlayerTextDrawFont = {' p' , ' x ' , ' i' },
3057- PlayerTextDrawColor = {' p' , ' x ' , ' c' },
3058- PlayerTextDrawSetOutline = {' p' , ' x ' , ' i' },
3059- PlayerTextDrawSetProportional = {' p' , ' x ' , ' i' },
3060- PlayerTextDrawSetShadow = {' p' , ' x ' , ' i' },
3061- PlayerTextDrawSetString = {' p' , ' x ' , ' s' },
3062- PlayerTextDrawSetPreviewModel = {' p' , ' x ' , ' i' },
3063- PlayerTextDrawSetPreviewVehCol = {' p' , ' x ' , ' i' , ' i' },
3064- PlayerTextDrawSetSelectable = {' p' , ' x ' , ' i' },
3065- PlayerTextDrawSetPreviewRot = {' p' , ' x ' , ' f' , ' f' , ' f' , ' f' },
3157+ PlayerTextDrawShow = {' p' , ' i ' },
3158+ PlayerTextDrawHide = {' p' , ' i ' },
3159+ PlayerTextDrawBoxColor = {' p' , ' i ' , ' c' },
3160+ PlayerTextDrawUseBox = {' p' , ' i ' , ' i' },
3161+ PlayerTextDrawTextSize = {' p' , ' i ' , ' f' , ' f' },
3162+ PlayerTextDrawLetterSize = {' p' , ' i ' , ' f' , ' f' },
3163+ PlayerTextDrawAlignment = {' p' , ' i ' , ' i' },
3164+ PlayerTextDrawBackgroundColor = {' p' , ' i ' , ' c' },
3165+ PlayerTextDrawFont = {' p' , ' i ' , ' i' },
3166+ PlayerTextDrawColor = {' p' , ' i ' , ' c' },
3167+ PlayerTextDrawSetOutline = {' p' , ' i ' , ' i' },
3168+ PlayerTextDrawSetProportional = {' p' , ' i ' , ' i' },
3169+ PlayerTextDrawSetShadow = {' p' , ' i ' , ' i' },
3170+ PlayerTextDrawSetString = {' p' , ' i ' , ' s' },
3171+ PlayerTextDrawSetPreviewModel = {' p' , ' i ' , ' i' },
3172+ PlayerTextDrawSetPreviewVehCol = {' p' , ' i ' , ' i' , ' i' },
3173+ PlayerTextDrawSetSelectable = {' p' , ' i ' , ' i' },
3174+ PlayerTextDrawSetPreviewRot = {' p' , ' i ' , ' f' , ' f' , ' f' , ' f' },
30663175 CreatePlayerTextDraw = {' p' , ' f' , ' f' , ' s' },
30673176
30683177 TogglePlayerClock = {' p' , ' b' , client = true },
0 commit comments