From 2d1094574c81c80b88578dc872efe5591171ec63 Mon Sep 17 00:00:00 2001 From: Steven Howard Date: Tue, 9 Oct 2018 10:09:15 +0100 Subject: [PATCH] adds a confirmation dialog before selling a business --- gamemodes/irresistible/cnr/dialog_ids.pwn | 3 +- .../cnr/features/business/business.pwn | 35 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/gamemodes/irresistible/cnr/dialog_ids.pwn b/gamemodes/irresistible/cnr/dialog_ids.pwn index 13c767f..53188a2 100644 --- a/gamemodes/irresistible/cnr/dialog_ids.pwn +++ b/gamemodes/irresistible/cnr/dialog_ids.pwn @@ -209,7 +209,8 @@ #define DIALOG_IC_BUY 1199 #define DIALOG_COMPONENTS_SELL 1200 #define DIALOG_HOUSE_SELL 1201 - +#define DIALOG_BUSINESS_SELL_CONFIRM 1202 + /* ** Hooks ** */ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) { diff --git a/gamemodes/irresistible/cnr/features/business/business.pwn b/gamemodes/irresistible/cnr/features/business/business.pwn index 282e307..cd7bbea 100644 --- a/gamemodes/irresistible/cnr/features/business/business.pwn +++ b/gamemodes/irresistible/cnr/features/business/business.pwn @@ -370,17 +370,9 @@ CMD:business( playerid, params[ ] ) new iCashMoney = floatround( g_businessData[ iBusiness ] [ E_COST ] / 2 ); - p_OwnedBusinesses[ playerid ] --; - g_businessData[ iBusiness ] [ E_OWNER_ID ] = 0; + SetPVarInt( playerid, "biz_sell_id", iBusiness ); - ResetBusiness( iBusiness, .hard_reset = true ); - StopBusinessExportMission( iBusiness ); - UpdateBusinessData( iBusiness ); - UpdateBusinessTitle( iBusiness ); // No point querying (add on resale) - GivePlayerCash( playerid, iCashMoney ); - - SetPlayerPosEx( playerid, g_businessData[ iBusiness ] [ E_X ], g_businessData[ iBusiness ] [ E_Y ], g_businessData[ iBusiness ] [ E_Z ], 0 ), SetPlayerVirtualWorld( playerid, 0 ); - SendServerMessage( playerid, "You have successfully sold your business for "COL_GOLD"%s"COL_WHITE".", cash_format( iCashMoney ) ); + ShowPlayerDialog( playerid, DIALOG_BUSINESS_SELL_CONFIRM, DIALOG_STYLE_MSGBOX, ""COL_WHITE"Sell Business", sprintf( ""COL_WHITE"Are you sure you want to sell this business for "COL_GOLD"%s"COL_WHITE"?", cash_format( iCashMoney ) ), "Sell", "Cancel" ); } return 1; } @@ -592,7 +584,28 @@ function Timer_DestroyObject( objectid ) hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) { - if ( dialogid == DIALOG_BUSINESSES ) + if ( dialogid == DIALOG_BUSINESS_SELL_CONFIRM && response ) + { + new + iBusiness = GetPVarInt( playerid, "biz_sell_id" ), + iCashMoney = floatround( g_businessData[ iBusiness ] [ E_COST ] / 2 ); + + p_OwnedBusinesses[ playerid ] --; + g_businessData[ iBusiness ] [ E_OWNER_ID ] = 0; + + ResetBusiness( iBusiness, .hard_reset = true ); + StopBusinessExportMission( iBusiness ); + UpdateBusinessData( iBusiness ); + UpdateBusinessTitle( iBusiness ); // No point querying (add on resale) + GivePlayerCash( playerid, iCashMoney ); + + SetPlayerPosEx( playerid, g_businessData[ iBusiness ] [ E_X ], g_businessData[ iBusiness ] [ E_Y ], g_businessData[ iBusiness ] [ E_Z ], 0 ), SetPlayerVirtualWorld( playerid, 0 ); + SendServerMessage( playerid, "You have successfully sold your business for "COL_GOLD"%s"COL_WHITE".", cash_format( iCashMoney ) ); + + DeletePVar( playerid, "biz_sell_id" ); + return 1; + } + else if ( dialogid == DIALOG_BUSINESSES ) { if ( ! response ) return ShowPlayerSpawnMenu( playerid );