From 49d646048b90021ad6f449576b8ebb311dba4514 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Sun, 23 Dec 2018 09:56:48 +1100 Subject: [PATCH] automatically check for inactive stocks at the end of a game day --- .../cnr/features/stocks/stocks.pwn | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/gamemodes/irresistible/cnr/features/stocks/stocks.pwn b/gamemodes/irresistible/cnr/features/stocks/stocks.pwn index 95951c5..d26ed96 100644 --- a/gamemodes/irresistible/cnr/features/stocks/stocks.pwn +++ b/gamemodes/irresistible/cnr/features/stocks/stocks.pwn @@ -94,30 +94,15 @@ hook OnScriptInit( ) CreateStockMarket( E_STOCK_GOVERNMENT, "Government", "GOV", 100000.0, 750.0, 7500.0, 100000.0, 150.0, "Fireman and LEO activities" ); CreateStockMarket( E_STOCK_AVIATION, "Elitas Travel", "ET", 100000.0, 50.0, 500.0, 100000.0, 20.0, "Completed pilot missions and intercity travel" ); - // force inactive share holders to sell their shares + // force inactive share holders to sell their shares on startup mysql_tquery( dbHandle, sprintf( "SELECT so.* FROM `STOCK_OWNERS` so JOIN `USERS` u ON so.`USER_ID`=u.`ID` WHERE UNIX_TIMESTAMP()-u.`LASTLOGGED` > 604800 AND so.`USER_ID` != %d", STOCK_MM_USER_ID ), "StockMarket_ForceShareSale", "" ); return 1; } - -thread StockMarket_ForceShareSale( ) +hook OnServerGameDayEnd( ) { - new - rows = cache_get_row_count( ); - - if ( rows ) - { - for ( new row = 0; row < rows; row ++ ) - { - new accountid = cache_get_field_content_int( row, "USER_ID" ); - new stockid = cache_get_field_content_int( row, "STOCK_ID" ); - new Float: shares = cache_get_field_content_float( row, "SHARES" ); - - mysql_single_query( sprintf( "DELETE FROM `STOCK_OWNERS` WHERE `USER_ID`=%d AND `STOCK_ID`=%d", accountid, stockid ) ); - StockMarket_UpdateSellOrder( stockid, accountid, shares ); - printf("Inactive shares (user id: %d, stock id: %s, shares: %f)", accountid, g_stockMarketData[ stockid ] [ E_NAME ], shares); - } - } + // force inactive share holders to sell their shares every game day + mysql_tquery( dbHandle, sprintf( "SELECT so.* FROM `STOCK_OWNERS` so JOIN `USERS` u ON so.`USER_ID`=u.`ID` WHERE UNIX_TIMESTAMP()-u.`LASTLOGGED` > 604800 AND so.`USER_ID` != %d", STOCK_MM_USER_ID ), "StockMarket_ForceShareSale", "" ); return 1; } @@ -730,6 +715,27 @@ thread StockMarket_ShowShareholders( playerid, stockid ) return 1; } +thread StockMarket_ForceShareSale( ) +{ + new + rows = cache_get_row_count( ); + + if ( rows ) + { + for ( new row = 0; row < rows; row ++ ) + { + new accountid = cache_get_field_content_int( row, "USER_ID" ); + new stockid = cache_get_field_content_int( row, "STOCK_ID" ); + new Float: shares = cache_get_field_content_float( row, "SHARES" ); + + mysql_single_query( sprintf( "DELETE FROM `STOCK_OWNERS` WHERE `USER_ID`=%d AND `STOCK_ID`=%d", accountid, stockid ) ); + StockMarket_UpdateSellOrder( stockid, accountid, shares ); + printf("Inactive shares (user id: %d, stock id: %s, shares: %f)", accountid, g_stockMarketData[ stockid ] [ E_NAME ], shares); + } + } + return 1; +} + /* ** Command ** */ CMD:stocks( playerid, params[ ] ) return cmd_stockmarkets( playerid, params ); CMD:stockmarkets( playerid, params[ ] ) @@ -762,12 +768,7 @@ CMD:astock( playerid, params[ ] ) UpdateServerVariableInt( "stock_report_time", GetServerTime( ) + STOCK_REPORTING_PERIOD ); return SendServerMessage( playerid, "All stocks have now had their dividends distributed." ); } - else if ( strmatch( params, "purge inactive" ) ) - { - mysql_tquery( dbHandle, sprintf( "SELECT so.* FROM `STOCK_OWNERS` so JOIN `USERS` u ON so.`USER_ID`=u.`ID` WHERE UNIX_TIMESTAMP()-u.`LASTLOGGED` > 604800 AND so.`USER_ID` != %d", STOCK_MM_USER_ID ), "StockMarket_ForceShareSale", "" ); - return SendServerMessage( playerid, "All inactive share holders now have their stocks on sale." ); - } - return SendUsage( playerid, "/astock [UPDATE MAXSHARES/NEW REPORT/PURGE INACTIVE]" ); + return SendUsage( playerid, "/astock [UPDATE MAXSHARES/NEW REPORT]" ); } /* ** Functions ** */