Advertisement
Guest User

Untitled

a guest
Jan 6th, 2014
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.41 KB | None | 0 0
  1. /**
  2. * Progreso Lentelës Sukurëjas
  3. * Copyright 2007-2010 Infernus' Group,
  4. * Fl?vio Toribio ([email protected])
  5. *
  6. * This is an add-on for the include Progress Bar
  7. * http://forum.sa-mp.com/index.php?topic=138556
  8. * Sulietuvinimas pagal Siera.
  9. * Skirta www.supergames.lt.
  10. */
  11.  
  12. #include <a_samp>
  13. #include <progress>
  14.  
  15. #if !defined SetPVarInt
  16. #error Version 0.3 R7 or higher of SA:MP Server requiered
  17. #endif
  18.  
  19. #if _progress_version < 0x1310
  20. #error Version 1.3.1 or higher of progress.inc required
  21. #endif
  22.  
  23. #define DIALOG_BAR 1834
  24. #define DIALOG_COLOR 1835
  25. #define DIALOG_DONE 1836
  26.  
  27. #define ITEM_MOVE 0
  28. #define ITEM_RESIZE 1
  29. #define ITEM_COLOR 2
  30. #define ITEM_DONE 3
  31.  
  32. #define MOVE_NONE 0
  33. #define MOVE_POSITION 1
  34. #define MOVE_SIZE 2
  35.  
  36. static Bars[MAX_BARS][e_bar];
  37.  
  38. public OnFilterScriptInit()
  39. {
  40. for(new i = 0; i < MAX_PLAYERS; ++i) if(IsPlayerConnected(i))
  41. {
  42. OnPlayerSpawn(i);
  43. }
  44. print("Progress Bar Creator by Flavio Toribio loaded/Sulietuvinimas pagal Siera");
  45. return 1;
  46. }
  47.  
  48. public OnFilterScriptExit()
  49. {
  50. for(new i = 0; i < MAX_PLAYERS; ++i) if(IsPlayerConnected(i))
  51. {
  52. OnPlayerDisconnect(i, 0);
  53. if(GetPVarInt(i, "MovingBar"))
  54. {
  55. TogglePlayerControllable(i, true);
  56. }
  57. if(GetPVarInt(i, "CreatingBar"))
  58. {
  59. DeletePVar(i, "BarID");
  60. DeletePVar(i, "MovingBar");
  61. DeletePVar(i, "CreatingBar");
  62. }
  63. }
  64. print("Progress Bar Creator by Flavio Toribio unloaded/Sulietuvinimas pagal Siera");
  65. return 1;
  66. }
  67.  
  68. public OnPlayerSpawn(playerid)
  69. {
  70. SendClientMessage(playerid, 0xFFF000AA, "Naudok /bar jaigu nori pradëti kurti!");
  71. return 1;
  72. }
  73.  
  74. GetVars(index, &Float:x, &Float:y, &Float:w, &Float:h, &color)
  75. {
  76. x = Bars[index][pb_x];
  77. y = Bars[index][pb_y];
  78. w = Bars[index][pb_w];
  79. h = Bars[index][pb_h];
  80. color = Bars[index][pb_color];
  81. }
  82.  
  83. UpdateVars(index, Float:x, Float:y, Float:w, Float:h, color)
  84. {
  85. Bars[index][pb_x] = x;
  86. Bars[index][pb_y] = y;
  87. Bars[index][pb_w] = w;
  88. Bars[index][pb_h] = h;
  89. Bars[index][pb_color] = color;
  90. }
  91.  
  92. DeleteVars(index)
  93. {
  94. Bars[index][pb_x] = 0.0;
  95. Bars[index][pb_y] = 0.0;
  96. Bars[index][pb_w] = 0.0;
  97. Bars[index][pb_h] = 0.0;
  98. Bars[index][pb_color] = 0;
  99. }
  100.  
  101. public OnPlayerUpdate(playerid)
  102. {
  103. if(GetPVarInt(playerid, "MovingBar"))
  104. {
  105. new keys, ud, lr;
  106. GetPlayerKeys(playerid, keys, ud, lr);
  107.  
  108. new Bar:barid = Bar:GetPVarInt(playerid, "BarID");
  109. new Float:x, Float:y, Float:w, Float:h, color;
  110.  
  111. if(ud || lr)
  112. {
  113. DestroyProgressBar(barid);
  114. GetVars(_:barid, x, y, w, h, color);
  115. DeleteVars(_:barid);
  116. if(ud == KEY_UP)
  117. {
  118. if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  119. {
  120. y -= keys & KEY_SPRINT ? 2.0 : 1.0;
  121. if(y < 0.0) y = 0.0;
  122. }
  123. else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  124. {
  125. h -= keys & KEY_SPRINT ? 2.0 : 1.0;
  126. if(h < 1.5) h = 1.5;
  127. }
  128. }
  129. else if(ud == KEY_DOWN)
  130. {
  131. if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  132. {
  133. y += keys & KEY_SPRINT ? 2.0 : 1.0;
  134. if(y > 480.0) y = 480.0;
  135. }
  136. else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  137. {
  138. h += keys & KEY_SPRINT ? 2.0 : 1.0;
  139. if(h > 480.0) h = 480.0;
  140. }
  141. }
  142. if(lr == KEY_LEFT)
  143. {
  144. if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  145. {
  146. x -= keys & KEY_SPRINT ? 2.0 : 1.0;
  147. if(x < 0.0) x = 0.0;
  148. }
  149. else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  150. {
  151. w -= keys & KEY_SPRINT ? 2.0 : 1.0;
  152. if(w < 1.5) w = 1.5;
  153. }
  154. }
  155. else if(lr == KEY_RIGHT)
  156. {
  157. if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  158. {
  159. x += keys & KEY_SPRINT ? 2.0 : 1.0;
  160. if(x > 640.0) x = 640.0;
  161. }
  162. else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  163. {
  164. w += keys & KEY_SPRINT ? 2.0 : 1.0;
  165. if(w > 640.0) w = 640.0;
  166. }
  167. }
  168. barid = CreateProgressBar(x, y, w, h, color, 100.0);
  169. SetProgressBarValue(barid, 50.0);
  170. ShowProgressBarForPlayer(playerid, barid);
  171. UpdateVars(_:barid, x, y, w, h, color);
  172. SetPVarInt(playerid, "BarID", _:barid);
  173. }
  174. }
  175. return 1;
  176. }
  177.  
  178. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  179. {
  180. if(newkeys & KEY_SECONDARY_ATTACK)
  181. {
  182. if(GetPVarInt(playerid, "MovingBar"))
  183. {
  184. TogglePlayerControllable(playerid, true);
  185. SetPVarInt(playerid, "MovingBar", MOVE_NONE);
  186. SendClientMessage(playerid, 0xFFF000AA, "Dabar naudok /bar dar karta, jai patobulinti.");
  187. }
  188. }
  189. return 1;
  190. }
  191.  
  192. public OnPlayerDeath(playerid, killerid, reason)
  193. {
  194. if(GetPVarInt(playerid, "MovingBar"))
  195. {
  196. TogglePlayerControllable(playerid, true);
  197. SetPVarInt(playerid, "MovingBar", MOVE_NONE);
  198. }
  199. return 1;
  200. }
  201.  
  202. public OnPlayerDisconnect(playerid, reason)
  203. {
  204. if(GetPVarInt(playerid, "CreatingBar") == 1)
  205. {
  206. DestroyProgressBar(Bar:GetPVarInt(playerid, "BarID"));
  207. DeleteVars(GetPVarInt(playerid, "BarID"));
  208. }
  209. return 1;
  210. }
  211.  
  212. public OnPlayerCommandText(playerid, cmdtext[])
  213. {
  214. if(!strcmp(cmdtext, "/bar", true))
  215. {
  216. if(GetPVarInt(playerid, "CreatingBar") == 0)
  217. {
  218. new Bar:barid;
  219. if((barid = CreateProgressBar(320.0, 240.0, 56.50, 3.39, 0xFF0000FF, 100.0)) == INVALID_BAR_ID)
  220. {
  221. SendClientMessage(playerid, 0xFF0000AA, "Atsipraðome, rastas Eroras / Kurti negalima.");
  222. return 1;
  223. }
  224. SetProgressBarValue(barid, 50.0);
  225. ShowProgressBarForPlayer(playerid, barid);
  226. TogglePlayerControllable(playerid, false);
  227. UpdateVars(_:barid, 320.0, 240.0, 55.5, 3.2, 0xFF0000FF);
  228.  
  229. SetPVarInt(playerid, "MovingBar", MOVE_POSITION);
  230. SetPVarInt(playerid, "CreatingBar", 1);
  231. SetPVarInt(playerid, "BarID", _:barid);
  232.  
  233. SendClientMessage(playerid, 0xFFF000AA, "Naudok rodykles klavetûroje, judinti lentelei.");
  234. SendClientMessage(playerid, 0xFFF000AA, "Laikyk 'Sprint' mygtukà greitesniam lentelës perkëlimui.");
  235. SendClientMessage(playerid, 0xFFF000AA, "Naudok 'Enter' norint baigti perkëlimà.");
  236. }
  237. else
  238. {
  239. ShowPlayerDialog(playerid, DIALOG_BAR, DIALOG_STYLE_LIST, "Progreso Lentelë", "Keisti pozicijà\nKeisti dydá\nKeisti spalvà\nBaigti darbà", "Gerai", "Iðeiti");
  240. }
  241. return 1;
  242. }
  243. return 0;
  244. }
  245.  
  246. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  247. {
  248. if(dialogid == DIALOG_BAR)
  249. {
  250. if(response)
  251. {
  252. if(listitem == ITEM_MOVE)
  253. {
  254. SetPVarInt(playerid, "MovingBar", MOVE_POSITION);
  255. TogglePlayerControllable(playerid, false);
  256. SendClientMessage(playerid, 0xFFF000AA, "Naudok rodykles klavetûroje, judinti lentelei.");
  257. SendClientMessage(playerid, 0xFFF000AA, "Laikyk 'Sprint' mygtukà greitesniam lentelës perkëlimui.");
  258. SendClientMessage(playerid, 0xFFF000AA, "Naudok 'Enter' norint baigti perkëlimà.");
  259. }
  260. else if(listitem == ITEM_RESIZE)
  261. {
  262. SetPVarInt(playerid, "MovingBar", MOVE_SIZE);
  263. TogglePlayerControllable(playerid, false);
  264. SendClientMessage(playerid, 0xFFF000AA, "Naudok rodykles klavetûroje, keisti lentelës formai.");
  265. SendClientMessage(playerid, 0xFFF000AA, "Laikyk 'Sprint' mygtukà, keisti formai greièiau.");
  266. SendClientMessage(playerid, 0xFFF000AA, "Naudok 'Enter' norint baigti.");
  267. }
  268. else if(listitem == ITEM_COLOR)
  269. {
  270. ShowPlayerDialog(playerid, DIALOG_COLOR, DIALOG_STYLE_INPUT, "Keisti spalvà", "Raðyk spalvà ðeðioliktainiu formatu.\nPavyzdys: 0xFFF000FF", "Gerai", "Atðaukti");
  271. }
  272. else if(listitem == ITEM_DONE)
  273. {
  274. ShowPlayerDialog(playerid, DIALOG_DONE, DIALOG_STYLE_INPUT, "Lentelës Saugojimas", "Yraðykite lentelës pavadinimà;\nJums nereikia iðsaugoti failo .txt formatu, jis bus iðsaugotas automatiðkai.\nLentelæ rasite ScriptFiles papkëje.", "Saugoti", "Atðaukti");
  275. }
  276. }
  277. }
  278. else if(dialogid == DIALOG_COLOR)
  279. {
  280. SetProgressBarColor(Bar:GetPVarInt(playerid, "BarID"), hexstr(inputtext));
  281. UpdateProgressBar(Bar:GetPVarInt(playerid, "BarID"), playerid);
  282. Bars[GetPVarInt(playerid, "BarID")][pb_color] = hexstr(inputtext);
  283. }
  284. else if(dialogid == DIALOG_DONE)
  285. {
  286. new File:file, name[32], line[128], barid;
  287.  
  288. if(strlen(inputtext) > 32 - 4)
  289. {
  290. strdel(inputtext, 32 - 4, strlen(inputtext));
  291. }
  292. format(name, sizeof name, "%s.txt", inputtext);
  293.  
  294. if(!(file = fopen(name, io_write)))
  295. {
  296. SendClientMessage(playerid, 0xFF0000AA, "Iðkilo problema yraðant faila, bandykite dar kartà.");
  297. ShowPlayerDialog(playerid, DIALOG_DONE, DIALOG_STYLE_INPUT, "Lentelës Saugojimas", "Yraðykite lentelës pavadinimà;\nJums nereikia iðsaugoti failo .txt formatu, jis bus iðsaugotas automatiðkai.\nLentelæ rasite ScriptFiles papkëje.", "Saugoti", "Atðaukti");
  298. return 1;
  299. }
  300. barid = GetPVarInt(playerid, "BarID");
  301. format(line, sizeof line, "new Bar:bar = CreateProgressBar(%.2f, %.2f, %.2f, %.2f, %d, 100.0);\r\n",
  302. Bars[barid][pb_x], Bars[barid][pb_y], Bars[barid][pb_w], Bars[barid][pb_h], Bars[barid][pb_color]);
  303.  
  304. fwrite(file, line);
  305. fwrite(file, "ShowProgressBarForAll(bar);\r\n");
  306. fwrite(file, "\r\nDabar, paþiûrëkite y oficialø SA-MP forumà, kaip tai naudoti:\r\n\r\nhttp://forum.sa-mp.com/index.php?topic=138556\r\n");
  307. fclose(file);
  308.  
  309. DeleteVars(barid);
  310. DestroyProgressBar(Bar:barid);
  311. DeletePVar(playerid, "BarID");
  312. DeletePVar(playerid, "MovingBar");
  313. DeletePVar(playerid, "CreatingBar");
  314.  
  315. SendClientMessage(playerid, 0xFFFF00AA, "Viskas baigtà! Dabar pasiþiûrëkite y savo sukurtà darbà!");
  316. SendClientMessage(playerid, 0xFFFFFFAA, "Dabar galite sukurti kità Progreso Lentelæ.");
  317. }
  318. return 1;
  319. }
  320.  
  321. stock hexstr(string[])
  322. {
  323. new ret, val, i;
  324. if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) i = 2;
  325. while(string[i])
  326. {
  327. ret <<= 4;
  328. val = string[i++] - '0';
  329. if(val > 0x09) val -= 0x07;
  330. if(val > 0x0F) val -= 0x20;
  331. if(val < 0x01) continue;
  332. if(val < 0x10) ret += val;
  333. }
  334. return ret;
  335. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement