disable happy hour configuration

This commit is contained in:
Lorenc Pekaj 2019-02-23 19:22:36 +11:00
parent 398f4c8ece
commit 5fe215beed
2 changed files with 66 additions and 53 deletions

View File

@ -13,41 +13,74 @@
#endinput #endinput
#endif #endif
/* ** Configuration ** */
#define DISABLE_HAPPY_HOUR
/* ** Variables ** */ /* ** Variables ** */
static stock #if !defined DISABLE_HAPPY_HOUR
bool: g_HappyHour = false, static stock
Float: g_HappyHourRate = 0.0 bool: g_HappyHour = false,
; Float: g_HappyHourRate = 0.0,
Text: g_NotManyPlayersTD = Text: INVALID_TEXT_DRAW
;
#endif
/* ** Hooks ** */ /* ** Hooks ** */
hook OnServerUpdate( ) #if !defined DISABLE_HAPPY_HOUR
{ hook OnScriptInit( )
new Float: fLastRate; {
new playersOnline = Iter_Count(Player); g_NotManyPlayersTD = TextDrawCreate(322.000000, 12.000000, "Coin generation increased by 5x as there aren't many players online!");
TextDrawAlignment(g_NotManyPlayersTD, 2);
// Happy Hour TextDrawBackgroundColor(g_NotManyPlayersTD, 0);
if ( ( g_HappyHour = playersOnline <= 20 ) == true ) { TextDrawFont(g_NotManyPlayersTD, 1);
// Maximum of 25% decrease TextDrawLetterSize(g_NotManyPlayersTD, 0.149999, 0.799999);
g_HappyHourRate = 0.25 - ( playersOnline / 80.0 ); TextDrawColor(g_NotManyPlayersTD, -16776961);
TextDrawSetOutline(g_NotManyPlayersTD, 1);
// Only update colors if neccessary TextDrawSetProportional(g_NotManyPlayersTD, 1);
if ( fLastRate != g_HappyHourRate ) return 1;
{
TextDrawSetString( g_NotManyPlayersTD, sprintf( "Coin generation increased by %0.1f%% as there aren't many players online!", g_HappyHourRate * 100.0 ) );
TextDrawColor( g_NotManyPlayersTD, setAlpha( COLOR_RED, floatround( 200.0 - 10.0 * float( playersOnline ) ) ) );
TextDrawShowForAllSpawned( g_NotManyPlayersTD );
}
// Update last rate
fLastRate = g_HappyHourRate;
} else {
// Disable Color
g_HappyHourRate = 0.0;
TextDrawColor( g_NotManyPlayersTD, 0 );
TextDrawHideForAll( g_NotManyPlayersTD );
} }
return 1;
} hook OnServerUpdate( )
{
new Float: fLastRate;
new playersOnline = Iter_Count(Player);
// Happy Hour
if ( ( g_HappyHour = playersOnline <= 20 ) == true ) {
// Maximum of 25% decrease
g_HappyHourRate = 0.25 - ( playersOnline / 80.0 );
// Only update colors if neccessary
if ( fLastRate != g_HappyHourRate )
{
TextDrawSetString( g_NotManyPlayersTD, sprintf( "Coin generation increased by %0.1f%% as there aren't many players online!", g_HappyHourRate * 100.0 ) );
TextDrawColor( g_NotManyPlayersTD, setAlpha( COLOR_RED, floatround( 200.0 - 10.0 * float( playersOnline ) ) ) );
TextDrawShowForAllSpawned( g_NotManyPlayersTD );
}
// Update last rate
fLastRate = g_HappyHourRate;
} else {
// Disable Color
g_HappyHourRate = 0.0;
TextDrawColor( g_NotManyPlayersTD, 0 );
TextDrawHideForAll( g_NotManyPlayersTD );
}
return 1;
}
hook OnPlayerLoadTextdraws( playerid ){
if ( g_HappyHour ) {
TextDrawShowForPlayer( playerid, g_NotManyPlayersTD );
}
return 1;
}
hook OnPlayerUnloadTextdraws( playerid ) {
TextDrawHideForPlayer( playerid, g_NotManyPlayersTD );
return 1;
}
#endif
hook OnPlayerTickSecond( playerid ) hook OnPlayerTickSecond( playerid )
{ {
@ -69,24 +102,14 @@ hook OnPlayerTickSecond( playerid )
else if ( p_VIPLevel[ playerid ] == VIP_PLATINUM ) else if ( p_VIPLevel[ playerid ] == VIP_PLATINUM )
iCoinGenRate *= 0.90; // Reduce by 10% if Diamond iCoinGenRate *= 0.90; // Reduce by 10% if Diamond
#if !defined DISABLE_HAPPY_HOUR
// Happy Hour // Happy Hour
if ( g_HappyHour && ( 0.0 <= g_HappyHourRate <= 0.25 ) ) if ( g_HappyHour && ( 0.0 <= g_HappyHourRate <= 0.25 ) )
iCoinGenRate *= 1.0 - g_HappyHourRate; iCoinGenRate *= 1.0 - g_HappyHourRate;
#endif
GivePlayerIrresistibleCoins( playerid, ( 1.0 / iCoinGenRate ) / 60.0 ); // Prev 25.92 GivePlayerIrresistibleCoins( playerid, ( 1.0 / iCoinGenRate ) / 60.0 ); // Prev 25.92
} }
} }
return 1; return 1;
} }
hook OnPlayerLoadTextdraws( playerid ) {
if ( g_HappyHour ) {
TextDrawShowForPlayer( playerid, g_NotManyPlayersTD );
}
return 1;
}
hook OnPlayerUnloadTextdraws( playerid ) {
TextDrawHideForPlayer( playerid, g_NotManyPlayersTD );
return 1;
}

