Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.47 KB | None | 0 0
  1. /*
  2.  * ensure that the script is only included
  3.  * once by defining a macro key but also
  4.  * throw an error to dismiss it.
  5.  */
  6.  
  7. #if defined _moneybar_included
  8.   #error "the money bar include has been included twice in this script."
  9. #endif
  10.  
  11. #define _moneybar_included
  12.  
  13. /*
  14.  * create a script-based variable to hold
  15.  * the key of the moneybar global textdraw.
  16.  */
  17.  
  18. static Text: moneyBarBackground;
  19.  
  20. /*
  21.  * create a script-based variable to hold
  22.  * the key of every player's player
  23.  * textdraw for the digits.
  24.  */
  25.  
  26. static PlayerText: moneyBarValue[MAX_PLAYERS] = { PlayerText: INVALID_TEXT_DRAW, ... };
  27.  
  28. /*
  29.  * create a script-based variable to hold
  30.  * the key of every player's player
  31.  * textdraw background color.
  32.  */
  33.  
  34. static moneyBarBoxColor[MAX_PLAYERS] = { -0xFF, ... };
  35.  
  36. /*
  37.  *
  38.  */
  39.  
  40. public OnGameModeInit() {
  41.   #if defined moneyBars_OnGameModeInit
  42.     moneyBars_OnGameModeInit();
  43.  
  44.     moneyBarBackground = TextDrawCreate(610.140563, 79.666671, "usebox");
  45.     TextDrawLetterSize(moneyBarBackground, 0.000000, 1.887036);
  46.     TextDrawTextSize(moneyBarBackground, 494.163970, 0.000000);
  47.     TextDrawAlignment(moneyBarBackground, 1);
  48.     TextDrawUseBox(moneyBarBackground, true);
  49.     TextDrawBoxColor(moneyBarBackground, 255);
  50.     TextDrawSetShadow(moneyBarBackground, 0);
  51.     TextDrawSetOutline(moneyBarBackground, 0);
  52.     TextDrawFont(moneyBarBackground, 0);
  53.  
  54.   #endif
  55.  
  56.   return 1;
  57. }
  58.  
  59. #if defined _ALS_OnGameModeInit
  60.   #undef OnGameModeInit
  61. #else
  62.   #define _ALS_OnGameModeInit
  63. #endif
  64.  
  65. #define OnGameModeInit moneyBars_OnGameModeInit
  66.  
  67. #if defined moneyBars_OnGameModeInit
  68.   forward moneyBars_OnGameModeInit();
  69. #endif
  70.  
  71. /*
  72.  * create a function to create a money bar
  73.  * value textdraw for a player.
  74.  *
  75.  * use the stock keyword to ignore the function
  76.  * if it's not used in the main script.
  77.  *
  78.  * return values:
  79.  *   false - the money bar was not created, errors
  80.  *           should be shown in the console.
  81.  *
  82.  *   true  - the money bar was created, display
  83.  *           it using ShowPlayerMoneyBar(..)
  84.  */
  85.  
  86. stock bool:CreatePlayerMoneyBar(playerid, boxColor, textColor) {
  87.  
  88.   /*
  89.    * ensure that the player is connected, otherwise
  90.    * throw an error in the console to inform the
  91.    * scripter.
  92.    */
  93.  
  94.   if(!IsPlayerConnected(playerid)) {
  95.     printf("[money-bars] could not create a money bar for player id %i, they are not connected!", playerid);
  96.     return false;
  97.   }
  98.  
  99.   /*
  100.    * ensure that the player doesn't already have
  101.    * a money bar.
  102.    */
  103.  
  104.   if(moneyBarValue[playerid] != PlayerText: INVALID_TEXT_DRAW) {
  105.     printf("[money-bars] could not create a money bar for player id %i, they already have got a money bar!", playerid);
  106.     return false;
  107.   }
  108.  
  109.   /*
  110.    * we're free of errors, create the textdraw for
  111.    * the player.
  112.    */
  113.  
  114.   moneyBarValue[playerid] = CreatePlayerTextDraw(playerid, 498.04, 73.5, "_");
  115.   PlayerTextDrawLetterSize(playerid, moneyBarValue[playerid], 0.433601, 2.708333);
  116.   PlayerTextDrawAlignment(playerid, moneyBarValue[playerid], 1);
  117.   PlayerTextDrawColor(playerid, moneyBarValue[playerid], textColor);
  118.   PlayerTextDrawSetShadow(playerid, moneyBarValue[playerid], 0);
  119.   PlayerTextDrawSetOutline(playerid, moneyBarValue[playerid], 1);
  120.   PlayerTextDrawBackgroundColor(playerid, moneyBarValue[playerid], 51);
  121.   PlayerTextDrawFont(playerid, moneyBarValue[playerid], 2);
  122.   PlayerTextDrawSetProportional(playerid, moneyBarValue[playerid], 1);
  123.  
  124.   /*
  125.    * ensure that the text draw was created, otherwise
  126.    * throw an error.
  127.    */
  128.  
  129.   if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
  130.     printf("[money-bars] could not create a money bar for player id %i, perhaps they've reached the textdraw limit!", playerid);
  131.     return false;
  132.   }
  133.  
  134.   /*
  135.    * set the player's textdraw background
  136.    * color for further usage.
  137.    */
  138.  
  139.   moneyBarBoxColor[playerid] = boxColor;
  140.  
  141.   /*
  142.    * and finally, return a success.
  143.    */
  144.  
  145.   return true;
  146. }
  147.  
  148. /*
  149.  * create a function to destroy a players
  150.  * money bar.
  151.  *
  152.  * use the stock keyword to ignore the function
  153.  * if it's not used in the main script.
  154.  *
  155.  * return values:
  156.  *   false - the money bar was not destroyed,
  157.  *           errors should be shown in the console.
  158.  *
  159.  *   true  - the money bar was destroyed
  160.  */
  161.  
  162. stock bool:DestroyPlayerMoneyBar(playerid) {
  163.  
  164.   /*
  165.    * ensure that the player is connected, otherwise
  166.    * throw an error in the console to inform the
  167.    * scripter.
  168.    */
  169.  
  170.   if(!IsPlayerConnected(playerid)) {
  171.     printf("[money-bars] could not destroy the money bar for player id %i, they are not connected!", playerid);
  172.     return false;
  173.   }
  174.  
  175.   /*
  176.    * ensure that the player has got a money
  177.    * bar.
  178.    */
  179.  
  180.   if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
  181.     printf("[money-bars] could not destroy a money bar for player id %i, they haven't got a money bar!", playerid);
  182.     return false;
  183.   }
  184.  
  185.   /*
  186.    * we're free of errors, destroy and hide the textdraw for
  187.    * the player.
  188.    */
  189.  
  190.   PlayerTextDrawHide(playerid, moneyBarValue[playerid]);
  191.   PlayerTextDrawDestroy(playerid, moneyBarValue[playerid]);
  192.  
  193.   /*
  194.    * reset the variable key
  195.    */
  196.  
  197.   moneyBarValue[playerid] = PlayerText: INVALID_TEXT_DRAW;
  198.   moneyBarBoxColor[playerid] = -0xFF;
  199.  
  200.   /*
  201.    * and finally, return a success.
  202.    */
  203.  
  204.   return true;
  205. }
  206.  
  207. /*
  208.  * create a function to display a players
  209.  * money bar.
  210.  *
  211.  * use the stock keyword to ignore the function
  212.  * if it's not used in the main script.
  213.  *
  214.  * return values:
  215.  *   false - the money bar was not displayed,
  216.  *           errors should be shown in the console.
  217.  *
  218.  *   true  - the money bar was shown
  219.  */
  220.  
  221. stock bool:ShowPlayerMoneyBar(playerid) {
  222.  
  223.   /*
  224.    * ensure that the player is connected, otherwise
  225.    * throw an error in the console to inform the
  226.    * scripter.
  227.    */
  228.  
  229.   if(!IsPlayerConnected(playerid)) {
  230.     printf("[money-bars] could not show the money bar for player id %i, they are not connected!", playerid);
  231.     return false;
  232.   }
  233.  
  234.   /*
  235.    * ensure that the player has got a money
  236.    * bar.
  237.    */
  238.  
  239.   if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
  240.     printf("[money-bars] could not show the money bar for player id %i, they haven't got a money bar!", playerid);
  241.     return false;
  242.   }
  243.  
  244.   /*
  245.    * we're free of errors, show the textdraw for the player.
  246.    */
  247.  
  248.   PlayerTextDrawShow(playerid, moneyBarValue[playerid]);
  249.  
  250.   TextDrawColor(moneyBarBackground, moneyBarBoxColor[playerid]);
  251.   TextDrawShowForPlayer(playerid, moneyBarBackground);
  252.  
  253.   /*
  254.    * and finally, return a success.
  255.    */
  256.  
  257.   return true;
  258. }
  259.  
  260. /*
  261.  * create a function to hide a players
  262.  * money bar.
  263.  *
  264.  * use the stock keyword to ignore the function
  265.  * if it's not used in the main script.
  266.  *
  267.  * return values:
  268.  *   false - the money bar was not displayed,
  269.  *           errors should be hidden in the console.
  270.  *
  271.  *   true  - the money bar was hidden
  272.  */
  273.  
  274. stock bool:HidePlayerMoneyBar(playerid) {
  275.  
  276.   /*
  277.    * ensure that the player is connected, otherwise
  278.    * throw an error in the console to inform the
  279.    * scripter.
  280.    */
  281.  
  282.   if(!IsPlayerConnected(playerid)) {
  283.     printf("[money-bars] could not hide the money bar for player id %i, they are not connected!", playerid);
  284.     return false;
  285.   }
  286.  
  287.   /*
  288.    * ensure that the player has got a money
  289.    * bar.
  290.    */
  291.  
  292.   if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
  293.     printf("[money-bars] could not hide the money bar for player id %i, they haven't got a money bar!", playerid);
  294.     return false;
  295.   }
  296.  
  297.   /*
  298.    * we're free of errors, hide the textdraws for the player.
  299.    */
  300.  
  301.   PlayerTextDrawHide(playerid, moneyBarValue[playerid]);
  302.  
  303.   TextDrawHideForPlayer(playerid, moneyBarBackground);
  304.  
  305.   /*
  306.    * and finally, return a success.
  307.    */
  308.  
  309.   return true;
  310. }
  311.  
  312. /*
  313.  * hook the OnPlayerDisconnect public function using
  314.  * ALS 4, method 7.
  315.  *
  316.  * reset the player's textdraw variable when they
  317.  * disconnect, if it is assigned a value.
  318.  */
  319.  
  320. public OnPlayerDisconnect(playerid, reason) {
  321.  
  322.   #if defined moneyBars_OnPlayerDisconnect
  323.  
  324.     if(moneyBarValue[playerid] != PlayerText: INVALID_TEXT_DRAW) {
  325.       moneyBarValue[playerid] = PlayerText: INVALID_TEXT_DRAW;
  326.       moneyBarBoxColor[playerid] = -0xFF;
  327.     }
  328.  
  329.     moneyBars_OnPlayerDisconnect(playerid, reason);
  330.  
  331.   #endif
  332.  
  333.   return 1;
  334. }
  335.  
  336. #if defined _ALS_OnPlayerDisconnect
  337.   #undef OnPlayerDisconnect
  338. #else
  339.   #define _ALS_OnPlayerDisconnect
  340. #endif
  341.  
  342. #define OnPlayerDisconnect moneyBars_OnPlayerDisconnect
  343.  
  344. #if defined moneyBars_OnPlayerDisconnect
  345.   forward moneyBars_OnPlayerDisconnect(playerid, reason);
  346. #endif
  347.  
  348. /*
  349.  * hook the GivePlayerMoney function using ALS
  350.  * 4, method 7.
  351.  *
  352.  * update the player's textdraw everytime their
  353.  * money is adjusted, if they've got a textdraw
  354.  * created.
  355.  *
  356.  * assign the function a stock keyword to ignore
  357.  * the hooking if the function is never used.
  358.  */
  359.  
  360. stock moneyBars_GivePlayerMoney(playerid, amount) {
  361.  
  362.   GivePlayerMoney(playerid, amount);
  363.  
  364.   if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW)
  365.     return 1;
  366.  
  367.   new digitInput[1 + 9 + 1]; // ($) (000,000,000) (\0)
  368.   format(digitInput, sizeof digitInput, "$%08d", GetPlayerMoney(playerid));
  369.  
  370.   PlayerTextDrawSetString(playerid, moneyBarValue[playerid], digitInput);
  371.   PlayerTextDrawShow(playerid, moneyBarValue[playerid]);
  372.  
  373.   return 1;
  374. }
  375.  
  376. #if defined _ALS_GivePlayerMoney
  377.   #undef GivePlayerMoney
  378. #else
  379.   #define _ALS_GivePlayerMoney
  380. #endif
  381.  
  382. #define GivePlayerMoney moneyBars_GivePlayerMoney
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement