Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ensure that the script is only included
- * once by defining a macro key but also
- * throw an error to dismiss it.
- */
- #if defined _moneybar_included
- #error "the money bar include has been included twice in this script."
- #endif
- #define _moneybar_included
- /*
- * create a script-based variable to hold
- * the key of the moneybar global textdraw.
- */
- static Text: moneyBarBackground;
- /*
- * create a script-based variable to hold
- * the key of every player's player
- * textdraw for the digits.
- */
- static PlayerText: moneyBarValue[MAX_PLAYERS] = { PlayerText: INVALID_TEXT_DRAW, ... };
- /*
- * create a script-based variable to hold
- * the key of every player's player
- * textdraw background color.
- */
- static moneyBarBoxColor[MAX_PLAYERS] = { -0xFF, ... };
- /*
- *
- */
- public OnGameModeInit() {
- #if defined moneyBars_OnGameModeInit
- moneyBars_OnGameModeInit();
- moneyBarBackground = TextDrawCreate(610.140563, 79.666671, "usebox");
- TextDrawLetterSize(moneyBarBackground, 0.000000, 1.887036);
- TextDrawTextSize(moneyBarBackground, 494.163970, 0.000000);
- TextDrawAlignment(moneyBarBackground, 1);
- TextDrawUseBox(moneyBarBackground, true);
- TextDrawBoxColor(moneyBarBackground, 255);
- TextDrawSetShadow(moneyBarBackground, 0);
- TextDrawSetOutline(moneyBarBackground, 0);
- TextDrawFont(moneyBarBackground, 0);
- #endif
- return 1;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit moneyBars_OnGameModeInit
- #if defined moneyBars_OnGameModeInit
- forward moneyBars_OnGameModeInit();
- #endif
- /*
- * create a function to create a money bar
- * value textdraw for a player.
- *
- * use the stock keyword to ignore the function
- * if it's not used in the main script.
- *
- * return values:
- * false - the money bar was not created, errors
- * should be shown in the console.
- *
- * true - the money bar was created, display
- * it using ShowPlayerMoneyBar(..)
- */
- stock bool:CreatePlayerMoneyBar(playerid, boxColor, textColor) {
- /*
- * ensure that the player is connected, otherwise
- * throw an error in the console to inform the
- * scripter.
- */
- if(!IsPlayerConnected(playerid)) {
- printf("[money-bars] could not create a money bar for player id %i, they are not connected!", playerid);
- return false;
- }
- /*
- * ensure that the player doesn't already have
- * a money bar.
- */
- if(moneyBarValue[playerid] != PlayerText: INVALID_TEXT_DRAW) {
- printf("[money-bars] could not create a money bar for player id %i, they already have got a money bar!", playerid);
- return false;
- }
- /*
- * we're free of errors, create the textdraw for
- * the player.
- */
- moneyBarValue[playerid] = CreatePlayerTextDraw(playerid, 498.04, 73.5, "_");
- PlayerTextDrawLetterSize(playerid, moneyBarValue[playerid], 0.433601, 2.708333);
- PlayerTextDrawAlignment(playerid, moneyBarValue[playerid], 1);
- PlayerTextDrawColor(playerid, moneyBarValue[playerid], textColor);
- PlayerTextDrawSetShadow(playerid, moneyBarValue[playerid], 0);
- PlayerTextDrawSetOutline(playerid, moneyBarValue[playerid], 1);
- PlayerTextDrawBackgroundColor(playerid, moneyBarValue[playerid], 51);
- PlayerTextDrawFont(playerid, moneyBarValue[playerid], 2);
- PlayerTextDrawSetProportional(playerid, moneyBarValue[playerid], 1);
- /*
- * ensure that the text draw was created, otherwise
- * throw an error.
- */
- if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
- printf("[money-bars] could not create a money bar for player id %i, perhaps they've reached the textdraw limit!", playerid);
- return false;
- }
- /*
- * set the player's textdraw background
- * color for further usage.
- */
- moneyBarBoxColor[playerid] = boxColor;
- /*
- * and finally, return a success.
- */
- return true;
- }
- /*
- * create a function to destroy a players
- * money bar.
- *
- * use the stock keyword to ignore the function
- * if it's not used in the main script.
- *
- * return values:
- * false - the money bar was not destroyed,
- * errors should be shown in the console.
- *
- * true - the money bar was destroyed
- */
- stock bool:DestroyPlayerMoneyBar(playerid) {
- /*
- * ensure that the player is connected, otherwise
- * throw an error in the console to inform the
- * scripter.
- */
- if(!IsPlayerConnected(playerid)) {
- printf("[money-bars] could not destroy the money bar for player id %i, they are not connected!", playerid);
- return false;
- }
- /*
- * ensure that the player has got a money
- * bar.
- */
- if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
- printf("[money-bars] could not destroy a money bar for player id %i, they haven't got a money bar!", playerid);
- return false;
- }
- /*
- * we're free of errors, destroy and hide the textdraw for
- * the player.
- */
- PlayerTextDrawHide(playerid, moneyBarValue[playerid]);
- PlayerTextDrawDestroy(playerid, moneyBarValue[playerid]);
- /*
- * reset the variable key
- */
- moneyBarValue[playerid] = PlayerText: INVALID_TEXT_DRAW;
- moneyBarBoxColor[playerid] = -0xFF;
- /*
- * and finally, return a success.
- */
- return true;
- }
- /*
- * create a function to display a players
- * money bar.
- *
- * use the stock keyword to ignore the function
- * if it's not used in the main script.
- *
- * return values:
- * false - the money bar was not displayed,
- * errors should be shown in the console.
- *
- * true - the money bar was shown
- */
- stock bool:ShowPlayerMoneyBar(playerid) {
- /*
- * ensure that the player is connected, otherwise
- * throw an error in the console to inform the
- * scripter.
- */
- if(!IsPlayerConnected(playerid)) {
- printf("[money-bars] could not show the money bar for player id %i, they are not connected!", playerid);
- return false;
- }
- /*
- * ensure that the player has got a money
- * bar.
- */
- if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
- printf("[money-bars] could not show the money bar for player id %i, they haven't got a money bar!", playerid);
- return false;
- }
- /*
- * we're free of errors, show the textdraw for the player.
- */
- PlayerTextDrawShow(playerid, moneyBarValue[playerid]);
- TextDrawColor(moneyBarBackground, moneyBarBoxColor[playerid]);
- TextDrawShowForPlayer(playerid, moneyBarBackground);
- /*
- * and finally, return a success.
- */
- return true;
- }
- /*
- * create a function to hide a players
- * money bar.
- *
- * use the stock keyword to ignore the function
- * if it's not used in the main script.
- *
- * return values:
- * false - the money bar was not displayed,
- * errors should be hidden in the console.
- *
- * true - the money bar was hidden
- */
- stock bool:HidePlayerMoneyBar(playerid) {
- /*
- * ensure that the player is connected, otherwise
- * throw an error in the console to inform the
- * scripter.
- */
- if(!IsPlayerConnected(playerid)) {
- printf("[money-bars] could not hide the money bar for player id %i, they are not connected!", playerid);
- return false;
- }
- /*
- * ensure that the player has got a money
- * bar.
- */
- if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW) {
- printf("[money-bars] could not hide the money bar for player id %i, they haven't got a money bar!", playerid);
- return false;
- }
- /*
- * we're free of errors, hide the textdraws for the player.
- */
- PlayerTextDrawHide(playerid, moneyBarValue[playerid]);
- TextDrawHideForPlayer(playerid, moneyBarBackground);
- /*
- * and finally, return a success.
- */
- return true;
- }
- /*
- * hook the OnPlayerDisconnect public function using
- * ALS 4, method 7.
- *
- * reset the player's textdraw variable when they
- * disconnect, if it is assigned a value.
- */
- public OnPlayerDisconnect(playerid, reason) {
- #if defined moneyBars_OnPlayerDisconnect
- if(moneyBarValue[playerid] != PlayerText: INVALID_TEXT_DRAW) {
- moneyBarValue[playerid] = PlayerText: INVALID_TEXT_DRAW;
- moneyBarBoxColor[playerid] = -0xFF;
- }
- moneyBars_OnPlayerDisconnect(playerid, reason);
- #endif
- return 1;
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect moneyBars_OnPlayerDisconnect
- #if defined moneyBars_OnPlayerDisconnect
- forward moneyBars_OnPlayerDisconnect(playerid, reason);
- #endif
- /*
- * hook the GivePlayerMoney function using ALS
- * 4, method 7.
- *
- * update the player's textdraw everytime their
- * money is adjusted, if they've got a textdraw
- * created.
- *
- * assign the function a stock keyword to ignore
- * the hooking if the function is never used.
- */
- stock moneyBars_GivePlayerMoney(playerid, amount) {
- GivePlayerMoney(playerid, amount);
- if(moneyBarValue[playerid] == PlayerText: INVALID_TEXT_DRAW)
- return 1;
- new digitInput[1 + 9 + 1]; // ($) (000,000,000) (\0)
- format(digitInput, sizeof digitInput, "$%08d", GetPlayerMoney(playerid));
- PlayerTextDrawSetString(playerid, moneyBarValue[playerid], digitInput);
- PlayerTextDrawShow(playerid, moneyBarValue[playerid]);
- return 1;
- }
- #if defined _ALS_GivePlayerMoney
- #undef GivePlayerMoney
- #else
- #define _ALS_GivePlayerMoney
- #endif
- #define GivePlayerMoney moneyBars_GivePlayerMoney
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement