Advertisement
Guest User

Dynamic label create - UPDATED

a guest
Oct 30th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. /*
  2. DINAMICNO KREIRANJE LABELA
  3. BY ZIXON
  4. v1.0.0
  5. */
  6. #include <a_samp>
  7. #include <zcmd>
  8. #include <streamer>
  9. #include <YSI\y_ini>
  10.  
  11.  
  12. /////////// cuvanje i ostalo
  13. #define LABEL_FILE "Labels/%d.ini"
  14. #define MAX_L 200
  15. enum lCuvanje
  16. {
  17. Float:PozicijaX,
  18. Float:PozicijaY,
  19. Float:PozicijaZ,
  20. Text[256],
  21. Namesten
  22. };
  23. new LabelC[MAX_L][lCuvanje];
  24. new Text3D:Label[sizeof(LabelC)];
  25.  
  26. ///////////// ucitavanje
  27. forward Load_Label(lid, name[], value[]);
  28. public Load_Label(lid, name[], value[])
  29. {
  30. INI_Float("PozicijaX",LabelC[lid][PozicijaX]);
  31. INI_Float("PozicijaY",LabelC[lid][PozicijaY]);
  32. INI_Float("PozicijaZ",LabelC[lid][PozicijaZ]);
  33. INI_String("Text",LabelC[lid][Text],256);
  34. INI_Int("Namesten",LabelC[lid][Namesten]);
  35. return 1;
  36. }
  37.  
  38. ///////////// sejvanje labela
  39. stock L_Save(lid)
  40. {
  41. new LabellFile[128];
  42. format(LabellFile, sizeof(LabellFile), LABEL_FILE, lid);
  43. new INI:File = INI_Open(LabellFile);
  44. INI_WriteFloat(File, "PozicijaX", LabelC[lid][PozicijaX]);
  45. INI_WriteFloat(File, "PozicijaY", LabelC[lid][PozicijaY]);
  46. INI_WriteFloat(File, "PozicijaZ", LabelC[lid][PozicijaZ]);
  47. INI_WriteString(File, "Text", LabelC[lid][Text]);
  48. INI_WriteInt(File, "Namesten", LabelC[lid][Namesten]);
  49. INI_Close(File);
  50. return 1;
  51. }
  52. ///////////// komande
  53. CMD:labelcreate(playerid, params[])
  54. {
  55. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Kreiranje labela", "Unesi tekst:", "Unesi", "Odustani");
  56. return 1;
  57. }
  58.  
  59. CMD:labeldelete(playerid, params[])
  60. {
  61. for(new cc; cc < MAX_L; cc++)
  62. {
  63. if(IsPlayerInRangeOfPoint(playerid, 1.5, LabelC[cc][PozicijaX], LabelC[cc][PozicijaY], LabelC[cc][PozicijaZ]))
  64. {
  65. if(LabelC[cc][Namesten] == 1)
  66. {
  67. DestroyDynamic3DTextLabel(Label[cc]);
  68. LabelC[cc][PozicijaX] = 0;
  69. LabelC[cc][PozicijaY] = 0;
  70. LabelC[cc][PozicijaZ] = 0;
  71. LabelC[cc][Namesten] = 0;
  72. strmid(LabelC[cc][Text], "0", 0, strlen("0"), 255);
  73. L_Save(cc);
  74. new l_file_delete[100];
  75. format(l_file_delete,128,"Labels/%d.ini", cc);
  76. fremove(l_file_delete);
  77. new string[60];
  78. format(string,sizeof(string), "Obrisao si label id %d.", cc);
  79. SendClientMessage(playerid, -1, string);
  80. }
  81. }
  82. }
  83. return 1;
  84. }
  85. //////////// callbacks
  86. public OnGameModeInit()
  87. {
  88. for(new cc = 0; cc < sizeof(LabelC); cc++)
  89. {
  90. new LabelFile[60];
  91. format(LabelFile, sizeof(LabelFile), LABEL_FILE, cc);
  92. if(fexist(LabelFile))
  93. {
  94. INI_ParseFile(LabelFile, "Load_Label", .bExtra = true, .extra = cc);
  95. if(LabelC[cc][Namesten] == 1)
  96. {
  97. new string[256];
  98. format(string,sizeof(string),LabelC[cc][Text]);
  99.  
  100. Label[cc] = CreateDynamic3DTextLabel(string, -1, LabelC[cc][PozicijaX], LabelC[cc][PozicijaY], LabelC[cc][PozicijaZ], 5);
  101. }
  102. }
  103. }
  104. return 1;
  105. }
  106.  
  107. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  108. {
  109. if(dialogid == 1)
  110. {
  111. if(!response) return 1;
  112. if(response)
  113. {
  114. if(strlen(inputtext) == 0) return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Kreiranje labela", "Unesi tekst:", "Unesi", "Odustani");
  115. else if(strlen(inputtext) > 0)
  116. {
  117. new lvariable = 0;
  118. new Float:Pos[3], string[256];
  119. GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  120. for(new cc = 0; cc < sizeof(LabelC); cc++)
  121. {
  122. if(LabelC[cc][Namesten] == 1)
  123. {
  124. lvariable = cc + 1;
  125. }
  126. }
  127. if(lvariable > MAX_L) return SendClientMessage(playerid, -1, "Nije moguce kreiranje vise od 200 labela!");
  128. LabelC[lvariable][PozicijaX] = Pos[0];
  129. LabelC[lvariable][PozicijaY] = Pos[1];
  130. LabelC[lvariable][PozicijaZ] = Pos[2];
  131. LabelC[lvariable][Namesten] = 1;
  132. format(string, sizeof(string), "%s", inputtext);
  133. strmid(LabelC[lvariable][Text], string, 0, strlen(string), 255);
  134. Label[lvariable] = CreateDynamic3DTextLabel(string, -1, LabelC[lvariable][PozicijaX], LabelC[lvariable][PozicijaY], LabelC[lvariable][PozicijaZ], 20);
  135. L_Save(lvariable);
  136. format(string, sizeof(string), "Napravio si label sa textom %s, id labela - %d.", inputtext, lvariable);
  137. SendClientMessage(playerid, -1, string);
  138. }
  139. }
  140. }
  141. return 1;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement