automatically check for inactive stocks at the end of a game day
This commit is contained in:
parent
dc699f5523
commit
49d646048b
@ -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_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" );
|
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", "" );
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hook OnServerGameDayEnd( )
|
||||||
thread StockMarket_ForceShareSale( )
|
|
||||||
{
|
{
|
||||||
new
|
// force inactive share holders to sell their shares every game day
|
||||||
rows = cache_get_row_count( );
|
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", "" );
|
||||||
|
|
||||||
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,6 +715,27 @@ thread StockMarket_ShowShareholders( playerid, stockid )
|
|||||||
return 1;
|
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 ** */
|
/* ** Command ** */
|
||||||
CMD:stocks( playerid, params[ ] ) return cmd_stockmarkets( playerid, params );
|
CMD:stocks( playerid, params[ ] ) return cmd_stockmarkets( playerid, params );
|
||||||
CMD:stockmarkets( playerid, params[ ] )
|
CMD:stockmarkets( playerid, params[ ] )
|
||||||
@ -762,12 +768,7 @@ CMD:astock( playerid, params[ ] )
|
|||||||
UpdateServerVariableInt( "stock_report_time", GetServerTime( ) + STOCK_REPORTING_PERIOD );
|
UpdateServerVariableInt( "stock_report_time", GetServerTime( ) + STOCK_REPORTING_PERIOD );
|
||||||
return SendServerMessage( playerid, "All stocks have now had their dividends distributed." );
|
return SendServerMessage( playerid, "All stocks have now had their dividends distributed." );
|
||||||
}
|
}
|
||||||
else if ( strmatch( params, "purge inactive" ) )
|
return SendUsage( playerid, "/astock [UPDATE MAXSHARES/NEW REPORT]" );
|
||||||
{
|
|
||||||
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]" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ** Functions ** */
|
/* ** Functions ** */
|
||||||
|
Loading…
Reference in New Issue
Block a user