add progress bar to experience

This commit is contained in:
Lorenc Pekaj 2018-09-29 19:25:39 +10:00
parent 88c8bd3582
commit 6c0ae4134c
4 changed files with 73 additions and 33 deletions

View File

@ -59,7 +59,13 @@ static const
/* ** Variables ** */
static stock
Float: g_playerExperience [ MAX_PLAYERS ] [ E_LEVELS ]
Float: g_playerExperience [ MAX_PLAYERS ] [ E_LEVELS ],
PlayerText: p_playerExpTitle [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: p_playerExpAwardTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerBar: p_playerExpProgress [ MAX_PLAYERS ],
p_playerExpHideTimer [ MAX_PLAYERS ] = { -1, ... }
;
/* ** Important ** */
@ -104,6 +110,34 @@ hook OnPlayerLogin( playerid )
return 1;
}
hook OnPlayerConnect( playerid )
{
// progress bar for xp
p_playerExpProgress[ playerid ] = CreatePlayerProgressBar( playerid, 47.000000, 263.000000, 82.500000, 7.199999, COLOR_GOLD, 100.0000, 0 ); // -2007060993
// title of progress bar
p_playerExpTitle[ playerid ] = CreatePlayerTextDraw( playerid, 86.000000, 248.000000, "_" );
PlayerTextDrawAlignment( playerid, p_playerExpTitle[ playerid ], 2 );
PlayerTextDrawBackgroundColor( playerid, p_playerExpTitle[ playerid ], 255 );
PlayerTextDrawFont( playerid, p_playerExpTitle[ playerid ], 1 );
PlayerTextDrawLetterSize( playerid, p_playerExpTitle[ playerid ], 0.240000, 1.200000 );
PlayerTextDrawColor( playerid, p_playerExpTitle[ playerid ], COLOR_GOLD );
PlayerTextDrawSetOutline( playerid, p_playerExpTitle[ playerid ], 1 );
PlayerTextDrawSetProportional( playerid, p_playerExpTitle[ playerid ], 1 );
// general reward
p_playerExpAwardTD[ playerid ] = CreatePlayerTextDraw( playerid,319.000000, 167.000000, "+20 XP" );
PlayerTextDrawAlignment( playerid,p_playerExpAwardTD[ playerid ], 2 );
PlayerTextDrawBackgroundColor( playerid,p_playerExpAwardTD[ playerid ], 255 );
PlayerTextDrawFont( playerid,p_playerExpAwardTD[ playerid ], 3 );
PlayerTextDrawLetterSize( playerid,p_playerExpAwardTD[ playerid ], 0.450000, 1.599999 );
PlayerTextDrawColor( playerid,p_playerExpAwardTD[ playerid ], COLOR_GOLD );
PlayerTextDrawSetOutline( playerid,p_playerExpAwardTD[ playerid ], 1 );
PlayerTextDrawSetProportional( playerid,p_playerExpAwardTD[ playerid ], 1 );
PlayerTextDrawSetSelectable( playerid,p_playerExpAwardTD[ playerid ], 0 );
return 1;
}
hook OnPlayerDisconnect( playerid, reason ) {
for ( new l = 0; l < sizeof ( g_levelData ); l ++ ) {
g_playerExperience[ playerid ] [ E_LEVELS: l ] = 0;
@ -134,11 +168,11 @@ CMD:level( playerid, params[ ] )
for ( new level_id; level_id < sizeof( g_levelData ); level_id ++ )
{
new Float: current_rank = GetPlayerLevel( watchingid, E_LEVELS: level_id );
new Float: next_rank = floatround( current_rank, floatround_floor ) + 1.0;
new Float: next_rank_xp = ( g_levelData[ level_id ] [ E_MAX_UNITS ] * g_levelData[ level_id ] [ E_XP_DILATION ] ) / ( EXP_MAX_PLAYER_LEVEL * EXP_MAX_PLAYER_LEVEL ) * ( next_rank * next_rank );
new Float: next_lvl = floatround( current_rank, floatround_floor ) + 1.0;
new Float: next_lvl_xp = ( g_levelData[ level_id ] [ E_MAX_UNITS ] * g_levelData[ level_id ] [ E_XP_DILATION ] ) / ( EXP_MAX_PLAYER_LEVEL * EXP_MAX_PLAYER_LEVEL ) * ( next_lvl * next_lvl );
player_total_lvl += floatround( current_rank, floatround_floor );
format( szLargeString, sizeof( szLargeString ), "%s%s Level\t%s%0.0f / %0.0f\t"COL_PURPLE"%0.0f XP\n", szLargeString, g_levelData[ level_id ] [ E_NAME ], current_rank >= 100.0 ? ( COL_GREEN ) : ( COL_GREY ), current_rank, EXP_MAX_PLAYER_LEVEL, next_rank_xp - g_playerExperience[ watchingid ] [ E_LEVELS: level_id ] );
format( szLargeString, sizeof( szLargeString ), "%s%s Level\t%s%0.0f / %0.0f\t"COL_PURPLE"%0.0f XP\n", szLargeString, g_levelData[ level_id ] [ E_NAME ], current_rank >= 100.0 ? ( COL_GREEN ) : ( COL_GREY ), current_rank, EXP_MAX_PLAYER_LEVEL, next_lvl_xp - g_playerExperience[ watchingid ] [ E_LEVELS: level_id ] );
}
SetPVarInt( playerid, "experience_watchingid", watchingid );
@ -177,23 +211,34 @@ stock GivePlayerExperience( playerid, E_LEVELS: level, Float: default_xp = 1.0,
new Float: xp_earned = default_xp * ( IsDoubleXP( ) ? 2.0 : 1.0 ) * ( with_dilation ? ( g_levelData[ _: level ] [ E_XP_DILATION ] ) : 1.0 );
// when a player ranks up
new next_rank = floatround( GetPlayerLevel( playerid, level ), floatround_floor ) + 1;
new Float: next_rank_xp = ( g_levelData[ _: level ] [ E_MAX_UNITS ] * g_levelData[ _: level ] [ E_XP_DILATION ] ) / ( EXP_MAX_PLAYER_LEVEL * EXP_MAX_PLAYER_LEVEL ) * float( next_rank * next_rank );
new next_lvl = floatround( GetPlayerLevel( playerid, level ), floatround_floor ) + 1;
new Float: next_lvl_xp = ( g_levelData[ _: level ] [ E_MAX_UNITS ] * g_levelData[ _: level ] [ E_XP_DILATION ] ) / ( EXP_MAX_PLAYER_LEVEL * EXP_MAX_PLAYER_LEVEL ) * float( next_lvl * next_lvl );
if ( g_playerExperience[ playerid ] [ level ] + xp_earned >= next_rank_xp ) {
ShowPlayerHelpDialog( playerid, 10000, "~p~Congratulations %s!~n~~n~~w~Your %s Level is now ~p~%d.", ReturnPlayerName( playerid ), g_levelData[ _: level ] [ E_NAME ], next_rank );
if ( g_playerExperience[ playerid ] [ level ] + xp_earned >= next_lvl_xp ) {
ShowPlayerHelpDialog( playerid, 10000, "~p~Congratulations %s!~n~~n~~w~Your %s Level is now ~p~%d.", ReturnPlayerName( playerid ), g_levelData[ _: level ] [ E_NAME ], next_lvl );
if ( !IsPlayerUsingRadio( playerid ) ) PlayAudioStreamForPlayer( playerid, "http://files.sfcnr.com/game_sounds/levelup.mp3" );
PlayerTextDrawSetString( playerid, p_playerExpTitle[ playerid ], sprintf( "%s Level %d", g_levelData[ _: level ] [ E_NAME ], next_lvl ) );
SetPlayerProgressBarValue( playerid, p_playerExpProgress[ playerid ], 100.0 );
} else {
PlayerTextDrawSetString( playerid, p_playerExpTitle[ playerid ], sprintf( "%s Level %d", g_levelData[ _: level ] [ E_NAME ], next_lvl - 1 ) );
}
// check if its over 100 anyway
if ( ( g_playerExperience[ playerid ] [ level ] += xp_earned ) > g_levelData[ _: level ] [ E_MAX_UNITS ] * g_levelData[ _: level ] [ E_XP_DILATION ] ) {
g_playerExperience[ playerid ] [ level ] = g_levelData[ _: level ] [ E_MAX_UNITS ] * g_levelData[ _: level ] [ E_XP_DILATION ];
SetPlayerProgressBarValue( playerid, p_playerExpProgress[ playerid ], 100.0 );
} else {
new Float: progress = floatfract( GetPlayerLevel( playerid, level ) ) * 100.0;
SetPlayerProgressBarValue( playerid, p_playerExpProgress[ playerid ], progress );
}
// alert user
PlayerTextDrawSetString( playerid, p_ExperienceAwardTD[ playerid ], sprintf( "+%0.0f XP", xp_earned ) );
PlayerTextDrawShow( playerid, p_ExperienceAwardTD[ playerid ] );
SetTimerEx( "Experience_HideIncrementTD", 3500, false, "d", playerid );
KillTimer( p_playerExpHideTimer[ playerid ] );
PlayerTextDrawShow( playerid, p_playerExpTitle[ playerid ] );
ShowPlayerProgressBar( playerid, p_playerExpProgress[ playerid ] );
PlayerTextDrawSetString( playerid, p_playerExpAwardTD[ playerid ], sprintf( "+%0.0f XP", xp_earned ) );
PlayerTextDrawShow( playerid, p_playerExpAwardTD[ playerid ] );
p_playerExpHideTimer[ playerid ] = SetTimerEx( "Experience_HideIncrementTD", 3500, false, "d", playerid );
// save to database
format(
@ -204,8 +249,13 @@ stock GivePlayerExperience( playerid, E_LEVELS: level, Float: default_xp = 1.0,
return mysql_single_query( szBigString ), 1;
}
function Experience_HideIncrementTD( playerid ) {
return PlayerTextDrawHide( playerid, p_ExperienceAwardTD[ playerid ] );
function Experience_HideIncrementTD( playerid )
{
p_playerExpHideTimer[ playerid ] = -1;
HidePlayerProgressBar( playerid, p_playerExpProgress[ playerid ] );
PlayerTextDrawHide( playerid, p_playerExpAwardTD[ playerid ] );
PlayerTextDrawHide( playerid, p_playerExpTitle[ playerid ] );
return 1;
}
/*stock GetPlayerTotalLevel( playerid, &level = 0 ) {

View File

@ -56,7 +56,7 @@ new
p_Kills [ MAX_PLAYERS ],
p_Deaths [ MAX_PLAYERS ],
p_VIPLevel [ MAX_PLAYERS ],
p_XP [ MAX_PLAYERS ],
// p_XP [ MAX_PLAYERS ],
p_CureDealer [ MAX_PLAYERS ] = { INVALID_PLAYER_ID, ... },
p_CureTick [ MAX_PLAYERS ],
p_HealDealer [ MAX_PLAYERS ] = { INVALID_PLAYER_ID, ... },

View File

@ -43,7 +43,6 @@ new
// Player Textdraws
PlayerText: p_LocationTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: p_ExperienceTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: p_ExperienceAwardTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: p_WantedLevelTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: p_CoinsTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: p_PlayerRankTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
@ -552,16 +551,6 @@ hook OnPlayerConnect( playerid )
PlayerTextDrawSetOutline( playerid, p_ExperienceTD[ playerid ], 1 );
PlayerTextDrawSetProportional( playerid, p_ExperienceTD[ playerid ], 1 );
p_ExperienceAwardTD[ playerid ] = CreatePlayerTextDraw( playerid, 338.000000, 149.000000, "+20 XP" );
PlayerTextDrawAlignment( playerid, p_ExperienceAwardTD[ playerid ], 2 );
PlayerTextDrawBackgroundColor( playerid, p_ExperienceAwardTD[ playerid ], 144 );
PlayerTextDrawFont( playerid, p_ExperienceAwardTD[ playerid ], 3 );
PlayerTextDrawLetterSize( playerid, p_ExperienceAwardTD[ playerid ], 0.409999, 1.600000 );
PlayerTextDrawColor( playerid, p_ExperienceAwardTD[ playerid ], COLOR_GOLD );
PlayerTextDrawSetOutline( playerid, p_ExperienceAwardTD[ playerid ], 1 );
PlayerTextDrawSetProportional( playerid, p_ExperienceAwardTD[ playerid ], 1 );
PlayerTextDrawSetSelectable( playerid, p_ExperienceAwardTD[ playerid ], 0 );
p_WantedLevelTD[ playerid ] = CreatePlayerTextDraw( playerid, 555.000000, 124.000000, "_" );
PlayerTextDrawAlignment( playerid, p_WantedLevelTD[ playerid ], 2 );
PlayerTextDrawBackgroundColor( playerid, p_WantedLevelTD[ playerid ], 255 );

View File

@ -16,7 +16,7 @@
#pragma option -d3
#pragma dynamic 7200000
//#define DEBUG_MODE
#define DEBUG_MODE
#if defined DEBUG_MODE
#pragma option -d3
@ -47,6 +47,7 @@
#include < MathParser >
#include < mapandreas >
#include < md-sort >
#include < progress2 >
native WP_Hash ( buffer[ ], len, const str[ ] );
native IsValidVehicle ( vehicleid );
native gpci ( playerid, serial[ ], len );
@ -3853,7 +3854,7 @@ public OnPlayerDisconnect( playerid, reason )
p_Kills [ playerid ] = 0;
p_Deaths [ playerid ] = 0;
p_VIPLevel [ playerid ] = 0;
p_XP [ playerid ] = 0;
// p_XP [ playerid ] = 0;
p_InHouse [ playerid ] = -1;
p_InGarage [ playerid ] = -1;
p_inMovieMode { playerid } = false;
@ -8233,7 +8234,7 @@ thread OnPlayerWeeklyTime( playerid, irc, player[ ] )
return 1;
}
CMD:xpmarket( playerid, params[ ] ) return SendServerMessage( playerid, "You can no longer sell your experience anymore." );
CMD:xpmarket( playerid, params[ ] ) return SendError( playerid, "You can no longer sell your experience anymore." );
/*{
ShowPlayerDialog( playerid, DIALOG_XPMARKET, DIALOG_STYLE_INPUT, "{FFFFFF}XP Market", sprintf( ""COL_WHITE"You have %s legacy XP. Current exchange rate is $10 per XP.\n\nHow many would you like to exchange?", number_format( p_XP[ playerid ] ) ), "Select", "Cancel");
return 1;
@ -13240,7 +13241,7 @@ thread OnAttemptPlayerLogin( playerid, password[ ] )
p_Kills[ playerid ] = cache_get_field_content_int( 0, "KILLS", dbHandle );
p_Deaths[ playerid ] = cache_get_field_content_int( 0, "DEATHS", dbHandle );
p_VIPLevel[ playerid ] = cache_get_field_content_int( 0, "VIP_PACKAGE", dbHandle );
p_XP[ playerid ] = cache_get_field_content_int( 0, "XP", dbHandle );
//p_XP[ playerid ] = cache_get_field_content_int( 0, "XP", dbHandle );
p_VIPExpiretime[ playerid ] = cache_get_field_content_int( 0, "VIP_EXPIRE", dbHandle );
p_LastSkin[ playerid ] = cache_get_field_content_int( 0, "LAST_SKIN", dbHandle );
p_Burglaries[ playerid ] = cache_get_field_content_int( 0, "BURGLARIES", dbHandle );
@ -13506,7 +13507,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
SetPlayerScore( playerid, 0 );
p_Kills[ playerid ] = 1;
p_Deaths[ playerid ] = 1;
p_XP[ playerid ] = 0;
//p_XP[ playerid ] = 0;
//p_CopTutorial{ playerid } = 0;
p_drillStrength[ playerid ] = MAX_DRILL_STRENGTH;
p_OwnedHouses[ playerid ] = 0;
@ -15117,7 +15118,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
""COL_GREY"Kills:{FFFFFF} %d\n"\
""COL_GREY"Deaths:{FFFFFF} %d\n"\
""COL_GREY"Ratio (K/D):{FFFFFF} %0.2f\n",
GetPlayerScore( pID ), p_XP[ pID ], cash_format( GetPlayerCash( pID ) ), cash_format( p_BankMoney[ pID ] ), p_Kills[ pID ], p_Deaths[ pID ], floatdiv( p_Kills[ pID ], p_Deaths[ pID ] ) );
GetPlayerScore( pID ), GetPlayerTotalExperience( pID ), cash_format( GetPlayerCash( pID ) ), cash_format( p_BankMoney[ pID ] ), p_Kills[ pID ], p_Deaths[ pID ], floatdiv( p_Kills[ pID ], p_Deaths[ pID ] ) );
format( szLargeString, 720, "%s"COL_GREY"Owned Houses:{FFFFFF} %d (Limit %d)\n"\
""COL_GREY"Owned Vehicles:{FFFFFF} %d (Limit %d)\n"\
@ -17374,10 +17375,10 @@ stock SavePlayerData( playerid, bool: logout = false )
if ( IsPlayerCuffed( playerid ) || IsPlayerTazed( playerid ) || IsPlayerTied( playerid ) || p_LeftCuffed{ playerid } || p_QuitToAvoidTimestamp[ playerid ] > g_iTime )
bQuitToAvoid = true;
format( Query, sizeof( Query ), "UPDATE `USERS` SET `SCORE`=%d,`CASH`=%d,`ADMINLEVEL`=%d,`BANKMONEY`=%d,`OWNEDHOUSES`=%d,`KILLS`=%d,`DEATHS`=%d,`VIP_PACKAGE`=%d,`XP`=%d,`OWNEDCARS`=%d,`LASTLOGGED`=%d,`VIP_EXPIRE`=%d,`LAST_SKIN`=%d,`BURGLARIES`=%d,`UPTIME`=%d,`ARRESTS`=%d,`CITY`=%d,`METH`=%d,`SODA`=%d,`ACID`=%d,`GAS`=%d,",
format( Query, sizeof( Query ), "UPDATE `USERS` SET `SCORE`=%d,`CASH`=%d,`ADMINLEVEL`=%d,`BANKMONEY`=%d,`OWNEDHOUSES`=%d,`KILLS`=%d,`DEATHS`=%d,`VIP_PACKAGE`=%d,`OWNEDCARS`=%d,`LASTLOGGED`=%d,`VIP_EXPIRE`=%d,`LAST_SKIN`=%d,`BURGLARIES`=%d,`UPTIME`=%d,`ARRESTS`=%d,`CITY`=%d,`METH`=%d,`SODA`=%d,`ACID`=%d,`GAS`=%d,",
GetPlayerScore( playerid ), GetPlayerCash( playerid ), p_AdminLevel[ playerid ],
p_BankMoney[ playerid ], p_OwnedHouses[ playerid ], p_Kills[ playerid ],
p_Deaths[ playerid ], p_VIPLevel[ playerid ], p_XP[ playerid ],
p_Deaths[ playerid ], p_VIPLevel[ playerid ],
p_OwnedVehicles[ playerid ], g_iTime, p_VIPExpiretime[ playerid ],
p_LastSkin[ playerid ], p_Burglaries[ playerid ], p_Uptime[ playerid ],
p_Arrests[ playerid ], p_SpawningCity{ playerid }, p_Methamphetamine{ playerid },