View File

@ -21,7 +21,6 @@ new
Text: g_currentXPTD = Text: INVALID_TEXT_DRAW, Text: g_currentXPTD = Text: INVALID_TEXT_DRAW,
Text: g_CurrentRankTD = Text: INVALID_TEXT_DRAW, Text: g_CurrentRankTD = Text: INVALID_TEXT_DRAW,
Text: g_CurrentCoinsTD = Text: INVALID_TEXT_DRAW, Text: g_CurrentCoinsTD = Text: INVALID_TEXT_DRAW,
Text: g_NotManyPlayersTD = Text: INVALID_TEXT_DRAW,
// Player Textdraws // Player Textdraws
PlayerText: p_LocationTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... }, PlayerText: p_LocationTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
@ -44,15 +43,6 @@ new
/* ** Hooks ** */ /* ** Hooks ** */
hook OnScriptInit( ) hook OnScriptInit( )
{ {
g_NotManyPlayersTD = TextDrawCreate(322.000000, 12.000000, "Coin generation increased by 5x as there aren't many players online!");
TextDrawAlignment(g_NotManyPlayersTD, 2);
TextDrawBackgroundColor(g_NotManyPlayersTD, 0);
TextDrawFont(g_NotManyPlayersTD, 1);
TextDrawLetterSize(g_NotManyPlayersTD, 0.149999, 0.799999);
TextDrawColor(g_NotManyPlayersTD, -16776961);
TextDrawSetOutline(g_NotManyPlayersTD, 1);
TextDrawSetProportional(g_NotManyPlayersTD, 1);
g_currentXPTD = TextDrawCreate(529.000000, 405.000000, "Current XP"); g_currentXPTD = TextDrawCreate(529.000000, 405.000000, "Current XP");
TextDrawBackgroundColor(g_currentXPTD, 255); TextDrawBackgroundColor(g_currentXPTD, 255);
TextDrawFont(g_currentXPTD, 3); TextDrawFont(g_currentXPTD, 3);