viewing paste topic/11587- maxlvexpgain_1.2 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
//===== Hercules Plugin ======================================
//= Maximum Level Exp Gain
//===== By: ==================================================
//= AnnieRuru
//===== Current Version: =====================================
//= 1.2
//===== Compatible With: =====================================
//= Hercules 2016-1-1
//===== Description: =========================================
//= stop players from gaining exp after certain level
//===== Topic ================================================
//= http://herc.ws/board/topic/11587-maxlvexpgain/
//===== Additional Comments: =================================
//= this plugin DOES
//= 1. stop players gain exp through killing monsters, mvp exp, or share party experience
//= 2. allows to gain exp by *getexp script command or BaseExp++ / JobExp++
//= 3. allows players to pay guild tax exp after they hit your capped level value
//= 4. if your server has heal_exp, resurrection_exp or shop_exp enable,
//=    they will stop gain exp from these action after they hit your cap level
//= 5. if the player do SA_LEVELUP ( a random skill from Hocos-Pocus ) after the cap level, they can't gain exp, or pay guild tax using this skill
//= ... it seems like SA_LEVELUP skill and guild->payexp hate each other ...
//============================================================
 
#include "common/hercules.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "map/pc.h"
#include "common/memmgr.h"
#include "common/nullpo.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
        "MaxLvExpGain",
        SERVER_TYPE_MAP,
        "1.2",
        HPM_VERSION,
};
 
int max_blv_exp_gain = 5; // when player reach this BaseLevel, they stop gain BaseExp
int max_jlv_exp_gain = 5; // when player reach this JobLevel, they stop gain JobExp
 
struct player_data {
        bool nobaseexpgain;
        bool nojobexpgain;
};
 
void battle_config_setting( const char *key, const char *val ) {
        if ( !strcmpi( key, "max_blv_exp_gain" ) )
                max_blv_exp_gain = atoi(val);
        else if ( !strcmpi( key, "max_jlv_exp_gain" ) )
                max_jlv_exp_gain = atoi(val);
}
 
int return_battle_config( const char *key ) {
        if ( !strcmpi( key, "max_blv_exp_gain" ) )
                return max_blv_exp_gain;
        else if ( !strcmpi( key, "max_jlv_exp_gain" ) )
                return max_jlv_exp_gain;
        return 0;
}
 
bool pc_gainexp_pre( struct map_session_data *sd, struct block_list *src, unsigned int *base_exp, unsigned int *job_exp, bool *is_quest ) {
        nullpo_ret(sd);
        if ( *is_quest == false ) {
                struct player_data *ssd = getFromMSD( sd, 0 );
                if ( !ssd ) {
                        CREATE( ssd, struct player_data, 1 );
                        ssd->nobaseexpgain = 0;
                        ssd->nojobexpgain = 0;
                        addToMSD( sd, ssd, 0, true );
                }
                if ( (int)sd->status.base_level >= max_blv_exp_gain ) {
                        if ( !src )
                                *base_exp = 0;
                        else
                                ssd->nobaseexpgain = 1;
                }
                if ( (int)sd->status.job_level >= max_jlv_exp_gain ) {
                        if ( !src )
                                *job_exp = 0;
                        else
                                ssd->nojobexpgain = 1;
                }
        }
        return true;
}
 
void pc_calcexp_post( struct map_session_data *sd, unsigned int *base_exp, unsigned int *job_exp, struct block_list *src ) {
        struct player_data *ssd = getFromMSD( sd, 0 );
        nullpo_retv(ssd);
        if ( ssd->nobaseexpgain ) {
                *base_exp = 0;
                ssd->nobaseexpgain = 0;
        }
        if ( ssd->nojobexpgain ) {
                *job_exp = 0;
                ssd->nojobexpgain = 0;
        }
        return;
}
 
HPExport void server_preinit (void) {
        addBattleConf( "max_blv_exp_gain", battle_config_setting, return_battle_config );
        addBattleConf( "max_jlv_exp_gain", battle_config_setting, return_battle_config );
}
 
HPExport void plugin_init (void) {
        addHookPre( "pc->gainexp", pc_gainexp_pre );
        addHookPost( "pc->calcexp", pc_calcexp_post );
}
Viewed 1023 times, submitted by AnnieRuru.