SHARE
TWEET

GoodNotes.inc

a guest Feb 16th, 2019 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     Author: knox
  4.     Version: 1.2
  5.     Data: 24.11.2018
  6.  
  7. */
  8.  
  9. #if defined _GoodNote_included
  10.     #endinput
  11. #endif
  12.  
  13. #define _GoodNote_included
  14.  
  15. #if !defined MAX_GOOD_NOTES
  16.     #define MAX_GOOD_NOTES 5
  17. #endif
  18.  
  19. #if !defined MAX_GOOD_TEXT_LENGTH
  20.     #define MAX_GOOD_TEXT_LENGTH 65
  21. #endif
  22.  
  23. #define GN_DIRECTION_UP 1       /* /\ */
  24. #define GN_DIRECTION_DOWN 2     /* \/ */
  25.  
  26. enum GOOD_NOTE_INFO
  27. {
  28.     GOOD_NOTE_ID,
  29.     PlayerText:GOOD_NOTE_TD_BG,
  30.     PlayerText:GOOD_NOTE_TD_TEXT,
  31.     GOOD_NOTE_TEXT[MAX_GOOD_TEXT_LENGTH],
  32.     GOOD_NOTE_TIME_OUT,
  33.     GOOD_NOTE_TIMER,
  34.     GOOD_NOTE_LINES,
  35.     GOOD_NOTE_COL_BG,
  36.     GOOD_NOTE_COL_TEXT
  37. }
  38.  
  39. static
  40.     GoodNoteData[MAX_PLAYERS][MAX_GOOD_NOTES][GOOD_NOTE_INFO],
  41.     GoodNoteLastId = 0,
  42.     Float:GoodNotePosX = 497.0,
  43.     Float:GoodNotePosY = 100.0,
  44.     Float:GoodNoteWidth = 111.0,
  45.     GoodNoteDirection = GN_DIRECTION_DOWN,
  46.     GoodNoteSound = 1149
  47. ;
  48.  
  49. stock SetGoodNoteSound(sound)
  50. {
  51.     GoodNoteSound = sound;
  52.     return 1;
  53. }
  54.  
  55. stock SetGoodNoteDirection(type)
  56. {
  57.     switch(type)
  58.     {
  59.         case GN_DIRECTION_UP, GN_DIRECTION_DOWN:
  60.         {
  61.             GoodNoteDirection = type;
  62.             return 1;
  63.         }
  64.     }
  65.     return 0;
  66. }
  67.  
  68. stock SetGoodNoteWidth(Float:width)
  69. {
  70.     GoodNoteWidth = width;
  71.     return 1;
  72. }
  73.  
  74. stock SetGoodNotePos(Float:pos_x, Float:pos_y)
  75. {
  76.     GoodNotePosX = pos_x;
  77.     GoodNotePosY = pos_y;
  78.     return 1;
  79. }
  80.  
  81. stock CreateGoodNote(playerid, const text[], time = 0, color = -1, bg_color = 255, sound = 1, const size = sizeof(text))
  82. {
  83.     static
  84.         free_pos,
  85.         lines_count,
  86.         Float:size_bg,
  87.         Float:pos_y
  88.     ;
  89.     free_pos = gn_GetFreeNotePos(playerid);
  90.     if(free_pos == -1) return 0;
  91.  
  92.     lines_count = gn_GetLineOfString(text, size);
  93.  
  94.     size_bg = 1.2 + (lines_count * 1.6);
  95.  
  96.     pos_y = GoodNotePosY;
  97.  
  98.     for(new i; i < free_pos; i++)
  99.     {
  100.         if(GoodNoteDirection == GN_DIRECTION_DOWN) {
  101.             pos_y += 12.0 + (GoodNoteData[playerid][i][GOOD_NOTE_LINES] * 16.0) + 5.0;
  102.         } else {
  103.             pos_y -= 12.0 + (GoodNoteData[playerid][i][GOOD_NOTE_LINES] * 16.0) + 5.0;
  104.         }
  105.     }
  106.  
  107.     if(lines_count > 1 && GoodNoteDirection == GN_DIRECTION_UP) {
  108.         pos_y -= (lines_count - 1) * 16.0;
  109.     }
  110.  
  111.     GoodNoteData[playerid][free_pos][GOOD_NOTE_LINES] = lines_count;
  112.     GoodNoteData[playerid][free_pos][GOOD_NOTE_COL_BG] = bg_color;
  113.     GoodNoteData[playerid][free_pos][GOOD_NOTE_COL_TEXT] = color;
  114.  
  115.     new PlayerText:temp_td = CreatePlayerTextDraw(playerid, GoodNotePosX, pos_y, "Box");
  116.     PlayerTextDrawLetterSize(playerid, temp_td, 0.0, size_bg);
  117.     PlayerTextDrawTextSize(playerid, temp_td, GoodNotePosX + GoodNoteWidth, 0.0);
  118.     PlayerTextDrawUseBox(playerid, temp_td, 1);
  119.     PlayerTextDrawBoxColor(playerid, temp_td, bg_color);
  120.     PlayerTextDrawShow(playerid, temp_td);
  121.  
  122.     GoodNoteData[playerid][free_pos][GOOD_NOTE_TD_BG] = temp_td;
  123.  
  124.     format(GoodNoteData[playerid][free_pos][GOOD_NOTE_TEXT], MAX_GOOD_TEXT_LENGTH, text);
  125.  
  126.     temp_td = CreatePlayerTextDraw(playerid, GoodNotePosX + 1.5, pos_y + 6.0, GoodNoteData[playerid][free_pos][GOOD_NOTE_TEXT]);
  127.     PlayerTextDrawLetterSize(playerid, temp_td, 0.4, 1.6);
  128.     PlayerTextDrawTextSize(playerid, temp_td, 500.3332, 0.0);
  129.     PlayerTextDrawColor(playerid, temp_td, color);
  130.     PlayerTextDrawFont(playerid, temp_td, 1);
  131.     PlayerTextDrawSetShadow(playerid, temp_td, 0);
  132.     PlayerTextDrawShow(playerid, temp_td);
  133.  
  134.     GoodNoteLastId++;
  135.  
  136.     GoodNoteData[playerid][free_pos][GOOD_NOTE_TD_TEXT] = temp_td;
  137.  
  138.     if(time == 0) {
  139.         GoodNoteData[playerid][free_pos][GOOD_NOTE_TIME_OUT] = 0;
  140.         GoodNoteData[playerid][free_pos][GOOD_NOTE_TIMER] = 0;
  141.     } else {
  142.         GoodNoteData[playerid][free_pos][GOOD_NOTE_TIME_OUT] = time + gettime();
  143.         GoodNoteData[playerid][free_pos][GOOD_NOTE_TIMER] = SetTimerEx("DestroyGoodNote", time * 1000, false, "dd", playerid, GoodNoteLastId);
  144.     }
  145.  
  146.     if(sound) {
  147.         PlayerPlaySound(playerid, GoodNoteSound, 0.0, 0.0, 0.0);
  148.     }
  149.  
  150.     GoodNoteData[playerid][free_pos][GOOD_NOTE_ID] = GoodNoteLastId;
  151.     return GoodNoteLastId;
  152. }
  153.  
  154. forward DestroyGoodNote(playerid, goodnoteid);
  155. public DestroyGoodNote(playerid, goodnoteid)
  156. {
  157.     static pos;
  158.     pos = gn_FindGoodNotePosById(playerid, goodnoteid);
  159.     if(pos == -1) return 0;
  160.     if(GoodNoteData[playerid][pos][GOOD_NOTE_TIMER] != 0) {
  161.         KillTimer(GoodNoteData[playerid][pos][GOOD_NOTE_TIMER]);
  162.     }
  163.     PlayerTextDrawHide(playerid, GoodNoteData[playerid][pos][GOOD_NOTE_TD_BG]);
  164.     PlayerTextDrawDestroy(playerid, GoodNoteData[playerid][pos][GOOD_NOTE_TD_BG]);
  165.     PlayerTextDrawHide(playerid, GoodNoteData[playerid][pos][GOOD_NOTE_TD_TEXT]);
  166.     PlayerTextDrawDestroy(playerid, GoodNoteData[playerid][pos][GOOD_NOTE_TD_TEXT]);
  167.     GoodNoteData[playerid][pos][GOOD_NOTE_ID] = 0;
  168.  
  169.     if(pos + 1 >= MAX_GOOD_NOTES) return 1;
  170.  
  171.     for(new j = pos + 1, time; j < MAX_GOOD_NOTES; j++)
  172.     {
  173.         if(GoodNoteData[playerid][j][GOOD_NOTE_ID] == 0) continue;
  174.         if(GoodNoteData[playerid][j][GOOD_NOTE_TIME_OUT] == 0) {
  175.             CreateGoodNote(
  176.                 playerid, GoodNoteData[playerid][j][GOOD_NOTE_TEXT], 0,
  177.                 GoodNoteData[playerid][j][GOOD_NOTE_COL_TEXT], GoodNoteData[playerid][j][GOOD_NOTE_COL_BG], 0
  178.             );
  179.         } else {
  180.             time = GoodNoteData[playerid][j][GOOD_NOTE_TIME_OUT] - gettime();
  181.             if(time > 0) {
  182.                 CreateGoodNote(
  183.                     playerid, GoodNoteData[playerid][j][GOOD_NOTE_TEXT], time,
  184.                     GoodNoteData[playerid][j][GOOD_NOTE_COL_TEXT], GoodNoteData[playerid][j][GOOD_NOTE_COL_BG], 0
  185.                 );
  186.             }
  187.         }
  188.         DestroyGoodNote(playerid, GoodNoteData[playerid][j][GOOD_NOTE_ID]);
  189.         return 1;
  190.     }
  191.     return 1;
  192. }
  193.  
  194. static stock gn_FindGoodNotePosById(playerid, goodnoteid)
  195. {
  196.     for(new i = 0; i < MAX_GOOD_NOTES; i++)
  197.     {
  198.         if(GoodNoteData[playerid][i][GOOD_NOTE_ID] == goodnoteid) return i;
  199.     }
  200.     return -1;
  201. }
  202.  
  203. static stock gn_GetFreeNotePos(playerid)
  204. {
  205.     for(new i = 0; i < MAX_GOOD_NOTES; i++)
  206.     {
  207.         if(GoodNoteData[playerid][i][GOOD_NOTE_ID] == 0) {
  208.             return i;
  209.         }
  210.     }
  211.     return -1;
  212. }
  213.  
  214. static stock gn_GetLineOfString(const string[], const size = sizeof(string))
  215. {
  216.     new
  217.         lines_count = 1,
  218.         perv_step_pos = 0,
  219.         step_pos = 0
  220.     ;
  221.     for(new i = 0; i < size; i++)
  222.     {
  223.         if(string[i] == '\0') break;
  224.         step_pos = strfind(string, "~n~", false, perv_step_pos);
  225.         if(step_pos == -1) {
  226.             break;
  227.         } else {
  228.             perv_step_pos = step_pos + 3;
  229.             lines_count++;
  230.         }
  231.     }
  232.     return lines_count;
  233. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top