Skip to content

Instantly share code, notes, and snippets.

@ohmypxl
Created December 25, 2022 05:44
Show Gist options
  • Save ohmypxl/747d29648f1088598ecfff2a90917f5b to your computer and use it in GitHub Desktop.
Save ohmypxl/747d29648f1088598ecfff2a90917f5b to your computer and use it in GitHub Desktop.
Simple clock textdraw with overload macros
// Overload macros for UpdateTextDrawTime
#define UpdateTextDrawTime(%1) (_:UTDT0:UTDT1:UpdateTdOvrld(%1))
#define UTDT0:UTDT1:UpdateTdOvrld(%1,%8PlayerText%9:%2) UpdateTextDrawTime__(%2,%1)
#define UTDT1:UpdateTdOvrld(%8Text%9:%1) UpdateTextDrawTime__(%1)
UpdateTextDrawTime__({PlayerText, Text}:textdraw, extraid = INVALID_PLAYER_ID, tag = tagof(textdraw))
{
new hour, minute, second;
gettime(hour, minute, second);
new string:timeFmt[64];
format(timeFmt, sizeof(timeFmt), "%02d:%02d:%02d", hour, minute, second);
if (tag == tagof(PlayerText:))
{
PlayerTextDrawSetString(extraid, textdraw, timeFmt);
}
else if (tag == tagof(Text:))
{
// Need to retag because of stupid warning
TextDrawSetString(Text:_:textdraw, timeFmt);
}
else
{
return 0;
}
return 1;
}
@ohmypxl
Copy link
Author

ohmypxl commented Dec 25, 2022

Code Example

TextDraw usage

#include <a_samp>
main() 
{
	new Text:text = TextDrawCreate(0.0, 0.0, "12:00:00");
	UpdateTextDrawTime(Text:text);
}

PlayerTextDraw usage

public OnPlayerConnect(playerid)
{
	new PlayerText:text = CreatePlayerTextDraw(playerid, 0.0, 0.0, "12:00:00");
	UpdateTextDrawTime(playerid, PlayerText:text);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment