JasperM

text.inc by Kaliber

Mar 10th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.94 KB | None | 0 0
  1. /* SA-MP Include GetText-Functions
  2.  *
  3.  * (c) by Kaliber, 2015
  4.  *
  5.  */
  6. #if !defined _samp_included
  7.     #include <a_samp>
  8. #endif
  9. #if defined _samp_getText
  10.     #endinput
  11. #endif
  12. #define _samp_getText
  13. #if !defined MAX_TEXT_DRAWS
  14.     #define MAX_TEXT_DRAWS (512)
  15. #endif
  16. #if !defined MAX_TEXT
  17.     #define MAX_TEXT (128)
  18. #endif
  19. #define A:: e_T_
  20. /*
  21.     native TextDrawGetText(Text:id);
  22.     native PlayerTextDrawGetText(PlayerText:id);
  23. */
  24. #if defined FILTERSCRIPT
  25.     forward A::OnFilterScriptInit();
  26. #else
  27.     forward A::OnGameModeInit();
  28. #endif
  29. native Text:A::TextDrawCreate(Float:x, Float:y, text[]) = TextDrawCreate;
  30. native A::TextDrawSetString(Text:text, string[]) = TextDrawSetString;
  31. native A::TextDrawDestroy(Text:text) = TextDrawDestroy;
  32.  
  33. native PlayerText:A::CreatePlayerTextDraw(playerid,Float:x, Float:y, text[]) = CreatePlayerTextDraw;
  34. native A::PlayerTextDrawSetString(playerid, PlayerText:text, string[]) = PlayerTextDrawSetString;
  35. native A::PlayerTextDrawDestroy(playerid, PlayerText:text) = PlayerTextDrawDestroy;
  36. enum A::e {
  37.     A::t[MAX_TEXT char], A::flag, bool:A::n
  38. };
  39. static A::S[MAX_TEXT_DRAWS][A::e];
  40.  
  41. stock TextDrawGetText(Text:id) {
  42.     new t = A::f1(_:id),tmp[MAX_TEXT] = "NaN";
  43.     if(t == INVALID_TEXT_DRAW) return tmp;
  44.     return strunpack(tmp,A::S[t][A::t],MAX_TEXT),tmp;
  45. }
  46. stock PlayerTextDrawGetText(PlayerText:id) {
  47.     new t = A::f2(_:id),tmp[MAX_TEXT] = "NaN";
  48.     if(t == INVALID_TEXT_DRAW) return tmp;
  49.     return strunpack(tmp,A::S[t][A::t],MAX_TEXT),tmp;
  50. }
  51. stock Text:_TextDrawCreate(Float:x, Float:y, text[]) {
  52.     new id = A::GetFree();
  53.     if(id == -1) return Text:INVALID_TEXT_DRAW;
  54.     A::S[id][A::flag] = _:A::TextDrawCreate(x,y,text),A::S[id][A::n]=false;
  55.     return strpack(A::S[id][A::t],text,MAX_TEXT),Text:A::S[id][A::flag];
  56. }
  57. #if defined _ALS_TextDrawCreate
  58.     #undef TextDrawCreate
  59. #else
  60.     #define _ALS_TextDrawCreate
  61. #endif
  62. #define TextDrawCreate _TextDrawCreate
  63. stock PlayerText:_CreatePlayerTextDraw(playerid, Float:x, Float:y, text[]) {
  64.     if(!IsPlayerConnected(playerid)) return PlayerText:INVALID_TEXT_DRAW;
  65.     new id = A::GetFree();
  66.     if(id == -1) return PlayerText:INVALID_TEXT_DRAW;
  67.     A::S[id][A::flag] = _:A::CreatePlayerTextDraw(playerid,x,y,text),A::S[id][A::n]=true;
  68.     return strpack(A::S[id][A::t],text,MAX_TEXT),PlayerText:A::S[id][A::flag];
  69. }
  70. #if defined _ALS_CreatePlayerTextDraw
  71.     #undef CreatePlayerTextDraw
  72. #else
  73.     #define _ALS_CreatePlayerTextDraw
  74. #endif
  75. #define CreatePlayerTextDraw _CreatePlayerTextDraw
  76. stock _TextDrawSetString(Text:text, string[]) {
  77.     new t = A::f1(_:text);
  78.     if(t == INVALID_TEXT_DRAW) return 0;
  79.     return strpack(A::S[t][A::t],string,MAX_TEXT),A::TextDrawSetString(text,string);
  80. }
  81. #if defined _ALS_TextDrawSetString
  82.     #undef TextDrawSetString
  83. #else
  84.     #define _ALS_TextDrawSetString
  85. #endif
  86. #define TextDrawSetString _TextDrawSetString
  87. stock _PlayerTextDrawSetString(playerid, PlayerText:text, string[]) {
  88.     new t = A::f2(_:text);
  89.     if(t == INVALID_TEXT_DRAW) return 0;
  90.     return strpack(A::S[t][A::t],string,MAX_TEXT),A::PlayerTextDrawSetString(playerid,text,string);
  91. }
  92. #if defined _ALS_PlayerTextDrawSetString
  93.     #undef PlayerTextDrawSetString
  94. #else
  95.     #define _ALS_PlayerTextDrawSetString
  96. #endif
  97. #define PlayerTextDrawSetString _PlayerTextDrawSetString
  98. stock _PlayerTextDrawDestroy(playerid, PlayerText:text) {
  99.     new t = A::f2(_:text);
  100.     if(t == INVALID_TEXT_DRAW) return 0;
  101.     return A::S[t][A::flag] = -1,A::PlayerTextDrawDestroy(playerid,text);
  102. }
  103. #if defined _ALS_PlayerTextDrawDestroy
  104.     #undef PlayerTextDrawDestroy
  105. #else
  106.     #define _ALS_PlayerTextDrawDestroy
  107. #endif
  108. #define PlayerTextDrawDestroy _PlayerTextDrawDestroy
  109. stock _TextDrawDestroy(Text:text) {
  110.     new t = A::f1(_:text);
  111.     if(t == INVALID_TEXT_DRAW) return 0;
  112.     return A::S[t][A::flag] = -1,A::TextDrawDestroy(text);
  113. }
  114. #if defined _ALS_TextDrawDestroy
  115.     #undef TextDrawDestroy
  116. #else
  117.     #define _ALS_TextDrawDestroy
  118. #endif
  119. #define TextDrawDestroy _TextDrawDestroy
  120.  
  121. #if defined FILTERSCRIPT
  122.     public OnFilterScriptInit() {
  123.         for(new i; i<sizeof(A::S); i++) A::S[i][A::flag] = -1;
  124.         return CallLocalFunction("e_T_OnFilterScriptInit","");
  125.     }
  126.     #if defined _ALS_OnFilterScriptInit
  127.         #undef OnFilterScriptInit
  128.     #else
  129.         #define _ALS_OnFilterScriptInit
  130.     #endif
  131.     #define OnFilterScriptInit e_T_OnFilterScriptInit
  132. #else
  133.     public OnGameModeInit() {
  134.         for(new i; i<sizeof(A::S); i++) A::S[i][A::flag] = -1;
  135.         return CallLocalFunction("e_T_OnGameModeInit","");
  136.     }
  137.     #if defined _ALS_OnGameModeInit
  138.         #undef OnGameModeInit
  139.     #else
  140.         #define _ALS_OnGameModeInit
  141.     #endif
  142.     #define OnGameModeInit e_T_OnGameModeInit
  143. #endif
  144. stock A::f1(const needle) {
  145.     for(new i; i<sizeof(A::S); i++) if(A::S[i][A::flag] == needle && !A::S[i][A::n]) return i;
  146.     return INVALID_TEXT_DRAW;
  147. }
  148. stock A::f2(const needle) {
  149.     for(new i; i<sizeof(A::S); i++) if(A::S[i][A::flag] == needle && A::S[i][A::n]) return i;
  150.     return INVALID_TEXT_DRAW;
  151. }
  152. stock A::GetFree() {
  153.     for(new i; i<sizeof(A::S); i++) if(A::S[i][A::flag] == -1) return i;
  154.     return INVALID_TEXT_DRAW;
  155. }
Add Comment
Please, Sign In to add comment