Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.06 KB | None | 0 0
  1. /**
  2.  *  Progress Bar Creator
  3.  *  Copyright 2007-2010 Infernus' Group,
  4.  *  Flavio Toribio (flavio_toribio@hotmail.com)
  5.  *
  6.  *  This is an add-on for the include Progress Bar
  7.  *  http://forum.sa-mp.com/index.php?topic=138556
  8.  */
  9.  
  10. #include <a_samp>
  11. #include <progress>
  12.  
  13. #if !defined SetPVarInt
  14.     #error Version 0.3 R7 or higher of SA:MP Server requiered
  15. #endif
  16.  
  17. #if _progress_version < 0x1310
  18.     #error Version 1.3.1 or higher of progress.inc required
  19. #endif
  20.  
  21. #define DIALOG_BAR      1834
  22. #define DIALOG_COLOR    1835
  23. #define DIALOG_DONE     1836
  24.  
  25. #define ITEM_MOVE       0
  26. #define ITEM_RESIZE     1
  27. #define ITEM_COLOR      2
  28. #define ITEM_DONE       3
  29.  
  30. #define MOVE_NONE       0
  31. #define MOVE_POSITION   1
  32. #define MOVE_SIZE       2
  33.  
  34. static Bars[MAX_BARS][e_bar];
  35.  
  36. public OnFilterScriptInit()
  37. {
  38.     for(new i = 0; i < MAX_PLAYERS; ++i) if(IsPlayerConnected(i))
  39.     {
  40.         OnPlayerSpawn(i);
  41.     }
  42.     print("제작자: Flavio Toribio");
  43.     return 1;
  44. }
  45.  
  46. public OnFilterScriptExit()
  47. {
  48.     for(new i = 0; i < MAX_PLAYERS; ++i) if(IsPlayerConnected(i))
  49.     {
  50.         OnPlayerDisconnect(i, 0);
  51.         if(GetPVarInt(i, "MovingBar"))
  52.         {
  53.             TogglePlayerControllable(i, true);
  54.         }
  55.         if(GetPVarInt(i, "CreatingBar"))
  56.         {
  57.             DeletePVar(i, "BarID");
  58.             DeletePVar(i, "MovingBar");
  59.             DeletePVar(i, "CreatingBar");
  60.         }
  61.     }
  62.     return 1;
  63. }
  64.  
  65. public OnPlayerSpawn(playerid)
  66. {
  67.     SendClientMessage(playerid, 0xFFF000AA, "/bar 을 이용하여 프로그레스바를 생성하실수 있습니다.");
  68.     return 1;
  69. }
  70.  
  71. GetVars(index, &Float:x, &Float:y, &Float:w, &Float:h, &color)
  72. {
  73.     x = Bars[index][pb_x];
  74.     y = Bars[index][pb_y];
  75.     w = Bars[index][pb_w];
  76.     h = Bars[index][pb_h];
  77.     color = Bars[index][pb_color];
  78. }
  79.  
  80. UpdateVars(index, Float:x, Float:y, Float:w, Float:h, color)
  81. {
  82.     Bars[index][pb_x] = x;
  83.     Bars[index][pb_y] = y;
  84.     Bars[index][pb_w] = w;
  85.     Bars[index][pb_h] = h;
  86.     Bars[index][pb_color] = color;
  87. }
  88.  
  89. DeleteVars(index)
  90. {
  91.     Bars[index][pb_x] = 0.0;
  92.     Bars[index][pb_y] = 0.0;
  93.     Bars[index][pb_w] = 0.0;
  94.     Bars[index][pb_h] = 0.0;
  95.     Bars[index][pb_color] = 0;
  96. }
  97.  
  98. public OnPlayerUpdate(playerid)
  99. {
  100.     if(GetPVarInt(playerid, "MovingBar"))
  101.     {
  102.         new keys, ud, lr;
  103.         GetPlayerKeys(playerid, keys, ud, lr);
  104.  
  105.         new Bar:barid = Bar:GetPVarInt(playerid, "BarID");
  106.         new Float:x, Float:y, Float:w, Float:h, color;
  107.  
  108.         if(ud || lr)
  109.         {
  110.             DestroyProgressBar(barid);
  111.             GetVars(_:barid, x, y, w, h, color);
  112.             DeleteVars(_:barid);
  113.             if(ud == KEY_UP)
  114.             {
  115.                 if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  116.                 {
  117.                     y -= keys & KEY_SPRINT ? 2.0 : 1.0;
  118.                     if(y < 0.0) y = 0.0;
  119.                 }
  120.                 else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  121.                 {
  122.                     h -= keys & KEY_SPRINT ? 2.0 : 1.0;
  123.                     if(h < 1.5) h = 1.5;
  124.                 }
  125.             }
  126.             else if(ud == KEY_DOWN)
  127.             {
  128.                 if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  129.                 {
  130.                     y += keys & KEY_SPRINT ? 2.0 : 1.0;
  131.                     if(y > 480.0) y = 480.0;
  132.                 }
  133.                 else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  134.                 {
  135.                     h += keys & KEY_SPRINT ? 2.0 : 1.0;
  136.                     if(h > 480.0) h = 480.0;
  137.                 }
  138.             }
  139.             if(lr == KEY_LEFT)
  140.             {
  141.                 if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  142.                 {
  143.                     x -= keys & KEY_SPRINT ? 2.0 : 1.0;
  144.                     if(x < 0.0) x = 0.0;
  145.                 }
  146.                 else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  147.                 {
  148.                     w -= keys & KEY_SPRINT ? 2.0 : 1.0;
  149.                     if(w < 1.5) w = 1.5;
  150.                 }
  151.             }
  152.             else if(lr == KEY_RIGHT)
  153.             {
  154.                 if(GetPVarInt(playerid, "MovingBar") == MOVE_POSITION)
  155.                 {
  156.                     x += keys & KEY_SPRINT ? 2.0 : 1.0;
  157.                     if(x > 640.0) x = 640.0;
  158.                 }
  159.                 else if(GetPVarInt(playerid, "MovingBar") == MOVE_SIZE)
  160.                 {
  161.                     w += keys & KEY_SPRINT ? 2.0 : 1.0;
  162.                     if(w > 640.0) w = 640.0;
  163.                 }
  164.             }
  165.             barid = CreateProgressBar(x, y, w, h, color, 100.0);
  166.             SetProgressBarValue(barid, 50.0);
  167.             ShowProgressBarForPlayer(playerid, barid);
  168.             UpdateVars(_:barid, x, y, w, h, color);
  169.             SetPVarInt(playerid, "BarID", _:barid);
  170.         }
  171.     }
  172.     return 1;
  173. }
  174.  
  175. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  176. {
  177.     if(newkeys & KEY_SECONDARY_ATTACK)
  178.     {
  179.         if(GetPVarInt(playerid, "MovingBar"))
  180.         {
  181.             TogglePlayerControllable(playerid, true);
  182.             SetPVarInt(playerid, "MovingBar", MOVE_NONE);
  183.             SendClientMessage(playerid, 0xFFF000AA, "/bar를 재입력하시면 생성을 마칩니다.");
  184.         }
  185.     }
  186.     return 1;
  187. }
  188.  
  189. public OnPlayerDeath(playerid, killerid, reason)
  190. {
  191.     if(GetPVarInt(playerid, "MovingBar"))
  192.     {
  193.         TogglePlayerControllable(playerid, true);
  194.         SetPVarInt(playerid, "MovingBar", MOVE_NONE);
  195.     }
  196.     return 1;
  197. }
  198.  
  199. public OnPlayerDisconnect(playerid, reason)
  200. {
  201.     if(GetPVarInt(playerid, "CreatingBar") == 1)
  202.     {
  203.         DestroyProgressBar(Bar:GetPVarInt(playerid, "BarID"));
  204.         DeleteVars(GetPVarInt(playerid, "BarID"));
  205.     }
  206.     return 1;
  207. }
  208.  
  209. public OnPlayerCommandText(playerid, cmdtext[])
  210. {
  211.     if(!strcmp(cmdtext, "/bar", true))
  212.     {
  213.         if(GetPVarInt(playerid, "CreatingBar") == 0)
  214.         {
  215.             new Bar:barid;
  216.             if((barid = CreateProgressBar(320.0, 240.0, 56.50, 3.39, 0xFF0000FF, 100.0)) == INVALID_BAR_ID)
  217.             {
  218.                 SendClientMessage(playerid, 0xFF0000AA, "이터널에러발생.");
  219.                 return 1;
  220.             }
  221.             SetProgressBarValue(barid, 50.0);
  222.             ShowProgressBarForPlayer(playerid, barid);
  223.             TogglePlayerControllable(playerid, false);
  224.             UpdateVars(_:barid, 320.0, 240.0, 55.5, 3.2, 0xFF0000FF);
  225.  
  226.             SetPVarInt(playerid, "MovingBar", MOVE_POSITION);
  227.             SetPVarInt(playerid, "CreatingBar", 1);
  228.             SetPVarInt(playerid, "BarID", _:barid);
  229.  
  230.             SendClientMessage(playerid, 0xFFF000AA, "(W: 위 | S : 아래 | A = 왼쪽 | D = 오른쪽)");
  231.             SendClientMessage(playerid, 0xFFF000AA, "Sprint키로 빠르게 움직일수 있습니다");
  232.         }
  233.         else
  234.         {
  235.             ShowPlayerDialog(playerid, DIALOG_BAR, DIALOG_STYLE_LIST, "프로그레스바", "좌표변경\n크기변경\n색상변경\n저장", "확인", "취소");
  236.         }
  237.         return 1;
  238.     }
  239.     return 0;
  240. }
  241.  
  242. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  243. {
  244.     if(dialogid == DIALOG_BAR)
  245.     {
  246.         if(response)
  247.         {
  248.             if(listitem == ITEM_MOVE)
  249.             {
  250.                 SetPVarInt(playerid, "MovingBar", MOVE_POSITION);
  251.                 TogglePlayerControllable(playerid, false);
  252.             }
  253.             else if(listitem == ITEM_RESIZE)
  254.             {
  255.                 SetPVarInt(playerid, "MovingBar", MOVE_SIZE);
  256.                 TogglePlayerControllable(playerid, false);
  257.             }
  258.             else if(listitem == ITEM_COLOR)
  259.             {
  260.                 ShowPlayerDialog(playerid, DIALOG_COLOR, DIALOG_STYLE_INPUT, "색상변경", "16진수의 색상코드를 입력하세요 (Ex: 0xFFFFFFF).", "확인", "취소");
  261.             }
  262.             else if(listitem == ITEM_DONE)
  263.             {
  264.                 ShowPlayerDialog(playerid, DIALOG_DONE, DIALOG_STYLE_INPUT, "저장", "원하시는 파일명을 입력해주세요 아무것도 입력하지 않을시 스크립트 폴더에 자동으로 txt파일이 생성됩니다.", "섹스", "취소");
  265.             }
  266.         }
  267.     }
  268.     else if(dialogid == DIALOG_COLOR)
  269.     {
  270.         SetProgressBarColor(Bar:GetPVarInt(playerid, "BarID"), hexstr(inputtext));
  271.         UpdateProgressBar(Bar:GetPVarInt(playerid, "BarID"), playerid);
  272.         Bars[GetPVarInt(playerid, "BarID")][pb_color] = hexstr(inputtext);
  273.     }
  274.     else if(dialogid == DIALOG_DONE)
  275.     {
  276.         new File:file, name[32], line[128], barid;
  277.  
  278.         if(strlen(inputtext) > 32 - 4)
  279.         {
  280.             strdel(inputtext, 32 - 4, strlen(inputtext));
  281.         }
  282.         format(name, sizeof name, "%s.txt", inputtext);
  283.  
  284.         if(!(file = fopen(name, io_write)))
  285.         {
  286.             SendClientMessage(playerid, 0xFF0000AA, "파일에 에러가 발생하였습니다 재시도하세요.");
  287.             ShowPlayerDialog(playerid, DIALOG_DONE, DIALOG_STYLE_INPUT, "저장", "원하시는 파일명을 입력해주세요 아무것도 입력하지 않을시 스크립트 폴더에 자동으로 txt파일이 생성됩니다.", "섹스", "취소");
  288.             return 1;
  289.         }
  290.         barid = GetPVarInt(playerid, "BarID");
  291.         format(line, sizeof line, "new Bar:bar = CreateProgressBar(%.2f, %.2f, %.2f, %.2f, %d, 100.0);\r\n",
  292.             Bars[barid][pb_x], Bars[barid][pb_y], Bars[barid][pb_w], Bars[barid][pb_h], Bars[barid][pb_color]);
  293.  
  294.         fwrite(file, line);
  295.         fwrite(file, "ShowProgressBarForAll(bar);\r\n");
  296.         fclose(file);
  297.  
  298.         DeleteVars(barid);
  299.         DestroyProgressBar(Bar:barid);
  300.         DeletePVar(playerid, "BarID");
  301.         DeletePVar(playerid, "MovingBar");
  302.         DeletePVar(playerid, "CreatingBar");
  303.     }
  304.     return 1;
  305. }
  306.  
  307. stock hexstr(string[])
  308. {
  309.  new ret, val, i;
  310.  if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) i = 2;
  311.  while(string[i])
  312.  {
  313.   ret <<= 4;
  314.   val = string[i++] - '0';
  315.   if(val > 0x09) val -= 0x07;
  316.   if(val > 0x0F) val -= 0x20;
  317.   if(val < 0x01) continue;
  318.   if(val < 0x10) ret += val;
  319.  }
  320.  return ret;
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement