add experience v2 base ... remove accountid parameter from onplayerlogin
This commit is contained in:
parent
a9f6a09447
commit
054f4e4363
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
// reliant on core definitions
|
// reliant on core definitions
|
||||||
#include "irresistible\cnr\vip\_vip.pwn"
|
#include "irresistible\cnr\vip\_vip.pwn"
|
||||||
|
#include "irresistible\cnr\experience.pwn"
|
||||||
#include "irresistible\cnr\ammunation.pwn"
|
#include "irresistible\cnr\ammunation.pwn"
|
||||||
#include "irresistible\cnr\irresistibleguard.pwn"
|
#include "irresistible\cnr\irresistibleguard.pwn"
|
||||||
#include "irresistible\cnr\player_settings.pwn"
|
#include "irresistible\cnr\player_settings.pwn"
|
||||||
|
121
gamemodes/irresistible/cnr/experience.pwn
Normal file
121
gamemodes/irresistible/cnr/experience.pwn
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Irresistible Gaming (c) 2018
|
||||||
|
* Developed by Lorenc Pekaj
|
||||||
|
* Module:
|
||||||
|
* Purpose:
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* ** Includes ** */
|
||||||
|
#include < YSI\y_hooks >
|
||||||
|
|
||||||
|
/* ** Definitions ** */
|
||||||
|
#define EXP_MAX_PLAYER_LEVEL ( 100 )
|
||||||
|
|
||||||
|
/* ** Constants ** */
|
||||||
|
enum E_LEVELS {
|
||||||
|
E_LAW_ENFORCEMENT,
|
||||||
|
E_DEATHMATCH,
|
||||||
|
E_ROBBERY,
|
||||||
|
// E_FIREMAN,
|
||||||
|
// E_HITMAN,
|
||||||
|
// E_BURGLAR,
|
||||||
|
// E_TERRORIST,
|
||||||
|
// E_CAR_JACKER,
|
||||||
|
// E_DRUG_PRODUCTION
|
||||||
|
};
|
||||||
|
|
||||||
|
enum E_LEVEL_DATA {
|
||||||
|
E_LEVELS: E_LEVEL, Float: E_MAX_UNITS
|
||||||
|
};
|
||||||
|
|
||||||
|
static const
|
||||||
|
g_levelData[ ] [ E_LEVEL_DATA ] =
|
||||||
|
{
|
||||||
|
// Level Requirement For Level 100
|
||||||
|
{ E_LAW_ENFORCEMENT, 25000.0 },
|
||||||
|
{ E_DEATHMATCH, 200000.0 },
|
||||||
|
{ E_ROBBERY, 100000.0 }
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
/* ** Variables ** */
|
||||||
|
new
|
||||||
|
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 ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
stock Float: GetPlayerTotalExperience( playerid ) {
|
||||||
|
new
|
||||||
|
Float: experience = 0.0;
|
||||||
|
|
||||||
|
for ( new l = 0; l < sizeof ( g_levelData ); l ++ ) {
|
||||||
|
experience += g_playerExperience[ playerid ] [ E_LEVELS: l ];
|
||||||
|
}
|
||||||
|
return experience;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ** Hooks ** */
|
||||||
|
hook OnPlayerDisconnect( playerid, reason ) {
|
||||||
|
for ( new l = 0; l < sizeof ( g_levelData ); l ++ ) {
|
||||||
|
g_playerExperience[ playerid ] [ E_LEVELS: l ] = 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hook OnPlayerLogin( playerid )
|
||||||
|
{
|
||||||
|
mysql_tquery( dbHandle, sprintf( "SELECT * FROM `USER_LEVELS` WHERE `USER_ID` = %d", GetPlayerAccountID( playerid ) ), "Experience_OnLoad", "d", playerid );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ** 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 )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
rows = cache_get_row_count( );
|
||||||
|
|
||||||
|
if ( rows )
|
||||||
|
{
|
||||||
|
for ( new row = 0; row < rows; row ++ )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
level_id = cache_get_field_content_int( row, "LEVEL_ID" );
|
||||||
|
|
||||||
|
// make sure we don't get any deprecated/invalid levels
|
||||||
|
if ( level_id < sizeof ( g_levelData ) ) {
|
||||||
|
g_playerExperience[ playerid ] [ E_LEVELS: level_id ] = cache_get_field_content_float( row, "EXPERIENCE" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ** Migrations ** */
|
||||||
|
/*
|
||||||
|
CREATE TABLE IF NOT EXISTS USER_LEVELS (
|
||||||
|
`USER_ID` int(11),
|
||||||
|
`LEVEL_ID` int(11),
|
||||||
|
`EXPERIENCE` float,
|
||||||
|
PRIMARY KEY (USER_ID, LEVEL_ID),
|
||||||
|
FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
*/
|
@ -104,9 +104,9 @@ hook OnPlayerConnect( playerid ) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hook OnPlayerLogin( playerid, accountid )
|
hook OnPlayerLogin( playerid )
|
||||||
{
|
{
|
||||||
format( szNormalString, sizeof( szNormalString ), "SELECT * FROM `SETTINGS` WHERE `USER_ID`=%d", accountid );
|
format( szNormalString, sizeof( szNormalString ), "SELECT * FROM `SETTINGS` WHERE `USER_ID`=%d", GetPlayerAccountID( playerid ) );
|
||||||
mysql_function_query( dbHandle, szNormalString, true, "OnSettingsLoad", "d", playerid );
|
mysql_function_query( dbHandle, szNormalString, true, "OnSettingsLoad", "d", playerid );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -162,11 +162,11 @@ CMD:passive( playerid, params[ ] )
|
|||||||
|
|
||||||
CMD:passivelist( playerid, params[ ])
|
CMD:passivelist( playerid, params[ ])
|
||||||
{
|
{
|
||||||
new
|
new
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
szBigString[ 0 ] = '\0';
|
szBigString[ 0 ] = '\0';
|
||||||
|
|
||||||
foreach ( new i : Player )
|
foreach ( new i : Player )
|
||||||
{
|
{
|
||||||
if ( IsPlayerPassive( i ) )
|
if ( IsPlayerPassive( i ) )
|
||||||
@ -178,7 +178,7 @@ CMD:passivelist( playerid, params[ ])
|
|||||||
|
|
||||||
if ( count == 0 )
|
if ( count == 0 )
|
||||||
return SendError( playerid, "There is currently no players in passive mode." );
|
return SendError( playerid, "There is currently no players in passive mode." );
|
||||||
else
|
else
|
||||||
return ShowPlayerDialog(playerid, DIALOG_NULL, DIALOG_STYLE_LIST, ""COL_WHITE"Passive List", szBigString, "Close", "" ), 1;
|
return ShowPlayerDialog(playerid, DIALOG_NULL, DIALOG_STYLE_LIST, ""COL_WHITE"Passive List", szBigString, "Close", "" ), 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#pragma option -d3
|
#pragma option -d3
|
||||||
#pragma dynamic 7200000
|
#pragma dynamic 7200000
|
||||||
|
|
||||||
//#define DEBUG_MODE
|
#define DEBUG_MODE
|
||||||
|
|
||||||
#if defined DEBUG_MODE
|
#if defined DEBUG_MODE
|
||||||
#pragma option -d3
|
#pragma option -d3
|
||||||
@ -13302,7 +13302,7 @@ thread OnAttemptPlayerLogin( playerid, password[ ] )
|
|||||||
CheckPlayerVipExpiry( playerid );
|
CheckPlayerVipExpiry( playerid );
|
||||||
|
|
||||||
// Load other player related variables
|
// Load other player related variables
|
||||||
CallLocalFunction( "OnPlayerLogin", "dd", playerid, p_AccountID[ playerid ] );
|
CallLocalFunction( "OnPlayerLogin", "d", playerid );
|
||||||
|
|
||||||
// Load some more linking tables
|
// Load some more linking tables
|
||||||
format( szNormalString, sizeof( szNormalString ), "SELECT * FROM `EMAILS` WHERE `USER_ID`=%d", p_AccountID[ playerid ] );
|
format( szNormalString, sizeof( szNormalString ), "SELECT * FROM `EMAILS` WHERE `USER_ID`=%d", p_AccountID[ playerid ] );
|
||||||
|
Loading…
Reference in New Issue
Block a user