viewing paste Unknown #49953 | Text

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/*
 Based on pkmode src
 */
 
/// Sample Hercules Plugin
 
#include "common/hercules.h" /* Should always be the first Hercules file included! (if you don't make it first, you won't be able to use interfaces) */
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/socket.h"
#include "common/strlib.h"
#include "common/nullpo.h"
#include "common/timer.h"
#include "map/clif.h"
#include "map/pc.h"
#include "map/battle.h"
#include "map/script.h"
 
#include "common/HPMDataCheck.h" /* should always be the last Hercules file included! (if you don't make it last, it'll intentionally break compile time) */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
HPExport struct hplugin_info pinfo = {
    "Pkmode",    // Plugin name
    SERVER_TYPE_MAP,// Which server types this plugin works with?
    "0.1",       // Plugin version
    HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
};
 
struct pkmode_data_struct {
    struct {
        unsigned int pk_mode : 1;
    } state;
    int64 pk_mode_tick;
};
 
struct Battle_Config battle_config;
 
int pc_setnewpc_post(int retVal, struct map_session_data *sd, int *account_id, int *char_id, int *login_id1, unsigned int *client_tick, int *sex, int *fd)
{
    struct pkmode_data_struct *pksd;
 
    if (!(pksd = getFromMSD(sd, 0))) {
        CREATE(pksd, struct pkmode_data_struct, 1);
        pksd->pk_mode_tick = timer->gettick();
        addToMSD(sd, pksd, 0, true);
    }
 
    return retVal;
}
 
 
ACMD(pkmode) {
        struct pkmode_data_struct *pksd;
        int64 tick;
 
        if (!(pksd = getFromMSD(sd, 0))) {
            return 0;
        }
    
        tick = timer->gettick();
    
        nullpo_retr(-1, sd);
        nullpo_retr(-1, pksd);
    
        if (map->list[sd->bl.m].flag.pvp || map->list[sd->bl.m].flag.gvg || map->list[sd->bl.m].flag.gvg_castle || map->list[sd->bl.m].flag.gvg_dungeon) {
        clif->message(sd->fd, "You can only change your PK state on non-PVP maps.");
        return false;
        
    }
    
        if (DIFF_TICK(pksd->pk_mode_tick, tick) > 0) { //check the delay before use this command again
        clif->message(sd->fd, "You cannot turn OFF your PK state twice within just 15 minutes.");
        return false;
        
    }
    else {
        if (!pksd->state.pk_mode) {
            pksd->state.pk_mode = 1;
            clif->message(sd->fd, "Your PK state is now OFF");
            pksd->pk_mode_tick = tick + 0; //set the delay here
            
        }
        else {
            pksd->state.pk_mode = 0;
            clif->message(sd->fd, "Your PK state is now ON");
            pksd->pk_mode_tick = tick + 1500000; //set the delay here
            
        }
        
    }
    return true;
    
}
 
int battle_check_target_post(int retVal, struct block_list *src, struct block_list *target, int flag)
{
    struct block_list *s_bl = src, *t_bl = target;
    struct pkmode_data_struct *pksd;
    int16 m; //map
    if (retVal <= 0) return retVal; // Don't do anything
    if (s_bl->type != BL_PC && s_bl->type != BL_SKILL) return retVal;
 
 
    nullpo_ret(src);
    nullpo_ret(target);
 
    
 
    m = target->m;
    if ((t_bl = battle->get_master(target)) == NULL)
        t_bl = target;
 
    if ((s_bl = battle->get_master(src)) == NULL)
        s_bl = src;
 
 
    switch (t_bl->type)
    {
        case BL_PC:
        {
            const struct map_session_data *sd = BL_UCCAST(BL_PC, t_bl);
 
            if (!(pksd = getFromMSD(sd, 0))) {
                return 0;
            }
 
            switch (battle->get_current_skill(src)) {
                case SN_WINDWALK: // add more like this for other skills with same issue
                    return retVal;
            }
 
            if (t_bl == s_bl)
                break;
 
 
            if (map->list[m].flag.pvp && pksd->state.pk_mode && s_bl->type != BL_MOB)
                return 0;
        }
    }
 
    switch(s_bl->type)
    {
        case BL_PC:
        {
            const struct map_session_data *sd = BL_UCCAST(BL_PC, s_bl);
 
            if (!(pksd = getFromMSD(sd, 0))) {
                return 0;
            }
 
            if (s_bl != t_bl) {
                if (map->list[m].flag.pvp && pksd->state.pk_mode && t_bl->type != BL_MOB)
                    return 0;
            }
        }
 
    }
    return retVal;;
 
}
 
 
// pc.h stuffs here
// learn how to append to structs.
 
/* run when server starts */
HPExport void plugin_init (void) {
 
    addAtcommand("pk",pkmode);//link our '@sample' command
 
    addHookPost("pc->setnewpc", pc_setnewpc_post);
 
    addHookPost("battle->check_target", battle_check_target_post);
 
}
Viewed 3715 times, submitted by Begin.