diff --git a/gamemodes/irresistible/cnr/features/fires.pwn b/gamemodes/irresistible/cnr/features/fires.pwn index 5496838..3912a01 100644 --- a/gamemodes/irresistible/cnr/features/fires.pwn +++ b/gamemodes/irresistible/cnr/features/fires.pwn @@ -94,7 +94,7 @@ hook OnPlayerUpdateEx( playerid ) GivePlayerScore( playerid, 2 ); //GivePlayerExperience( playerid, E_FIREMAN ); GivePlayerCash( playerid, FIRE_EXTINGUISH_PAYOUT ); - StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, FIRE_EXTINGUISH_PAYOUT, 0.01 ); + StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, FIRE_EXTINGUISH_PAYOUT, 0.05 ); HouseFire_Remove( i ); } return 1; diff --git a/gamemodes/irresistible/cnr/features/stocks/stocks.pwn b/gamemodes/irresistible/cnr/features/stocks/stocks.pwn index 6183017..6eec951 100644 --- a/gamemodes/irresistible/cnr/features/stocks/stocks.pwn +++ b/gamemodes/irresistible/cnr/features/stocks/stocks.pwn @@ -19,6 +19,8 @@ #define DIALOG_PLAYER_STOCKS 8924 #define DIALOG_STOCK_MARKET_BUY 8925 #define DIALOG_STOCK_MARKET_SELL 8926 +#define DIALOG_STOCK_MARKET_OPTIONS 8927 +#define DIALOG_STOCK_MARKET_HOLDERS 8928 #define STOCK_MM_USER_ID ( 0 ) @@ -125,14 +127,44 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) { if ( x == listitem ) { + ShowPlayerStockMarketOptions( playerid, s ); SetPVarInt( playerid, "stockmarket_selection", s ); - StockMarket_ShowBuySlip( playerid, s ); break; } x ++; } return 1; } + else if ( dialogid == DIALOG_STOCK_MARKET_HOLDERS && response ) + { + new + stockid = GetPVarInt( playerid, "stockmarket_selection" ); + + if ( ! Iter_Contains( stockmarkets, stockid ) ) { + return SendError( playerid, "There was an error with the stock you were seeing, please try again." ); + } + return ShowPlayerStockMarketOptions( playerid, stockid ); + } + else if ( dialogid == DIALOG_STOCK_MARKET_OPTIONS ) + { + if ( ! response ) { + return ShowPlayerStockMarket( playerid ); + } + + new + stockid = GetPVarInt( playerid, "stockmarket_selection" ); + + if ( ! Iter_Contains( stockmarkets, stockid ) ) { + return SendError( playerid, "There was an error with the stock you were seeing, please try again." ); + } + + switch ( listitem ) + { + case 0: StockMarket_ShowBuySlip( playerid, stockid ); + case 1: mysql_tquery( dbHandle, sprintf( "SELECT s.*, u.`NAME`, u.`ONLINE` FROM `STOCK_OWNERS` s LEFT JOIN `USERS` u ON s.`USER_ID` = u.`ID` WHERE s.`STOCK_ID`=%d ORDER BY s.`SHARES` DESC", stockid ), "StockMarket_ShowShareholders", "dd", playerid, stockid ); + } + return 1; + } else if ( dialogid == DIALOG_PLAYER_STOCKS && response ) { new @@ -153,7 +185,7 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) else if ( dialogid == DIALOG_STOCK_MARKET_SELL ) { if ( ! response ) { - return cmd_shares( playerid, "" ), 1; + return ShowPlayerStockMarket( playerid ); } new @@ -206,7 +238,7 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) } else { - return cmd_stockmarkets( playerid, "" ); + return ShowPlayerStockMarket( playerid ); } } return 1; @@ -527,33 +559,50 @@ thread StockMarket_OnCancelOrder( playerid ) } } +thread StockMarket_ShowShareholders( playerid, stockid ) +{ + new rows = cache_get_row_count( ); + + // format dialog title + szLargeString = ""COL_WHITE"User\t"COL_WHITE"Shares\t"COL_WHITE"Percentage (%)\n"; + + // track the shares that are held by players + new Float: out_standing_shares = g_stockMarketData[ stockid ] [ E_MAX_SHARES ]; + + // show all the shareholders + if ( rows ) + { + new + player_name[ 24 ]; + + for ( new row = 0; row < rows; row ++ ) + { + cache_get_field_content( row, "NAME", player_name ); + + new is_online = cache_get_field_content_int( row, "ONLINE" ); + new Float: shares = cache_get_field_content_float( row, "SHARES" ); + + out_standing_shares -= shares; + format( szLargeString, sizeof ( szLargeString ), "%s%s%s\t%s\t%s%%\n", szLargeString, is_online ? COL_GREEN : COL_WHITE, player_name, number_format( shares, .decimals = 0 ), number_format( shares / g_stockMarketData[ stockid ] [ E_MAX_SHARES ] * 100.0, .decimals = 3 ) ); + } + } + + // tell players the shares tied up in sell orders + if ( out_standing_shares > 0.0 ) { + format( szLargeString, sizeof ( szLargeString ), "%s{666666}Held In Sell Orders\t{666666}%s\t{666666}%s%%\n", szLargeString, number_format( out_standing_shares, .decimals = 0 ), number_format( out_standing_shares / g_stockMarketData[ stockid ] [ E_MAX_SHARES ] * 100.0, .decimals = 3 ) ); + } + + // format dialog + ShowPlayerDialog( playerid, DIALOG_STOCK_MARKET_HOLDERS, DIALOG_STYLE_TABLIST_HEADERS, ""COL_WHITE"Stock Market - Shareholders", szLargeString, "Back", "Close" ); + return 1; +} + /* ** Command ** */ CMD:stocks( playerid, params[ ] ) return cmd_stockmarkets( playerid, params ); CMD:stockmarkets( playerid, params[ ] ) { - szLargeString = ""COL_WHITE"Stock\t"COL_WHITE"Max Shares\t"COL_WHITE"Dividend Per Share ($)\t"COL_WHITE"Price ($)\n"; - - foreach ( new s : stockmarkets ) - { - new Float: price_change = ( ( g_stockMarketReportData[ s ] [ 1 ] [ E_PRICE ] / g_stockMarketReportData[ s ] [ 2 ] [ E_PRICE ] ) - 1.0 ) * 100.0; - new Float: payout = g_stockMarketReportData[ s ] [ 0 ] [ E_POOL ] / g_stockMarketData[ s ] [ E_MAX_SHARES ]; - - format( - szLargeString, sizeof( szLargeString ), - "%s%s (%s)\t%s\t"COL_GREEN"%s\t%s%s (%s%%)\n", - szLargeString, - g_stockMarketData[ s ] [ E_NAME ], - g_stockMarketData[ s ] [ E_SYMBOL ], - number_format( g_stockMarketData[ s ] [ E_MAX_SHARES ], .decimals = 0 ), - cash_format( payout, .decimals = 2 ), - price_change >= 0.0 ? COL_GREEN : COL_RED, - cash_format( g_stockMarketReportData[ s ] [ 1 ] [ E_PRICE ], .decimals = 2 ), - number_format( price_change, .decimals = 2, .prefix = ( price_change >= 0.0 ? '+' : '\0' ) ) - ); - } - SendServerMessage( playerid, "The stock market will payout dividends in %s.", secondstotime( GetServerVariableInt( "stock_report_time" ) - GetServerTime( ) ) ); - return ShowPlayerDialog( playerid, DIALOG_STOCK_MARKET, DIALOG_STYLE_TABLIST_HEADERS, ""COL_WHITE"Stock Market", szLargeString, "Buy", "Close" ); + return ShowPlayerStockMarket( playerid ); } CMD:shares( playerid, params[ ] ) @@ -671,6 +720,38 @@ static stock StockMarket_ShowSellSlip( playerid, stockid ) return 1; } +static stock ShowPlayerStockMarket( playerid ) +{ + szLargeString = ""COL_WHITE"Stock\t"COL_WHITE"Max Shares\t"COL_WHITE"Dividend Per Share ($)\t"COL_WHITE"Price ($)\n"; + + foreach ( new s : stockmarkets ) + { + new Float: price_change = ( ( g_stockMarketReportData[ s ] [ 1 ] [ E_PRICE ] / g_stockMarketReportData[ s ] [ 2 ] [ E_PRICE ] ) - 1.0 ) * 100.0; + new Float: payout = g_stockMarketReportData[ s ] [ 0 ] [ E_POOL ] / g_stockMarketData[ s ] [ E_MAX_SHARES ]; + + format( + szLargeString, sizeof( szLargeString ), + "%s%s (%s)\t%s\t"COL_GREEN"%s\t%s%s (%s%%)\n", + szLargeString, + g_stockMarketData[ s ] [ E_NAME ], + g_stockMarketData[ s ] [ E_SYMBOL ], + number_format( g_stockMarketData[ s ] [ E_MAX_SHARES ], .decimals = 0 ), + cash_format( payout, .decimals = 2 ), + price_change >= 0.0 ? COL_GREEN : COL_RED, + cash_format( g_stockMarketReportData[ s ] [ 1 ] [ E_PRICE ], .decimals = 2 ), + number_format( price_change, .decimals = 2, .prefix = ( price_change >= 0.0 ? '+' : '\0' ) ) + ); + } + return ShowPlayerDialog( playerid, DIALOG_STOCK_MARKET, DIALOG_STYLE_TABLIST_HEADERS, ""COL_WHITE"Stock Market", szLargeString, "Buy", "Close" ); +} + +static stock ShowPlayerStockMarketOptions( playerid, stockid ) +{ + format( szBigString, sizeof( szBigString ), "Buy shares\t"COL_GREEN"%s\nView shareholders\t"COL_GREY">>>", cash_format( g_stockMarketReportData[ stockid ] [ 1 ] [ E_PRICE ], .decimals = 2 ) ); + ShowPlayerDialog( playerid, DIALOG_STOCK_MARKET_OPTIONS, DIALOG_STYLE_TABLIST, sprintf( ""COL_WHITE"Stock Market - %s", g_stockMarketData[ stockid ] [ E_NAME ] ), szBigString, "Select", "Back" ); + return 1; +} + /* DROP TABLE `STOCK_REPORTS`; CREATE TABLE IF NOT EXISTS `STOCK_REPORTS` ( diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index d9479e6..9b2ac79 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -2538,11 +2538,11 @@ public OnPlayerDeath( playerid, killerid, reason ) if ( p_WantedLevel[ playerid ] > 5 ) { static const killedWords[ ] [ ] = { { "murked" }, { "killed" }, { "ended" }, { "slain" }, { "massacred" }, { "destroyed" }, { "screwed" } }; - new cashEarned = ( p_WantedLevel[ playerid ] < MAX_WANTED_LVL ? p_WantedLevel[ playerid ] : MAX_WANTED_LVL ) * ( reason == 38 ? 170 : 270 ); + new cashEarned = ( p_WantedLevel[ playerid ] < MAX_WANTED_LVL ? p_WantedLevel[ playerid ] : MAX_WANTED_LVL ) * ( reason == 38 || reason == 51 ? 160 : 270 ); GivePlayerCash( killerid, cashEarned ); GivePlayerScore( killerid, 2 ); GivePlayerExperience( killerid, E_POLICE, 0.5 ); - StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, cashEarned, 0.01 ); + StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, cashEarned, 0.05 ); if ( cashEarned > 20000 ) printf("[police kill] %s -> %s - %s", ReturnPlayerName( killerid ), ReturnPlayerName( playerid ), cash_format( cashEarned ) ); // 8hska7082bmahu if ( p_WantedLevel[ playerid ] > 64 ) SendGlobalMessage( -1, ""COL_GOLD"[POLICE KILL]{FFFFFF} %s(%d) has %s %s(%d) who had a wanted level of %d!", ReturnPlayerName( killerid ), killerid, killedWords[ random( sizeof( killedWords ) ) ], ReturnPlayerName( playerid ), playerid, p_WantedLevel[ playerid ] ); SendClientMessageFormatted( killerid, -1, ""COL_GOLD"[ACHIEVE]{FFFFFF} You have killed %s(%d) with a wanted level of %d; earning you "COL_GOLD"%s{FFFFFF} and 2 score!", ReturnPlayerName( playerid ), playerid, p_WantedLevel[ playerid ], cash_format( cashEarned ) ); @@ -5127,7 +5127,7 @@ CMD:acceptbail( playerid, params[ ] ) GivePlayerCash( playerid, -equa ); GivePlayerCash( p_BailOfferer[ playerid ], cashEarned ); - StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, cashEarned, 0.01 ); + StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, cashEarned, 0.05 ); SendClientMessageFormatted( p_BailOfferer[ playerid ], -1, ""COL_GREEN"[BAIL]"COL_WHITE" %s(%d) has paid bail. You have earned "COL_GOLD"%s"COL_WHITE" from his bail.", ReturnPlayerName( playerid ), playerid, cash_format( cashEarned ) ); p_BailOfferer[ playerid ] = INVALID_PLAYER_ID; SendServerMessage( playerid, "You have paid for your bail. You are now free!" ); @@ -13382,7 +13382,7 @@ stock ArrestPlayer( victimid, playerid ) GivePlayerScore( playerid, 2 ); GivePlayerExperience( playerid, E_POLICE ); GivePlayerCash( playerid, totalCash ); - StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, totalCash, 0.01 ); + StockMarket_UpdateEarnings( E_STOCK_GOVERNMENT, totalCash, 0.05 ); if ( totalCash > 20000 ) printf("[police arrest] %s -> %s - %s", ReturnPlayerName( playerid ), ReturnPlayerName( victimid ), cash_format( totalCash ) ); // 8hska7082bmahu SendClientMessageFormatted( playerid, -1, ""COL_GREEN"[ACHIEVE]{FFFFFF} You have earned "COL_GOLD"%s{FFFFFF} dollars and 2 score for arresting %s(%d)!", cash_format( totalCash ), ReturnPlayerName( victimid ), victimid ); GameTextForPlayer( victimid, "~r~Busted!", 4000, 0 );