boombox cleanup

This commit is contained in:
Lorenc Pekaj 2019-06-11 19:43:44 +10:00
parent d4744276a7
commit 32402b938c
5 changed files with 22 additions and 15 deletions

View File

@ -1027,13 +1027,13 @@ CMD:giveboombox( playerid, params[ ] )
if ( p_AdminLevel[ playerid ] < 5 ) return SendError( playerid, ADMIN_COMMAND_REJECT ); if ( p_AdminLevel[ playerid ] < 5 ) return SendError( playerid, ADMIN_COMMAND_REJECT );
else if ( sscanf( params, "u", pID ) ) return SendUsage( playerid, "/giveboombox [PLAYER_ID]" ); else if ( sscanf( params, "u", pID ) ) return SendUsage( playerid, "/giveboombox [PLAYER_ID]" );
else if ( !IsPlayerConnected( pID ) || IsPlayerNPC( pID ) ) return SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) || IsPlayerNPC( pID ) ) return SendError( playerid, "Invalid Player ID." );
else if ( p_Boombox{ pID } == true ) return SendError( playerid, "Player already has boombox in his inventory." ); else if ( GetPlayerBoombox( pID ) ) return SendError( playerid, "Player already has boombox in his inventory." );
else else
{ {
SendClientMessageFormatted( pID, -1, ""COL_PINK"[ADMIN]"COL_WHITE" %s(%d) gave you boombox.", ReturnPlayerName( playerid ), playerid ); SendClientMessageFormatted( pID, -1, ""COL_PINK"[ADMIN]"COL_WHITE" %s(%d) gave you boombox.", ReturnPlayerName( playerid ), playerid );
SendClientMessageFormatted( playerid, -1, ""COL_PINK"[ADMIN]"COL_WHITE" You have given boombox to %s(%d).", ReturnPlayerName( pID ), pID ); SendClientMessageFormatted( playerid, -1, ""COL_PINK"[ADMIN]"COL_WHITE" You have given boombox to %s(%d).", ReturnPlayerName( pID ), pID );
AddAdminLogLineFormatted( "%s(%d) has given boombox to %s(%d)", ReturnPlayerName( playerid ), playerid, ReturnPlayerName( pID ), pID ); AddAdminLogLineFormatted( "%s(%d) has given boombox to %s(%d)", ReturnPlayerName( playerid ), playerid, ReturnPlayerName( pID ), pID );
p_Boombox{ pID } = true; SetPlayerBoombox( pID, true );
} }
return 1; return 1;
} }
@ -1046,15 +1046,13 @@ CMD:removeboombox( playerid, params[ ] )
if ( p_AdminLevel[ playerid ] < 5 ) return SendError( playerid, ADMIN_COMMAND_REJECT ); if ( p_AdminLevel[ playerid ] < 5 ) return SendError( playerid, ADMIN_COMMAND_REJECT );
else if ( sscanf( params, "u", pID ) ) return SendUsage( playerid, "/removeboombox [PLAYER_ID]" ); else if ( sscanf( params, "u", pID ) ) return SendUsage( playerid, "/removeboombox [PLAYER_ID]" );
else if ( !IsPlayerConnected( pID ) || IsPlayerNPC( pID ) ) return SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) || IsPlayerNPC( pID ) ) return SendError( playerid, "Invalid Player ID." );
else if ( p_Boombox{ pID } == false ) return SendError( playerid, "Player doesn't have boombox in his inventory." ); else if ( GetPlayerBoombox( pID ) ) return SendError( playerid, "Player doesn't have boombox in his inventory." );
else else
{ {
SendClientMessageFormatted( pID, -1, ""COL_PINK"[ADMIN]"COL_WHITE" %s(%d) has removed your boombox.", ReturnPlayerName( playerid ), playerid ); SendClientMessageFormatted( pID, -1, ""COL_PINK"[ADMIN]"COL_WHITE" %s(%d) has removed your boombox.", ReturnPlayerName( playerid ), playerid );
SendClientMessageFormatted( playerid, -1, ""COL_PINK"[ADMIN]"COL_WHITE" You have removed boombox from %s(%d).", ReturnPlayerName( pID ), pID ); SendClientMessageFormatted( playerid, -1, ""COL_PINK"[ADMIN]"COL_WHITE" You have removed boombox from %s(%d).", ReturnPlayerName( pID ), pID );
AddAdminLogLineFormatted( "%s(%d) has removed boombox from %s(%d)", ReturnPlayerName( playerid ), playerid, ReturnPlayerName( pID ), pID ); AddAdminLogLineFormatted( "%s(%d) has removed boombox from %s(%d)", ReturnPlayerName( playerid ), playerid, ReturnPlayerName( pID ), pID );
p_UsingBoombox{ pID } = false; SetPlayerBoombox( pID, false );
p_Boombox{ pID } = false;
Boombox_Destroy( pID );
} }
return 1; return 1;
} }

View File

