Guest User

Untitled

a guest
Aug 10th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.30 KB | None | 0 0
  1. /*
  2. * Progress bar editor by Emmet_
  3. * Made for Southclaw's Progress Bars v2.
  4. *
  5. * Features:
  6. * - Ability to adjust all settings, including direction, color, and size.
  7. * - Uses SQLite for better organization.
  8. * - Supports multiple progress bars.
  9. */
  10.  
  11. #include <a_samp>
  12. #include <progress2>
  13. #include <zcmd>
  14.  
  15. #define COLOR_INFO (0xFFDD00FF)
  16. #define COLOR_ERROR (0xFF5030FF)
  17.  
  18. #define PROJECT_DB_PATH "projects.db" // Path of the file that stores all of the project names.
  19. #define PROJECT_EXPORT_PATH "%s.pwn" // Path of the export file location.
  20. #define ADMIN_RESTRICTION false // Restrict the progress bar editor to RCON admins only?
  21. #define MAX_PROJECT_NAME 24 // Maximum amount of characters in a project name.
  22.  
  23. #define DIALOG_MAIN_MENU 18300
  24. #define DIALOG_LOAD_PROJECT 18301
  25. #define DIALOG_LOAD_CUSTOM 18302
  26. #define DIALOG_DELETE_PROJECT 18303
  27. #define DIALOG_DELETE_CUSTOM 18304
  28. #define DIALOG_DELETE_CONFIRM 18305
  29. #define DIALOG_CREATE_PROJECT 18306
  30. #define DIALOG_PROJECT_MENU 18307
  31. #define DIALOG_BAR_MENU 18308
  32. #define DIALOG_COLOR_INPUT 18309
  33. #define DIALOG_DIRECTION_LIST 18310
  34. #define DIALOG_MAX_VALUE 18311
  35.  
  36. #define LIST_TYPE_LOAD 1
  37. #define LIST_TYPE_DELETE 2
  38.  
  39. #define UPDATE_BAR_POSITION 1
  40. #define UPDATE_BAR_SIZE 2
  41. #define UPDATE_BAR_DIRECTION 3
  42. #define UPDATE_BAR_MAX_VALUE 4
  43. #define UPDATE_BAR_COLOR 5
  44.  
  45. #define EDIT_TYPE_POSITION 1
  46. #define EDIT_TYPE_SIZE 2
  47.  
  48. main( ) { }
  49.  
  50. enum e_ProjectData
  51. {
  52. // Indicates if a project is active.
  53. e_ProjectActive,
  54.  
  55. // Name of the project.
  56. e_ProjectName[MAX_PROJECT_NAME],
  57.  
  58. // Name of the project to delete.
  59. e_ProjectToDelete[MAX_PROJECT_NAME],
  60.  
  61. // Editing type. (1) Position (2) Size
  62. e_EditType,
  63.  
  64. // Index of the selected progress bar, relative to "ProjectBars"
  65. e_SelectedBar
  66. };
  67.  
  68. new Project[MAX_PLAYERS][e_ProjectData];
  69.  
  70. enum e_ProjectBars
  71. {
  72. // Database ID of the progress bar's record.
  73. e_DatabaseID,
  74.  
  75. // ID of the progress bar.
  76. PlayerBar:e_ProgressBarID
  77. };
  78.  
  79. new ProjectBars[MAX_PLAYERS][MAX_PLAYER_BARS][e_ProjectBars];
  80.  
  81. new DB:g_iDatabase;
  82.  
  83. new DBResult:g_iDatabaseResult;
  84.  
  85. public OnFilterScriptInit()
  86. {
  87. for (new i = 0; i < MAX_PLAYERS; i ++)
  88. {
  89. if (IsPlayerConnected(i)) ResetProjectData(i);
  90. }
  91. g_iDatabase = db_open(PROJECT_DB_PATH);
  92.  
  93. db_query(g_iDatabase, "CREATE TABLE IF NOT EXISTS `projects` (name VARCHAR("#MAX_PROJECT_NAME"), creator VARCHAR(24))");
  94. db_query(g_iDatabase, "CREATE TABLE IF NOT EXISTS `bars` (bar_id INTEGER PRIMARY KEY AUTOINCREMENT, project VARCHAR("#MAX_PROJECT_NAME"), x_pos FLOAT, y_pos FLOAT, width FLOAT, height FLOAT, max_value FLOAT, color INTEGER, direction INTEGER, FOREIGN KEY (project) REFERENCES projects(name))");
  95.  
  96. print("\nProgress Bar Editor loaded!");
  97. print("Use the /bar command to begin editing.\n");
  98. return 1;
  99. }
  100.  
  101. public OnFilterScriptExit()
  102. {
  103. for (new i = 0; i < MAX_PLAYERS; i ++)
  104. {
  105. if (Project[i][e_ProjectActive])
  106. {
  107. Project_Close(i);
  108. ShowPlayerDialog(i, -1, DIALOG_STYLE_LIST, " ", " ", " ", "");
  109. }
  110. }
  111. db_close(g_iDatabase);
  112.  
  113. print("Progress Bar Editor unloaded!");
  114. return 1;
  115. }
  116.  
  117. public OnPlayerConnect(playerid)
  118. {
  119. ResetProjectData(playerid);
  120. return 1;
  121. }
  122.  
  123. public OnPlayerDisconnect(playerid, reason)
  124. {
  125. if (Project[playerid][e_ProjectActive])
  126. {
  127. Project_Close(playerid);
  128. }
  129. return 1;
  130. }
  131.  
  132. public OnPlayerSpawn(playerid)
  133. {
  134. #if ADMIN_RESTRICTION == true
  135. if (IsPlayerAdmin(playerid)) SendClientMessage(playerid, COLOR_INFO, "Use the /bar command to begin editing!");
  136. #elseif ADMIN_RESTRICTION == false
  137. SendClientMessage(playerid, COLOR_INFO, "Use the /bar command to begin editing!");
  138. #endif
  139.  
  140. return 1;
  141. }
  142.  
  143. public OnPlayerUpdate(playerid)
  144. {
  145. new
  146. keys,
  147. ud,
  148. lr;
  149.  
  150. if (Project[playerid][e_ProjectActive] && Project[playerid][e_SelectedBar] != -1)
  151. {
  152. new
  153. PlayerBar:barid = ProjectBars[playerid][Project[playerid][e_SelectedBar]][e_ProgressBarID],
  154. string[128],
  155. Float:x,
  156. Float:y;
  157.  
  158. GetPlayerKeys(playerid, keys, ud, lr);
  159.  
  160. GetPlayerProgressBarPos(playerid, barid, x, y);
  161.  
  162. if (keys & KEY_SECONDARY_ATTACK)
  163. {
  164. switch (Project[playerid][e_EditType])
  165. {
  166. case EDIT_TYPE_POSITION:
  167. {
  168. UpdateProgressBarData(playerid, Project[playerid][e_SelectedBar], UPDATE_BAR_POSITION);
  169. SetTimerEx("ShowProgressBarMenu", 300, false, "dd", playerid, _:barid);
  170.  
  171. format(string, sizeof(string), "You have set the position of bar #%d.", Project[playerid][e_SelectedBar]);
  172. SendClientMessage(playerid, COLOR_INFO, string);
  173. }
  174. case EDIT_TYPE_SIZE:
  175. {
  176. UpdateProgressBarData(playerid, Project[playerid][e_SelectedBar], UPDATE_BAR_SIZE);
  177. SetTimerEx("ShowProgressBarMenu", 300, false, "dd", playerid, _:barid);
  178.  
  179. format(string, sizeof(string), "You have set the size of bar #%d.", Project[playerid][e_SelectedBar]);
  180. SendClientMessage(playerid, COLOR_INFO, string);
  181. }
  182. }
  183. TogglePlayerControllable(playerid, 1);
  184. SetPlayerProgressBarValue(playerid, barid, 50.0);
  185.  
  186. Project[playerid][e_EditType] = 0;
  187. }
  188. if (ud == KEY_UP)
  189. {
  190. if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  191. {
  192. if (keys == KEY_SPRINT)
  193. SetPlayerProgressBarPos(playerid, barid, x, y - 5.0);
  194. else
  195. SetPlayerProgressBarPos(playerid, barid, x, y - 1.0);
  196. }
  197. else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  198. {
  199. if (keys == KEY_SPRINT)
  200. SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) - 1.0);
  201. else
  202. SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) - 0.5);
  203. }
  204. }
  205. if (ud == KEY_DOWN)
  206. {
  207. if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  208. {
  209. if (keys == KEY_SPRINT)
  210. SetPlayerProgressBarPos(playerid, barid, x, y + 5.0);
  211. else
  212. SetPlayerProgressBarPos(playerid, barid, x, y + 1.0);
  213. }
  214. else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  215. {
  216. if (keys == KEY_SPRINT)
  217. SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) + 1.0);
  218. else
  219. SetPlayerProgressBarHeight(playerid, barid, GetPlayerProgressBarHeight(playerid, barid) + 0.5);
  220. }
  221. }
  222. if (lr == KEY_LEFT)
  223. {
  224. if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  225. {
  226. if (keys == KEY_SPRINT)
  227. SetPlayerProgressBarPos(playerid, barid, x - 5.0, y);
  228. else
  229. SetPlayerProgressBarPos(playerid, barid, x - 1.0, y);
  230. }
  231. else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  232. {
  233. if (keys == KEY_SPRINT)
  234. SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) - 1.0);
  235. else
  236. SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) - 0.5);
  237. }
  238. }
  239. if (lr == KEY_RIGHT)
  240. {
  241. if (Project[playerid][e_EditType] == EDIT_TYPE_POSITION)
  242. {
  243. if (keys == KEY_SPRINT)
  244. SetPlayerProgressBarPos(playerid, barid, x + 5.0, y);
  245. else
  246. SetPlayerProgressBarPos(playerid, barid, x + 1.0, y);
  247. }
  248. else if (Project[playerid][e_EditType] == EDIT_TYPE_SIZE)
  249. {
  250. if (keys == KEY_SPRINT)
  251. SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) + 1.0);
  252. else
  253. SetPlayerProgressBarWidth(playerid, barid, GetPlayerProgressBarWidth(playerid, barid) + 0.5);
  254. }
  255. }
  256. }
  257. return 1;
  258. }
  259.  
  260. /*
  261. Function:
  262. ResetProjectData
  263. Parameters:
  264. playerid - The player to reset the data for.
  265. Returns:
  266. No significant value.
  267. */
  268.  
  269. stock ResetProjectData(playerid)
  270. {
  271. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  272. {
  273. ProjectBars[playerid][i][e_DatabaseID] = 0;
  274. ProjectBars[playerid][i][e_ProgressBarID] = INVALID_PLAYER_BAR_ID;
  275. }
  276. Project[playerid][e_ProjectActive] = 0;
  277. Project[playerid][e_ProjectName] = 0;
  278. Project[playerid][e_EditType] = 0;
  279. Project[playerid][e_SelectedBar] = -1;
  280. }
  281.  
  282. /*
  283. Function:
  284. Project_ExportPath
  285. Parameters:
  286. name[] - Name of the project.
  287. Returns:
  288. The export file path for the specified project name.
  289. */
  290.  
  291. stock Project_ExportPath(name[])
  292. {
  293. new
  294. path[MAX_PROJECT_NAME + 14];
  295.  
  296. format(path, sizeof(path), PROJECT_EXPORT_PATH, name);
  297. return path;
  298. }
  299.  
  300. /*
  301. Function:
  302. Project_Exists
  303. Parameters:
  304. name[] - Name of the project.
  305. Returns:
  306. Returns 1 if the project file exists.
  307. */
  308.  
  309. stock Project_Exists(name[])
  310. {
  311. new
  312. string[128],
  313. rows;
  314.  
  315. format(string, sizeof(string), "SELECT `name` FROM `projects` WHERE `name` = '%s'", name);
  316.  
  317. g_iDatabaseResult = db_query(g_iDatabase, string);
  318.  
  319. rows = db_num_rows(g_iDatabaseResult);
  320.  
  321. db_free_result(g_iDatabaseResult);
  322.  
  323. return (rows > 0);
  324. }
  325.  
  326. /*
  327. Function:
  328. Project_Remove
  329. Parameters:
  330. name[] - Name of the project.
  331. Returns:
  332. Returns 1 if the project was removed.
  333. */
  334.  
  335. stock Project_Remove(name[])
  336. {
  337. if (Project_Exists(name))
  338. {
  339. new
  340. string[128];
  341.  
  342. format(string, sizeof(string), "DELETE FROM projects WHERE name = '%s'", name);
  343. db_query(g_iDatabase, string);
  344.  
  345. format(string, sizeof(string), "DELETE FROM bars WHERE project = '%s'", name);
  346. db_query(g_iDatabase, string);
  347.  
  348. return 1;
  349. }
  350. return 0;
  351. }
  352.  
  353. /*
  354. Function:
  355. Project_IsOpen
  356. Parameters:
  357. name[] - Name of the project.
  358. Returns:
  359. Returns 1 if the project is opened by another player.
  360. */
  361.  
  362. stock Project_IsOpen(name[])
  363. {
  364. for (new i = 0; i < MAX_PLAYERS; i ++)
  365. {
  366. if (!IsPlayerConnected(i)) continue;
  367.  
  368. if (Project[i][e_ProjectActive] && !strcmp(Project[i][e_ProjectName], name, true))
  369. {
  370. return 1;
  371. }
  372. }
  373. return 0;
  374. }
  375.  
  376. /*
  377. Function:
  378. Project_Open
  379. Parameters:
  380. playerid - The player that is editing the project.
  381. name[] - Name of the project.
  382. Returns:
  383. 1: if the project was successfully opened.
  384. 0: if another player is already editing that project.
  385. */
  386.  
  387. stock Project_Open(playerid, name[])
  388. {
  389. new
  390. str[128],
  391. rows
  392. ;
  393. if (!Project_Exists(name))
  394. {
  395. // If it doesn't exist in the database, then add it in there.
  396. GetPlayerName(playerid, str, sizeof(str));
  397.  
  398. format(str, sizeof(str), "INSERT INTO projects (name, creator) VALUES('%s', '%s')", name, str);
  399. db_query(g_iDatabase, str);
  400. }
  401. else if (Project_IsOpen(name)) // Another player is already editing this project.
  402. {
  403. return 0;
  404. }
  405.  
  406. new
  407. Float:x,
  408. Float:y,
  409. Float:width,
  410. Float:height,
  411. Float:maxvalue,
  412. color,
  413. direction
  414. ;
  415.  
  416. format(str, sizeof(str), "SELECT * FROM `bars` WHERE `project` = '%s'", name);
  417.  
  418. g_iDatabaseResult = db_query(g_iDatabase, str);
  419.  
  420. rows = db_num_rows(g_iDatabaseResult);
  421.  
  422. for (new i = 0; i < rows; i ++)
  423. {
  424. if (i >= MAX_PLAYER_BARS)
  425. {
  426. printf("Warning: Project \"%s\" contains %d bars; limit is %d.", name, rows, MAX_PLAYER_BARS);
  427. break;
  428. }
  429. db_get_field_assoc(g_iDatabaseResult, "bar_id", str, sizeof(str));
  430. ProjectBars[playerid][i][e_DatabaseID] = strval(str);
  431.  
  432. db_get_field_assoc(g_iDatabaseResult, "x_pos", str, sizeof(str));
  433. x = floatstr(str);
  434.  
  435. db_get_field_assoc(g_iDatabaseResult, "y_pos", str, sizeof(str));
  436. y = floatstr(str);
  437.  
  438. db_get_field_assoc(g_iDatabaseResult, "width", str, sizeof(str));
  439. width = floatstr(str);
  440.  
  441. db_get_field_assoc(g_iDatabaseResult, "height", str, sizeof(str));
  442. height = floatstr(str);
  443.  
  444. db_get_field_assoc(g_iDatabaseResult, "max_value", str, sizeof(str));
  445. maxvalue = floatstr(str);
  446.  
  447. db_get_field_assoc(g_iDatabaseResult, "color", str, sizeof(str));
  448. color = strval(str);
  449.  
  450. db_get_field_assoc(g_iDatabaseResult, "direction", str, sizeof(str));
  451. direction = strval(str);
  452.  
  453. ProjectBars[playerid][i][e_ProgressBarID] = CreatePlayerProgressBar(playerid, x, y, width, height, color, maxvalue, direction);
  454.  
  455. SetPlayerProgressBarValue(playerid, ProjectBars[playerid][i][e_ProgressBarID], 50.0);
  456. ShowPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  457.  
  458. db_next_row(g_iDatabaseResult);
  459. }
  460. db_free_result(g_iDatabaseResult);
  461.  
  462. Project[playerid][e_ProjectActive] = 1;
  463.  
  464. return strcat(Project[playerid][e_ProjectName], name, MAX_PROJECT_NAME);
  465. }
  466.  
  467. /*
  468. Function:
  469. ShowProjectMainMenu
  470. Parameters:
  471. playerid - The player to show the main menu for.
  472. Returns:
  473. 1: if the menu was successfully shown.
  474. 0: if the player is not editing any projects.
  475. */
  476.  
  477. stock ShowProjectMainMenu(playerid)
  478. {
  479. if (Project[playerid][e_ProjectActive])
  480. {
  481. ShowProjectMenu(playerid);
  482. }
  483. else
  484. {
  485. ShowPlayerDialog(playerid, DIALOG_MAIN_MENU, DIALOG_STYLE_LIST, "Main Menu", "Create project...\nLoad project...\nDelete project...", "Select", "Cancel");
  486. }
  487. return 1;
  488. }
  489.  
  490. /*
  491. Function:
  492. ShowProjectMenu
  493. Parameters:
  494. playerid - The player to show the menu for.
  495. Returns:
  496. 1: if the menu was successfully shown.
  497. 0: if the player is not editing any projects.
  498. */
  499.  
  500. forward ShowProjectMenu(playerid);
  501. public ShowProjectMenu(playerid)
  502. {
  503. if (Project[playerid][e_ProjectActive])
  504. {
  505. new
  506. string[1024];
  507.  
  508. format(string, sizeof(string), "Create progress bar...\nExport project...\nClose project...");
  509.  
  510. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  511. {
  512. if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
  513. continue;
  514.  
  515. switch (GetPlayerProgressBarDirection(playerid, ProjectBars[playerid][i][e_ProgressBarID]))
  516. {
  517. case BAR_DIRECTION_LEFT:
  518. format(string, sizeof(string), "%s\n- Bar #%d - Direction: Left", string, i);
  519. case BAR_DIRECTION_RIGHT:
  520. format(string, sizeof(string), "%s\n- Bar #%d - Direction: Right", string, i);
  521. case BAR_DIRECTION_UP:
  522. format(string, sizeof(string), "%s\n- Bar #%d - Direction: Up", string, i);
  523. case BAR_DIRECTION_DOWN:
  524. format(string, sizeof(string), "%s\n- Bar #%d - Direction: Down", string, i);
  525. }
  526. }
  527. ShowPlayerDialog(playerid, DIALOG_PROJECT_MENU, DIALOG_STYLE_LIST, "Project Menu", string, "Select", "Cancel");
  528. return 1;
  529. }
  530. return 0;
  531. }
  532.  
  533. /*
  534. Function:
  535. Project_ShowList
  536. Parameters:
  537. playerid - The player to show the list to.
  538. type - The type of the list.
  539. Returns:
  540. 1: if the list was successfully shown.
  541. 0: if there wasn't anything to display.
  542. */
  543.  
  544. stock Project_ShowList(playerid, type)
  545. {
  546. new
  547. string[MAX_PROJECT_NAME + 3],
  548. buffer[1024],
  549. rows;
  550.  
  551. strcat(buffer, "Custom name...\n");
  552.  
  553. g_iDatabaseResult = db_query(g_iDatabase, "SELECT `name` FROM projects");
  554.  
  555. rows = db_num_rows(g_iDatabaseResult);
  556.  
  557. for (new i = 0; i < rows; i ++)
  558. {
  559. db_get_field(g_iDatabaseResult, 0, string, sizeof(string));
  560. db_next_row(g_iDatabaseResult);
  561.  
  562. strcat(buffer, string);
  563. strcat(buffer, "\n");
  564. }
  565. db_free_result(g_iDatabaseResult);
  566.  
  567. if (isnull(buffer))
  568. {
  569. return 0;
  570. }
  571. switch (type)
  572. {
  573. case LIST_TYPE_LOAD:
  574. {
  575. ShowPlayerDialog(playerid, DIALOG_LOAD_PROJECT, DIALOG_STYLE_LIST, "Load project...", buffer, "Load", "Cancel");
  576. }
  577. case LIST_TYPE_DELETE:
  578. {
  579. ShowPlayerDialog(playerid, DIALOG_DELETE_PROJECT, DIALOG_STYLE_LIST, "Delete project...", buffer, "Delete", "Cancel");
  580. }
  581. }
  582. return 1;
  583. }
  584.  
  585. /*
  586. Function:
  587. Project_Close
  588. Parameters:
  589. playerid - The player to close the project for.
  590. Returns:
  591. 1: if the project was closed.
  592. 0: if there wasn't any project loaded.
  593. */
  594.  
  595. stock Project_Close(playerid)
  596. {
  597. if (Project[playerid][e_ProjectActive])
  598. {
  599. if (Project[playerid][e_EditType] > 0)
  600. {
  601. TogglePlayerControllable(playerid, 1);
  602. }
  603. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  604. {
  605. if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID)
  606. {
  607. HidePlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  608. DestroyPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  609. }
  610. }
  611. ResetProjectData(playerid);
  612. return 1;
  613. }
  614. return 0;
  615. }
  616.  
  617. /*
  618. Function:
  619. ShowProgressBarMenu
  620. Parameters:
  621. playerid - The player to show the menu to.
  622. PlayerBar:barid - The ID of the player bar.
  623. Returns:
  624. 1: if the menu was shown.
  625. 0: if the player bar doesn't exist.
  626. */
  627.  
  628. forward ShowProgressBarMenu(playerid, PlayerBar:barid);
  629. public ShowProgressBarMenu(playerid, PlayerBar:barid)
  630. {
  631. if (Project[playerid][e_ProjectActive])
  632. {
  633. new
  634. string[512],
  635. title[24];
  636.  
  637. Project[playerid][e_SelectedBar] = GetProgressBarInternalID(playerid, barid);
  638. format(title, sizeof(title), "Bar #%d", Project[playerid][e_SelectedBar]);
  639.  
  640. format(string, sizeof(string), "Change position\nChange size\nChange color\nChange direction (%s)\nChange max value (%.4f)\nDuplicate bar\nDelete this bar", GetDirectionFromType(GetPlayerProgressBarDirection(playerid, barid)), GetPlayerProgressBarMaxValue(playerid, barid));
  641. ShowPlayerDialog(playerid, DIALOG_BAR_MENU, DIALOG_STYLE_LIST, title, string, "Select", "Back");
  642. }
  643. return 1;
  644. }
  645.  
  646. /*
  647. Function:
  648. GetProgressBarInternalID
  649. Parameters:
  650. playerid - The player ID of the progress bar.
  651. PlayerBar:barid - The ID of the progress bar.
  652. Returns:
  653. The index of "ProjectBars" that contains the progress bar ID.
  654. */
  655.  
  656. stock GetProgressBarInternalID(playerid, PlayerBar:barid)
  657. {
  658. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  659. {
  660. if (ProjectBars[playerid][i][e_ProgressBarID] == barid)
  661. {
  662. return i;
  663. }
  664. }
  665. return -1;
  666. }
  667.  
  668. /*
  669. Function:
  670. DuplicateProgresssBar
  671. Parameters:
  672. playerid - The player ID to duplicate the progress bar for.
  673. index - The index of the bar, relative to "ProjectBars".
  674. Returns:
  675. The index relative to "ProjectBars" that contains the new progress bar ID.
  676. */
  677.  
  678. stock DuplicateProgressBar(playerid, index)
  679. {
  680. if (Project[playerid][e_ProjectActive])
  681. {
  682. new
  683. PlayerBar:barid = ProjectBars[playerid][index][e_ProgressBarID],
  684. Float:x,
  685. Float:y;
  686.  
  687. GetPlayerProgressBarPos(playerid, barid, x, y);
  688. return AddBarToProject(playerid, x, y, GetPlayerProgressBarWidth(playerid, barid), GetPlayerProgressBarHeight(playerid, barid), GetPlayerProgressBarMaxValue(playerid, barid), GetPlayerProgressBarColour(playerid, barid), GetPlayerProgressBarDirection(playerid, barid));
  689. }
  690. return -1;
  691. }
  692.  
  693. /*
  694. Function:
  695. AddBarToProject
  696. Parameters:
  697. playerid - The player ID to add the bar for.
  698. ... - Parameters. Check "CreatePlayerProgressBar" for more details.
  699. Returns:
  700. The index relative to "ProjectBars" that contains the new progress bar ID.
  701. */
  702.  
  703. stock AddBarToProject(playerid, Float:x = 280.0, Float:y = 200.0, Float:width = 55.5, Float:height = 3.2, Float:max_value = 100.0, color = -1429936641, direction = BAR_DIRECTION_RIGHT)
  704. {
  705. new
  706. string[160];
  707.  
  708. if (!Project[playerid][e_ProjectActive])
  709. {
  710. return -1;
  711. }
  712. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  713. {
  714. if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID) continue;
  715.  
  716. format(string, sizeof(string), "INSERT INTO `bars` VALUES(null, '%s', %.6f, %.6f, %.6f, %.6f, %.4f, %d, %d)", Project[playerid][e_ProjectName], x, y, width, height, max_value, color, direction);
  717. db_query(g_iDatabase, string);
  718.  
  719. ProjectBars[playerid][i][e_ProgressBarID] = CreatePlayerProgressBar(playerid, x, y, width, height, color, max_value, direction);
  720. ProjectBars[playerid][i][e_DatabaseID] = db_last_insert_id(g_iDatabase, "bars");
  721.  
  722. SetPlayerProgressBarValue(playerid, ProjectBars[playerid][i][e_ProgressBarID], 50.0);
  723. ShowPlayerProgressBar(playerid, ProjectBars[playerid][i][e_ProgressBarID]);
  724. return i;
  725. }
  726. return -1;
  727. }
  728.  
  729. /*
  730. Function:
  731. UpdateProgressBarData
  732. Parameters:
  733. playerid - The player ID to add the bar for.
  734. index - Index of the progress bar, relative to "ProjectBars".
  735. type - Type of data to update in the database.
  736. Returns:
  737. Returns 1 if the data was successfully updated.
  738. */
  739.  
  740. stock UpdateProgressBarData(playerid, index, type)
  741. {
  742. new
  743. PlayerBar:barid = ProjectBars[playerid][index][e_ProgressBarID],
  744. string[128];
  745.  
  746. if (IsValidPlayerProgressBar(playerid, barid))
  747. {
  748. switch (type)
  749. {
  750. case UPDATE_BAR_POSITION:
  751. {
  752. new
  753. Float:x,
  754. Float:y;
  755.  
  756. GetPlayerProgressBarPos(playerid, barid, x, y);
  757.  
  758. format(string, sizeof(string), "UPDATE `bars` SET `x_pos` = %.6f, `y_pos` = %.6f WHERE `bar_id` = %d", x, y, ProjectBars[playerid][index][e_DatabaseID]);
  759. db_query(g_iDatabase, string);
  760. }
  761. case UPDATE_BAR_SIZE:
  762. {
  763. format(string, sizeof(string), "UPDATE `bars` SET `width` = %.6f, `height` = %.6f WHERE `bar_id` = %d", GetPlayerProgressBarWidth(playerid, barid), GetPlayerProgressBarHeight(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  764. db_query(g_iDatabase, string);
  765. }
  766. case UPDATE_BAR_DIRECTION:
  767. {
  768. format(string, sizeof(string), "UPDATE `bars` SET `direction` = %d WHERE `bar_id` = %d", GetPlayerProgressBarDirection(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  769. db_query(g_iDatabase, string);
  770. }
  771. case UPDATE_BAR_MAX_VALUE:
  772. {
  773. format(string, sizeof(string), "UPDATE `bars` SET `max_value` = %.6f WHERE `bar_id` = %d", GetPlayerProgressBarMaxValue(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  774. db_query(g_iDatabase, string);
  775. }
  776. case UPDATE_BAR_COLOR:
  777. {
  778. format(string, sizeof(string), "UPDATE `bars` SET `color` = %d WHERE `bar_id` = %d", GetPlayerProgressBarColour(playerid, barid), ProjectBars[playerid][index][e_DatabaseID]);
  779. db_query(g_iDatabase, string);
  780. }
  781. }
  782. return 1;
  783. }
  784. return 0;
  785. }
  786.  
  787. stock GetDirectionFromType(direction)
  788. {
  789. new
  790. str[6];
  791.  
  792. if (direction == BAR_DIRECTION_LEFT)
  793. str = "Left";
  794. else if (direction == BAR_DIRECTION_RIGHT)
  795. str = "Right";
  796. else if (direction == BAR_DIRECTION_UP)
  797. str = "Up";
  798. else if (direction == BAR_DIRECTION_DOWN)
  799. str = "Down";
  800.  
  801. return str;
  802. }
  803.  
  804. stock StrToHex(str[])
  805. {
  806. // Credits to Y_Less.
  807.  
  808. new
  809. i,
  810. value;
  811.  
  812. if (str[0] == '0' && (str [1] == 'x' || str [1] == 'X'))
  813. i = 2;
  814.  
  815. while (str[i])
  816. {
  817. value <<= 4;
  818.  
  819. switch (str[i])
  820. {
  821. case '0'..'9':
  822. value |= str [i] - '0';
  823.  
  824. case 'A'..'F':
  825. value |= str [i] - 'A' + 10;
  826.  
  827. case 'a'..'f':
  828. value |= str [i] - 'a' + 10;
  829.  
  830. default:
  831. return 0;
  832. }
  833. ++ i;
  834. }
  835. return value;
  836. }
  837.  
  838. stock db_last_insert_id(DB:database, const table[])
  839. {
  840. new
  841. DBResult:result,
  842. string[64];
  843.  
  844. format(string, sizeof(string), "SELECT last_insert_rowid() FROM %s", table);
  845.  
  846. result = db_query(database, string);
  847.  
  848. db_get_field(result, 0, string, sizeof(string));
  849.  
  850. db_free_result(result);
  851.  
  852. return strval(string);
  853. }
  854.  
  855. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  856. {
  857. new
  858. string[255],
  859. PlayerBar:barid,
  860. index = -1;
  861.  
  862. if (Project[playerid][e_ProjectActive] && (index = Project[playerid][e_SelectedBar]) != -1)
  863. {
  864. barid = ProjectBars[playerid][Project[playerid][e_SelectedBar]][e_ProgressBarID];
  865. }
  866.  
  867. switch (dialogid)
  868. {
  869. case DIALOG_MAIN_MENU:
  870. {
  871. if (response)
  872. {
  873. switch (listitem)
  874. {
  875. case 0: // Create new project
  876. {
  877. ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "Please enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  878. }
  879. case 1: // Load existing project
  880. {
  881. Project_ShowList(playerid, LIST_TYPE_LOAD);
  882. }
  883. case 2: // Delete project
  884. {
  885. new
  886. success = Project_ShowList(playerid, LIST_TYPE_DELETE);
  887.  
  888. if (!success) return SendClientMessage(playerid, COLOR_ERROR, "There are no projects to delete.");
  889. }
  890. }
  891. }
  892. }
  893. case DIALOG_CREATE_PROJECT:
  894. {
  895. if (response)
  896. {
  897. if (isnull(inputtext))
  898. {
  899. return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "Please enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  900. }
  901. else if (strlen(inputtext) > 32)
  902. {
  903. return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "Please enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  904. }
  905. else if (Project_Exists(inputtext))
  906. {
  907. return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "The specified project name is already in use!\n\nPlease enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  908. }
  909. else
  910. {
  911. for (new i = 0, l = strlen(inputtext); i < l; i ++)
  912. {
  913. switch (inputtext[i])
  914. {
  915. case '\\', '/', ':', '*', '"', '?', '<', '>', '|', '\'':
  916. {
  917. return ShowPlayerDialog(playerid, DIALOG_CREATE_PROJECT, DIALOG_STYLE_INPUT, "Create new project...", "You have entered invalid characters. Please remove them and try again.\n\nPlease enter the name of your new project below:\nThe name must contain only letters, numbers and spaces.", "Submit", "Back");
  918. }
  919. }
  920. }
  921. format(string, sizeof(string), "You have created project \"%s\".", inputtext);
  922. SendClientMessage(playerid, COLOR_INFO, string);
  923.  
  924. Project_Open(playerid, inputtext);
  925. ShowProjectMenu(playerid);
  926. }
  927. }
  928. else
  929. {
  930. ShowProjectMainMenu(playerid);
  931. }
  932. }
  933. case DIALOG_LOAD_PROJECT:
  934. {
  935. if (response)
  936. {
  937. if (!listitem) // Custom name...
  938. {
  939. ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to load:", "Submit", "Back");
  940. }
  941. else
  942. {
  943. new
  944. pos = -1;
  945.  
  946. // strip extra characters
  947. if ((pos = strfind(inputtext, "\r")) != -1) strdel(inputtext, pos, pos + 1);
  948. if ((pos = strfind(inputtext, "\n")) != -1) strdel(inputtext, pos, pos + 1);
  949.  
  950. format(string, sizeof(string), "You have loaded project \"%s\".", inputtext);
  951. SendClientMessage(playerid, COLOR_INFO, string);
  952.  
  953. Project_Open(playerid, inputtext);
  954. ShowProjectMenu(playerid);
  955. }
  956. }
  957. else
  958. {
  959. ShowProjectMainMenu(playerid);
  960. }
  961. }
  962. case DIALOG_LOAD_CUSTOM:
  963. {
  964. if (response)
  965. {
  966. if (isnull(inputtext) || strlen(inputtext) > 32)
  967. {
  968. ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to load:", "Submit", "Back");
  969. }
  970. else if (!Project_Exists(inputtext))
  971. {
  972. ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project name doesn't exist.\n\nPlease enter the name of the project you wish to load:", "Submit", "Back");
  973. }
  974. else if (Project_IsOpen(inputtext))
  975. {
  976. ShowPlayerDialog(playerid, DIALOG_LOAD_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project is being edited by another player.\n\nPlease enter the name of the project you wish to load:", "Submit", "Back");
  977. }
  978. else
  979. {
  980. format(string, sizeof(string), "You have loaded project \"%s\".", inputtext);
  981. SendClientMessage(playerid, COLOR_INFO, string);
  982.  
  983. Project_Open(playerid, inputtext);
  984. ShowProjectMenu(playerid);
  985. }
  986. }
  987. else
  988. {
  989. Project_ShowList(playerid, LIST_TYPE_LOAD);
  990. }
  991. }
  992. case DIALOG_DELETE_PROJECT:
  993. {
  994. if (response)
  995. {
  996. if (!listitem) // Custom name...
  997. {
  998. ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to delete:", "Submit", "Back");
  999. }
  1000. else
  1001. {
  1002. new
  1003. pos = -1;
  1004.  
  1005. // strip extra characters
  1006. if ((pos = strfind(inputtext, "\r")) != -1) strdel(inputtext, pos, pos + 1);
  1007. if ((pos = strfind(inputtext, "\n")) != -1) strdel(inputtext, pos, pos + 1);
  1008.  
  1009. Project[playerid][e_ProjectToDelete] = 0;
  1010. strcat(Project[playerid][e_ProjectToDelete], inputtext, MAX_PROJECT_NAME);
  1011.  
  1012. format(string, sizeof(string), "You are about to delete project \"%s\"!\nYou cannot recover a project once it is deleted.", inputtext);
  1013. ShowPlayerDialog(playerid, DIALOG_DELETE_CONFIRM, DIALOG_STYLE_MSGBOX, "Delete project...", string, "Yes", "No");
  1014. }
  1015. }
  1016. else
  1017. {
  1018. ShowProjectMainMenu(playerid);
  1019. }
  1020. }
  1021. case DIALOG_DELETE_CUSTOM:
  1022. {
  1023. if (response)
  1024. {
  1025. if (isnull(inputtext) || strlen(inputtext) > 32)
  1026. {
  1027. ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "Please enter the name of the project you wish to delete:", "Submit", "Back");
  1028. }
  1029. else if (!Project_Exists(inputtext))
  1030. {
  1031. ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project name doesn't exist.\n\nPlease enter the name of the project you wish to delete:", "Submit", "Back");
  1032. }
  1033. else if (Project_IsOpen(inputtext))
  1034. {
  1035. ShowPlayerDialog(playerid, DIALOG_DELETE_CUSTOM, DIALOG_STYLE_INPUT, "Custom name...", "The specified project is being edited by another player.\n\nPlease enter the name of the project you wish to delete:", "Submit", "Back");
  1036. }
  1037. else
  1038. {
  1039. Project[playerid][e_ProjectToDelete] = 0;
  1040. strcat(Project[playerid][e_ProjectToDelete], inputtext, MAX_PROJECT_NAME);
  1041.  
  1042. format(string, sizeof(string), "You are about to delete project \"%s\"!\nYou cannot recover a project once it is deleted.", inputtext);
  1043. ShowPlayerDialog(playerid, DIALOG_DELETE_CONFIRM, DIALOG_STYLE_MSGBOX, "Delete project...", string, "Yes", "No");
  1044. }
  1045. }
  1046. else
  1047. {
  1048. Project_ShowList(playerid, LIST_TYPE_LOAD);
  1049. }
  1050. }
  1051. case DIALOG_DELETE_CONFIRM:
  1052. {
  1053. if (response)
  1054. {
  1055. Project_Remove(Project[playerid][e_ProjectToDelete]);
  1056.  
  1057. format(string, sizeof(string), "You have deleted project \"%s\".", Project[playerid][e_ProjectToDelete]);
  1058. SendClientMessage(playerid, COLOR_INFO, string);
  1059.  
  1060. Project[playerid][e_ProjectToDelete] = 0;
  1061. }
  1062. else
  1063. {
  1064. ShowProjectMainMenu(playerid);
  1065. }
  1066. }
  1067. case DIALOG_PROJECT_MENU:
  1068. {
  1069. if (response)
  1070. {
  1071. switch (listitem)
  1072. {
  1073. case 0: // Create progress bar...
  1074. {
  1075. new
  1076. id = AddBarToProject(playerid);
  1077.  
  1078. if (id != -1)
  1079. {
  1080. format(string, sizeof(string), "You have created progress bar #%d.", id);
  1081. SendClientMessage(playerid, COLOR_INFO, string);
  1082.  
  1083. ShowProjectMenu(playerid);
  1084. return 1;
  1085. }
  1086. else
  1087. {
  1088. SendClientMessage(playerid, COLOR_ERROR, "Please adjust the \"MAX_PLAYER_BARS\" setting in \"progress2.inc\" to add more progress bars.");
  1089. ShowProjectMenu(playerid);
  1090. }
  1091. }
  1092. case 1: // Export project...
  1093. {
  1094. new
  1095. File:file = fopen(Project_ExportPath(Project[playerid][e_ProjectName]), io_write),
  1096. Float:x,
  1097. Float:y,
  1098. date[6]
  1099. ;
  1100.  
  1101. if (file)
  1102. {
  1103. getdate(date[0], date[1], date[2]);
  1104. gettime(date[3], date[4], date[5]);
  1105.  
  1106. format(string, sizeof(string), "/*\r\n * Project Name: %s\r\n * Date: %02d/%02d/%d @ %02d:%02d:%02d\r\n\r\n * The code below is to be used with the Progress Bar V2 include.\r\n *\r\n*/\r\n\r\n", Project[playerid][e_ProjectName], date[2], date[1], date[0], date[3], date[4], date[5]);
  1107. fwrite(file, string);
  1108.  
  1109. fwrite(file, "#include <a_samp>\r\n#include <progress2>\r\n\r\n");
  1110.  
  1111. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  1112. {
  1113. if (ProjectBars[playerid][i][e_ProgressBarID] != INVALID_PLAYER_BAR_ID)
  1114. {
  1115. format(string, sizeof(string), "new PlayerBar:Bar%d[MAX_PLAYERS];\r\n", i);
  1116. fwrite(file, string);
  1117. }
  1118. }
  1119. fwrite(file, "\r\npublic OnPlayerConnect(playerid)\r\n{\r\n");
  1120.  
  1121. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  1122. {
  1123. if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
  1124. continue;
  1125.  
  1126. GetPlayerProgressBarPos(playerid, ProjectBars[playerid][i][e_ProgressBarID], x, y);
  1127.  
  1128. format(string, sizeof(string), " Bar%d[playerid] = CreatePlayerProgressBar(playerid, %.6f, %.6f, %.6f, %.6f, %d, %.4f, %d);\r\n",
  1129. i,
  1130. x,
  1131. y,
  1132. GetPlayerProgressBarWidth(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1133. GetPlayerProgressBarHeight(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1134. GetPlayerProgressBarColour(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1135. GetPlayerProgressBarMaxValue(playerid, ProjectBars[playerid][i][e_ProgressBarID]),
  1136. GetPlayerProgressBarDirection(playerid, ProjectBars[playerid][i][e_ProgressBarID])
  1137. );
  1138.  
  1139. fwrite(file, string);
  1140. }
  1141. fwrite(file, "\r\n return 1;\r\n}\r\n\r\npublic OnPlayerSpawn(playerid)\r\n{\r\n");
  1142.  
  1143. for (new i = 0; i < MAX_PLAYER_BARS; i ++)
  1144. {
  1145. if (ProjectBars[playerid][i][e_ProgressBarID] == INVALID_PLAYER_BAR_ID)
  1146. continue;
  1147.  
  1148. format(string, sizeof(string), " ShowPlayerProgressBar(playerid, Bar%d[playerid]);\r\n", i);
  1149. fwrite(file, string);
  1150. }
  1151. fwrite(file, "\r\n return 1;\r\n}\r\n");
  1152. fclose(file);
  1153.  
  1154. format(string, sizeof(string), "Project has been exported to \"%s\".", Project_ExportPath(Project[playerid][e_ProjectName]));
  1155. SendClientMessage(playerid, COLOR_INFO, string);
  1156.  
  1157. ShowProjectMenu(playerid);
  1158. }
  1159. }
  1160. case 2: // Close project...
  1161. {
  1162. format(string, sizeof(string), "You have closed project \"%s\".", Project[playerid][e_ProjectName]);
  1163. SendClientMessage(playerid, COLOR_INFO, string);
  1164.  
  1165. Project_Close(playerid);
  1166. ShowProjectMainMenu(playerid);
  1167. }
  1168. default: // Player selected a bar
  1169. {
  1170. index = strval(inputtext[7]);
  1171.  
  1172. if (!IsValidPlayerProgressBar(playerid, ProjectBars[playerid][index][e_ProgressBarID]))
  1173. {
  1174. SendClientMessage(playerid, COLOR_ERROR, "Whoops! There seems to be a problem here... Please contact Emmet.");
  1175. }
  1176. else
  1177. {
  1178. ShowProgressBarMenu(playerid, ProjectBars[playerid][index][e_ProgressBarID]);
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }
  1184. case DIALOG_BAR_MENU:
  1185. {
  1186. if (response)
  1187. {
  1188. switch (listitem)
  1189. {
  1190. case 0: // Change position
  1191. {
  1192. Project[playerid][e_EditType] = EDIT_TYPE_POSITION;
  1193. TogglePlayerControllable(playerid, 0);
  1194.  
  1195. format(string, sizeof(string), "You are changing bar #%d's position. Use the arrow keys to move the bar and press Enter when done.", index);
  1196. SendClientMessage(playerid, COLOR_INFO, string);
  1197. }
  1198. case 1: // Change size
  1199. {
  1200. Project[playerid][e_EditType] = EDIT_TYPE_SIZE;
  1201. TogglePlayerControllable(playerid, 0);
  1202.  
  1203. format(string, sizeof(string), "You are changing bar #%d's size. Use the arrow keys to adjust the size and press Enter when done.", index);
  1204. SendClientMessage(playerid, COLOR_INFO, string);
  1205. }
  1206. case 2: // Change color
  1207. {
  1208. ShowPlayerDialog(playerid, DIALOG_COLOR_INPUT, DIALOG_STYLE_INPUT, "Change color", "Please enter the new color for this progress bar below:\nYou must enter a hexadecimal value. The hex color for white is 0xFFFFFFFF.", "Submit", "Back");
  1209. }
  1210. case 3: // Change direction
  1211. {
  1212. ShowPlayerDialog(playerid, DIALOG_DIRECTION_LIST, DIALOG_STYLE_LIST, "Change direction", "Right\nLeft\nUp\nDown", "Select", "Back");
  1213. }
  1214. case 4: // Change max value
  1215. {
  1216. format(string, sizeof(string), "Please enter the new maximum value for this bar below (current: %.4f):", GetPlayerProgressBarMaxValue(playerid, barid));
  1217. ShowPlayerDialog(playerid, DIALOG_MAX_VALUE, DIALOG_STYLE_INPUT, "Change max value", string, "Submit", "Back");
  1218. }
  1219. case 5: // Duplicate bar
  1220. {
  1221. new
  1222. id = DuplicateProgressBar(playerid, index);
  1223.  
  1224. if (id != -1)
  1225. {
  1226. format(string, sizeof(string), "You have duplicated progress bar #%d (new ID: #%d).", index, id);
  1227. SendClientMessage(playerid, COLOR_INFO, string);
  1228.  
  1229. ShowProjectMenu(playerid);
  1230. }
  1231. else
  1232. {
  1233. SendClientMessage(playerid, COLOR_ERROR, "Please adjust the \"MAX_PLAYER_BARS\" setting in \"progress2.inc\" to add more progress bars.");
  1234. ShowProjectMenu(playerid);
  1235. }
  1236. }
  1237. case 6: // Delete this bar
  1238. {
  1239. format(string, sizeof(string), "DELETE FROM `bars` WHERE `bar_id` = %d", ProjectBars[playerid][index][e_DatabaseID]);
  1240. db_query(g_iDatabase, string);
  1241.  
  1242. HidePlayerProgressBar(playerid, barid);
  1243. DestroyPlayerProgressBar(playerid, barid);
  1244.  
  1245. format(string, sizeof(string), "You have deleted progress bar #%d.", index);
  1246. SendClientMessage(playerid, COLOR_INFO, string);
  1247.  
  1248. ProjectBars[playerid][index][e_ProgressBarID] = INVALID_PLAYER_BAR_ID;
  1249. ProjectBars[playerid][index][e_DatabaseID] = 0;
  1250.  
  1251. Project[playerid][e_SelectedBar] = -1;
  1252.  
  1253. return ShowProjectMenu(playerid);
  1254. }
  1255. }
  1256. }
  1257. else
  1258. {
  1259. ShowProjectMenu(playerid);
  1260. }
  1261. }
  1262. case DIALOG_COLOR_INPUT:
  1263. {
  1264. if (response)
  1265. {
  1266. if (isnull(inputtext) || (strlen(inputtext) != 6 && strlen(inputtext) != 8))
  1267. {
  1268. ShowPlayerDialog(playerid, DIALOG_COLOR_INPUT, DIALOG_STYLE_INPUT, "Change color", "Please enter the new color for this progress bar below:\nYou must enter a hexadecimal value. The hex color for white is 0xFFFFFFFF.", "Submit", "Back");
  1269. }
  1270. else
  1271. {
  1272. new color = StrToHex(inputtext);
  1273.  
  1274. SetPlayerProgressBarColour(playerid, barid, color);
  1275.  
  1276. ShowPlayerProgressBar(playerid, barid);
  1277. UpdateProgressBarData(playerid, index, UPDATE_BAR_COLOR);
  1278.  
  1279. format(string, sizeof(string), "You have set bar #%d's color to {%06x}%s.", index, color >>> 8, inputtext);
  1280. SendClientMessage(playerid, COLOR_INFO, string);
  1281.  
  1282. ShowProgressBarMenu(playerid, barid);
  1283. }
  1284. }
  1285. else
  1286. {
  1287. ShowProgressBarMenu(playerid, barid);
  1288. }
  1289. }
  1290. case DIALOG_DIRECTION_LIST:
  1291. {
  1292. if (response)
  1293. {
  1294. SetPlayerProgressBarDirection(playerid, barid, listitem);
  1295. UpdateProgressBarData(playerid, index, UPDATE_BAR_DIRECTION);
  1296.  
  1297. format(string, sizeof(string), "You have changed bar #%d's direction to %s.", index, GetDirectionFromType(listitem));
  1298. SendClientMessage(playerid, COLOR_INFO, string);
  1299.  
  1300. ShowProgressBarMenu(playerid, barid);
  1301. }
  1302. else
  1303. {
  1304. ShowProgressBarMenu(playerid, barid);
  1305. }
  1306. }
  1307. case DIALOG_MAX_VALUE:
  1308. {
  1309. if (response)
  1310. {
  1311. if (isnull(inputtext))
  1312. {
  1313. format(string, sizeof(string), "Please enter the new maximum value for this bar below (current: %.4f):", GetPlayerProgressBarMaxValue(playerid, barid));
  1314. ShowPlayerDialog(playerid, DIALOG_MAX_VALUE, DIALOG_STYLE_INPUT, "Change max value", string, "Submit", "Back");
  1315. }
  1316. else
  1317. {
  1318. new
  1319. Float:max_value = floatstr(inputtext);
  1320.  
  1321. SetPlayerProgressBarMaxValue(playerid, barid, max_value);
  1322. UpdateProgressBarData(playerid, index, UPDATE_BAR_MAX_VALUE);
  1323.  
  1324. format(string, sizeof(string), "You have changed bar #%d's maximum value to %.4f.", index, max_value);
  1325. SendClientMessage(playerid, COLOR_INFO, string);
  1326.  
  1327. ShowProgressBarMenu(playerid, barid);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. ShowProgressBarMenu(playerid, barid);
  1333. }
  1334. }
  1335. }
  1336. return 0;
  1337. }
  1338.  
  1339. CMD:bar(playerid, params[])
  1340. {
  1341. #if ADMIN_RESTRICTION == true
  1342. if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "You must be an RCON admin to use the editor.");
  1343. #endif
  1344.  
  1345. if (Project[playerid][e_EditType] > 0)
  1346. {
  1347. return SendClientMessage(playerid, COLOR_ERROR, "You must finish editing before you can use this command.");
  1348. }
  1349. ShowProjectMainMenu(playerid);
  1350. return 1;
  1351. }
Advertisement
Add Comment
Please, Sign In to add comment