- add xp dilation just so people do not get bored of "+1 xp" constantly

- double xp factored in
This commit is contained in:
Lorenc Pekaj 2018-09-28 09:49:06 +10:00
parent 2cb296835a
commit 1e6b9d8116
3 changed files with 67 additions and 33 deletions

View File

@ -11,6 +11,9 @@
/* ** Definitions ** */
#define EXP_MAX_PLAYER_LEVEL ( 100 )
/* ** Double XP ** */
#define IsDoubleXP() ( GetGVarInt( "doublexp" ) )
/* ** Constants ** */
enum E_LEVELS {
E_LAW_ENFORCEMENT,
@ -25,27 +28,27 @@ enum E_LEVELS {
};
enum E_LEVEL_DATA {
E_NAME[ 16 ], Float: E_MAX_UNITS
E_NAME[ 16 ], Float: E_MAX_UNITS, Float: E_XP_DILATION
};
static const
g_levelData[ ] [ E_LEVEL_DATA ] =
{
// Level Name Level 100 Req.
{ "Law Enforcement", 25000.0 }, // 25K arrests
{ "Robbery", 100000.0 }, // 100K robberies
{ "Deathmatch", 200000.0 } // 200K kills
// Level Name Level 100 Req. XP Dilation (just to confuse user)
{ "Law Enforcement", 25000.0, 3.0 }, // 25K arrests
{ "Robbery", 100000.0, 2.0 }, // 100K robberies
{ "Deathmatch", 200000.0, 1.0 } // 200K kills
}
;
/* ** Variables ** */
new
static stock
Float: g_playerExperience [ MAX_PLAYERS ] [ E_LEVELS ]
;
/* ** Important ** */
stock Float: GetPlayerLevel( playerid, E_LEVELS: level ) {
return floatsqroot( g_playerExperience[ playerid ] [ level ] / ( g_levelData[ _: level ] [ E_MAX_UNITS ] / ( EXP_MAX_PLAYER_LEVEL * EXP_MAX_PLAYER_LEVEL ) ) );
return floatsqroot( g_playerExperience[ playerid ] [ level ] / ( ( g_levelData[ _: level ] [ E_MAX_UNITS ] * g_levelData[ _: level ] [ E_XP_DILATION ] ) / ( EXP_MAX_PLAYER_LEVEL * EXP_MAX_PLAYER_LEVEL ) ) );
}
stock Float: GetPlayerTotalExperience( playerid ) {
@ -59,9 +62,14 @@ stock Float: GetPlayerTotalExperience( playerid ) {
}
/* ** Hooks ** */
hook OnPlayerDisconnect( playerid, reason ) {
for ( new l = 0; l < sizeof ( g_levelData ); l ++ ) {
g_playerExperience[ playerid ] [ E_LEVELS: l ] = 0;
hook OnPlayerUpdateEx( playerid )
{
if ( IsPlayerLoggedIn( playerid ) )
{
new
Float: total_experience = GetPlayerTotalExperience( playerid );
PlayerTextDrawSetString( playerid, p_ExperienceTD[ playerid ], sprintf( "%08.0f", total_experience ) );
}
return 1;
}
@ -72,6 +80,13 @@ hook OnPlayerLogin( playerid )
return 1;
}
hook OnPlayerDisconnect( playerid, reason ) {
for ( new l = 0; l < sizeof ( g_levelData ); l ++ ) {
g_playerExperience[ playerid ] [ E_LEVELS: l ] = 0;
}
return 1;
}
/* ** Commands ** */
CMD:level( playerid, params[ ] )
{
@ -87,21 +102,6 @@ CMD:level( playerid, params[ ] )
return ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Player Level", szLargeString, "Close", "" );
}
/* ** Functions ** */
stock GivePlayerExperience( playerid, E_LEVELS: level, Float: experience = 1.0 )
{
if ( ( g_playerExperience[ playerid ] [ level ] += experience ) > g_levelData[ _: level ] [ E_MAX_UNITS ] ) {
g_playerExperience[ playerid ] [ level ] = g_levelData[ _: level ] [ E_MAX_UNITS ];
}
// save to database
mysql_format(
dbHandle, szBigString, sizeof( szBigString ),
"INSERT INTO `USER_LEVELS` (`USER_ID`,`LEVEL_ID`,`EXPERIENCE`) VALUES(%d,%d,%d) ON DUPLICATE KEY UPDATE `EXPERIENCE`=%d",
GetPlayerAccountID( playerid ), _: level, g_playerExperience[ playerid ] [ level ], g_playerExperience[ playerid ] [ level ]
);
}
/* ** SQL Threads ** */
thread Experience_OnLoad( playerid )
{
@ -124,6 +124,46 @@ thread Experience_OnLoad( playerid )
return 1;
}
/* ** Functions ** */
stock GivePlayerExperience( playerid, E_LEVELS: level, Float: experience = 1.0 )
{
if ( ! IsPlayerLoggedIn( playerid ) )
return;
// dilation is there so people see +3 when they arrest ... could trigger dopamine levels instead of constantly +1 lol
new xp_earned = ( experience * g_levelData[ _: level ] [ E_XP_DILATION ] ) * ( IsDoubleXP( ) ? 2.0 : 1.0 );
// 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 ];
}
// alert user
PlayerTextDrawSetString( playerid, p_ExperienceAwardTD[ playerid ], sprintf( "+%0.0f", xp_earned ) );
PlayerTextDrawShow( playerid, p_ExperienceAwardTD[ playerid ] );
SetTimerEx( "Experience_HideIncrementTD", 3500, false, "d", playerid );
// TODO: on level change
// save to database
mysql_format(
dbHandle, szBigString, sizeof( szBigString ),
"INSERT INTO `USER_LEVELS` (`USER_ID`,`LEVEL_ID`,`EXPERIENCE`) VALUES(%d,%d,%d) ON DUPLICATE KEY UPDATE `EXPERIENCE`=%d",
GetPlayerAccountID( playerid ), _: level, g_playerExperience[ playerid ] [ level ], g_playerExperience[ playerid ] [ level ]
);
}
function Experience_HideIncrementTD( playerid ) {
return PlayerTextDrawHide( playerid, p_ExperienceAwardTD[ playerid ] );
}
stock GetPlayerTotalLevel( playerid, &level = 0 ) {
for ( new l = 0; l < sizeof ( g_levelData ); l ++ ) {
level += floatround( GetPlayerLevel( playerid, E_LEVELS: l ), floatround_floor );
}
return level;
}
/* ** Migrations ** */
/*
CREATE TABLE IF NOT EXISTS USER_LEVELS (

View File

@ -65,7 +65,6 @@ new
bool: p_Spectating [ MAX_PLAYERS char ],
bool: p_Muted [ MAX_PLAYERS char ],
bool: p_InfectedHIV [ MAX_PLAYERS char ],
p_ExperienceHideTimer [ MAX_PLAYERS ],
p_AntiTextSpam [ MAX_PLAYERS ],
bool: p_BlockedPM [ MAX_PLAYERS ] [ MAX_PLAYERS ],
bool: p_inFBI [ MAX_PLAYERS char ],
@ -265,3 +264,4 @@ stock IsPlayerAdminOnDuty( playerid ) return p_AdminOnDuty{ playerid };
stock IsPlayerSpawnProtected( playerid ) return p_AntiSpawnKillEnabled{ playerid };
stock IsPlayerLoggedIn( playerid ) return p_PlayerLogged{ playerid };

View File

@ -71,9 +71,6 @@ new bool: False = false;
#define IsPlayerNpcEx(%0) (IsPlayerNPC(%0) || strmatch(p_PlayerIP[%0], "127.0.0.1"))
#define GetBusinessSecurity(%0) (g_businessSecurityData[%0][E_LEVEL])
/* Dynamic Macros */
#define IsDoubleXP() (GetGVarInt("doublexp")!=0)
/* Beast Functions */
#define SendClientMessageToCops(%1,%2,%3) \
do{foreach(new fI : Player){if (p_Class[fI]==CLASS_POLICE)format(szNormalString,sizeof(szNormalString),(%2),%3),SendClientMessage(fI,(%1),szNormalString);}}while(False)
@ -2551,7 +2548,6 @@ public OnServerUpdateTimer( )
// Generally Updated textdraws
PlayerTextDrawSetString( playerid, p_LocationTD[ playerid ], GetPlayerArea( playerid ) );
PlayerTextDrawSetString( playerid, p_ExperienceTD[ playerid ], sprintf( "%08d", p_XP[ playerid ] ) );
// Update casino labels
UpdateDynamic3DTextLabelText( p_RewardsLabel_Caligs[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) );
@ -17991,7 +17987,7 @@ stock GivePlayerXP( playerid, amount )
p_XP[ playerid ] += amount;
PlayerTextDrawSetString( playerid, p_ExperienceAwardTD[ playerid ], string );
PlayerTextDrawShow( playerid, p_ExperienceAwardTD[ playerid ] );
p_ExperienceHideTimer[ playerid ] = SetTimerEx( "ExperienceTD_hide", 3500, false, "d", playerid );
SetTimerEx( "ExperienceTD_hide", 3500, false, "d", playerid );
if ( p_XP[ playerid ] > 99999999 ) p_XP[ playerid ] = 99999999;
autosaveStart( playerid ); // auto-save
return 1;
@ -17999,8 +17995,6 @@ stock GivePlayerXP( playerid, amount )
return 0;
}
function ExperienceTD_hide( playerid ) return PlayerTextDrawHide( playerid, p_ExperienceAwardTD[ playerid ] );
stock IsPlayerFBI( playerid )
{
new