Update business.pwn

This commit is contained in:
Stev 2019-08-26 21:15:52 +01:00
parent dbd9c9a2fd
commit d13152e84d

View File

@ -220,40 +220,32 @@ hook OnServerUpdate( )
// Replenish product // Replenish product
foreach ( new businessid : business ) if ( g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] ) foreach ( new businessid : business ) if ( g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] )
{ {
new // reduce business production time by a second
members = 0; g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] --;
GetOnlineBusinessAssociates( businessid, members ); // if the production timestamp is less than 0 ... refuel
if ( g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] <= 0 )
if ( members )
{ {
// reduce business production time by a second // update the timestamps and switch stock for product
g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] --; g_businessData[ businessid ] [ E_PRODUCT ] += g_businessData[ businessid ] [ E_SUPPLIES ];
g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] = 0;
g_businessData[ businessid ] [ E_SUPPLIES ] = 0;
// if the production timestamp is less than 0 ... refuel // alert any associates
if ( g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] <= 0 ) foreach ( new p : Player ) if ( IsBusinessAssociate( p, businessid ) ) {
{ SendClientMessageFormatted( p, -1, ""COL_GREY"[BUSINESS]"COL_WHITE" Production has completed for "COL_GREY"%s"COL_WHITE".", g_businessData[ businessid ] [ E_NAME ] );
// update the timestamps and switch stock for product
g_businessData[ businessid ] [ E_PRODUCT ] += g_businessData[ businessid ] [ E_SUPPLIES ];
g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] = 0;
g_businessData[ businessid ] [ E_SUPPLIES ] = 0;
// alert any associates
foreach ( new p : Player ) if ( IsBusinessAssociate( p, businessid ) ) {
SendClientMessageFormatted( p, -1, ""COL_GREY"[BUSINESS]"COL_WHITE" Production has completed for "COL_GREY"%s"COL_WHITE".", g_businessData[ businessid ] [ E_NAME ] );
}
// update db
UpdateBusinessData( businessid );
}
else if ( g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] % 60 == 0 ) // every minute that passes, update in the sql
{
mysql_single_query( sprintf( "UPDATE `BUSINESSES` SET `PROD_TIMESTAMP` = %d WHERE `ID` = %d", g_businessData[ businessid ] [ E_PROD_TIMESTAMP ], businessid ) );
} }
// update label anyway // update db
UpdateBusinessProductionLabel( businessid ); UpdateBusinessData( businessid );
} }
else if ( g_businessData[ businessid ] [ E_PROD_TIMESTAMP ] % 60 == 0 ) // every minute that passes, update in the sql
{
mysql_single_query( sprintf( "UPDATE `BUSINESSES` SET `PROD_TIMESTAMP` = %d WHERE `ID` = %d", g_businessData[ businessid ] [ E_PROD_TIMESTAMP ], businessid ) );
}
// update label anyway
UpdateBusinessProductionLabel( businessid );
} }
return 1; return 1;
} }