@ -20,7 +20,9 @@ enum E_BOOMBOX_DATA
}; };
static stock static stock
g_boomboxData [ MAX_PLAYERS ] [ E_BOOMBOX_DATA ] g_boomboxData [ MAX_PLAYERS ] [ E_BOOMBOX_DATA ],
bool: p_Boombox [ MAX_PLAYERS char ],
bool: p_UsingBoombox [ MAX_PLAYERS char ]
; ;
/* ** Hooks ** */ /* ** Hooks ** */
@ -134,8 +136,17 @@ stock IsPlayerUsingBoombox( playerid ) return p_UsingBoombox{ playerid };
stock GetPlayerBoombox( playerid ) return p_Boombox{ playerid }; stock GetPlayerBoombox( playerid ) return p_Boombox{ playerid };
stock SetPlayerBoombox( playerid, bool: toggle )
{
if ( ( p_Boombox{ playerid } = toggle ) == false ) {
Boombox_Destroy( playerid );
}
}
stock Boombox_Destroy( playerid ) stock Boombox_Destroy( playerid )
{ {
p_UsingBoombox{ playerid } = false;
g_boomboxData[ playerid ] [ E_X ] = 0.0; g_boomboxData[ playerid ] [ E_X ] = 0.0;
g_boomboxData[ playerid ] [ E_Y ] = 0.0; g_boomboxData[ playerid ] [ E_Y ] = 0.0;
g_boomboxData[ playerid ] [ E_Z ] = 0.0; g_boomboxData[ playerid ] [ E_Z ] = 0.0;

View File

@ -106,8 +106,8 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
} }
case SHOP_ITEM_BOOMBOX: case SHOP_ITEM_BOOMBOX:
{ {
if ( p_Boombox{ playerid } == true ) return SendError( playerid, "You have already purchased this item." ); if ( GetPlayerBoombox( playerid ) ) return SendError( playerid, "You have already purchased this item." );
p_Boombox{ playerid } = true; SetPlayerBoombox( playerid, true );
} }
} }
GivePlayerCash( playerid, -( g_shopItemData[ listitem ] [ E_PRICE ] ) ); GivePlayerCash( playerid, -( g_shopItemData[ listitem ] [ E_PRICE ] ) );
@ -198,7 +198,7 @@ stock GetShopItemAmount( playerid, id )
case SHOP_ITEM_METAL_MELTER: return p_MetalMelter[ playerid ]; case SHOP_ITEM_METAL_MELTER: return p_MetalMelter[ playerid ];
case SHOP_ITEM_WEED_SEED: return g_playerShopItems[ playerid ] [ SHOP_ITEM_WEED_SEED ]; case SHOP_ITEM_WEED_SEED: return g_playerShopItems[ playerid ] [ SHOP_ITEM_WEED_SEED ];
case SHOP_ITEM_FIREWORKS: return p_Fireworks[ playerid ]; case SHOP_ITEM_FIREWORKS: return p_Fireworks[ playerid ];
case SHOP_ITEM_BOOMBOX: return p_Boombox[ playerid ]; case SHOP_ITEM_BOOMBOX: return GetPlayerBoombox( playerid );
} }
return 0; return 0;
} }
@ -221,7 +221,7 @@ stock SetPlayerShopItemAmount( playerid, id, value )
case SHOP_ITEM_METAL_MELTER: p_MetalMelter[ playerid ] = value; case SHOP_ITEM_METAL_MELTER: p_MetalMelter[ playerid ] = value;
case SHOP_ITEM_WEED_SEED: g_playerShopItems[ playerid ] [ SHOP_ITEM_WEED_SEED ] = value; case SHOP_ITEM_WEED_SEED: g_playerShopItems[ playerid ] [ SHOP_ITEM_WEED_SEED ] = value;
case SHOP_ITEM_FIREWORKS: p_Fireworks[ playerid ] = value; case SHOP_ITEM_FIREWORKS: p_Fireworks[ playerid ] = value;
case SHOP_ITEM_BOOMBOX: p_Boombox[ playerid ] = !!value; case SHOP_ITEM_BOOMBOX: SetPlayerBoombox( playerid, !!value );
} }
return 1; return 1;
} }

View File

@ -209,9 +209,7 @@ new
p_TazingImmunity [ MAX_PLAYERS ], p_TazingImmunity [ MAX_PLAYERS ],
p_PlayerAltBind [ MAX_PLAYERS ] = { -1, ... }, p_PlayerAltBind [ MAX_PLAYERS ] = { -1, ... },
p_PlayerAltBindTick [ MAX_PLAYERS ], p_PlayerAltBindTick [ MAX_PLAYERS ],
p_AimedAtPolice [ MAX_PLAYERS ], p_AimedAtPolice [ MAX_PLAYERS ]
bool: p_UsingBoombox [ MAX_PLAYERS char ],
bool: p_Boombox [ MAX_PLAYERS char ]
; ;
/* ** Getters And Setters** */ /* ** Getters And Setters** */

View File

@ -5421,7 +5421,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
""COL_GREY"Fireworks:{FFFFFF} %d\n"\ ""COL_GREY"Fireworks:{FFFFFF} %d\n"\
""COL_GREY"Explosive Bullets:{FFFFFF} %d\n"\ ""COL_GREY"Explosive Bullets:{FFFFFF} %d\n"\
""COL_GREY"Boombox:{FFFFFF} %s\n", ""COL_GREY"Boombox:{FFFFFF} %s\n",
szLargeString, GetPlayerShopItemAmount( playerid, SHOP_ITEM_WEED_SEED ), p_Fireworks[ pID ], p_ExplosiveBullets[ pID ], p_Boombox{ pID } == true ? ( "Yes" ) : ( "No" ) ); szLargeString, GetPlayerShopItemAmount( playerid, SHOP_ITEM_WEED_SEED ), p_Fireworks[ pID ], p_ExplosiveBullets[ pID ], GetPlayerBoombox( pID ) ? ( "Yes" ) : ( "No" ) );
ShowPlayerDialog( playerid, DIALOG_STATS_REDIRECT, DIALOG_STYLE_MSGBOX, "{FFFFFF}Item Statistics", szLargeString, "Okay", "Back" ); ShowPlayerDialog( playerid, DIALOG_STATS_REDIRECT, DIALOG_STYLE_MSGBOX, "{FFFFFF}Item Statistics", szLargeString, "Okay", "Back" );
} }