viewing paste @pvpmode | 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 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
#include "common/hercules.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "map/pc.h"
#include "common/memmgr.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
    "pkonoff", // 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)
};
 
int config_delay = 5; // After turn pk on/off, how many seconds delay before the player allow to pk on/off ?
 
struct player_data {
    unsigned int pkmode :1;
    int pkmode_delay;
};
 
ACMD(pvpmode) {
    struct player_data *ssd;
    char output[CHAT_SIZE_MAX];
    if ( !( ssd = getFromMSD(sd,0) ) ) {
        CREATE( ssd, struct player_data, 1 );
        ssd->pkmode = 0;
        addToMSD( sd, ssd, 0, true );
    }
    if ( !map->list[sd->bl.m].flag.town ) {
        clif->message( sd->fd, "You can only change your PK state in towns.");
        return false;
    }
    if ( pc_isdead(sd) ) { //Disable @pvpmode when player is dead
        clif->message( sd->fd, "No puedes usar este comando estando muerto.");
        return false;
        }
    if ( ssd->pkmode_delay + config_delay > (int)time(NULL) ) {
        safesnprintf( output, CHAT_SIZE_MAX, "You must wait %d seconds before using this command again.", ssd->pkmode_delay + config_delay - (int)time(NULL) );
        clif->message( sd->fd, output );
        return false;
    }
    if ( !ssd->pkmode ) {
        
        clif->message( sd->fd, "Your PK state is now ON" );
        pc->setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, (clr_type)CLR_RESPAWN);
        pc_setglobalreg(sd, script->add_str("USERAURA"), 586);
        ssd->pkmode = 1;
    } else {
        ssd->pkmode = 0;
        clif->message( sd->fd, "Your PK state is now OFF" );
        pc->setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, (clr_type)CLR_RESPAWN);
        pc_setglobalreg(sd, script->add_str("USERAURA"), -1);
    }
    ssd->pkmode_delay = (int)time(NULL);
    return true;
}
 
int battle_check_target_post( int retVal, struct block_list *src, struct block_list *target, int *flag ) {
    if ( retVal != 1 && src->type == BL_PC && target->type == BL_PC ) {
        struct player_data *src_pc = getFromMSD( (TBL_PC*)src, 0 );
        struct player_data *target_pc = getFromMSD( (TBL_PC*)target, 0 );
        if ( src_pc != NULL && target_pc != NULL )
            if ( src_pc->pkmode && target_pc->pkmode )
                return 1;
    }
    return retVal;
}
//===========================================================
//              Disable Aura PvP Mode when player quit
//===========================================================
int map_quit_prepk( struct map_session_data *sd ) {
    struct player_data *ssd;
    if (( ssd = getFromMSD(sd,0) ))
        if ( ssd->pkmode)
            pc_setglobalreg(sd, script->add_str("USERAURA"), -1);
    return 0;
}
//===========================================================
//               Disable PvP Mode/Aura when player die 
//===========================================================
 
int pc_dead_prepk( struct map_session_data *sd ) {
    struct player_data *ssd;
    if (( ssd = getFromMSD(sd,0) ))
        if ( ssd->pkmode) {
            ssd->pkmode = 0;
            pc_setglobalreg(sd, script->add_str("USERAURA"), -1);
            pc->setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, (clr_type)CLR_RESPAWN);
            status_kill(&sd->bl);   
            clif->message( sd->fd, "Your PK state is now OFF" );
            }
    return 0;
}
//===========================================================
//   Prevents the player abandon pvpmode when receiving damage
//===========================================================
int pc_damage_receivedpk(struct map_session_data *sd,struct block_list *src,unsigned int hp, unsigned int sp){
    struct player_data *ssd;
    if (( ssd = getFromMSD(sd,0) ))
        if ( ssd->pkmode)
    ssd->pkmode_delay = (int)time(NULL);    
    return 0;
    
}
//===========================================================
//   Disable Teleport/Warp/Go when player is in PvP Mode
//===========================================================
int pc_setpos_delaypk(struct map_session_data* sd, unsigned short *map_index, int *x, int *y, clr_type *clrtype) {
    int16 m;
    struct player_data *ssd;
    unsigned short mapindex_ = *map_index;
 
    if (!sd)
        return 0;
 
    if( !mapindex_ || !mapindex_id2name(mapindex_) || ( m = map->mapindex2mapid(mapindex_) ) == -1 ) {
        ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex_);
        return 1;
    }
    if( !(ssd = getFromMSD(sd,0)) ) {
        return 0;
    }
    if ( ssd->pkmode) {
        clif->message( sd->fd, "No puedes teletransportarte en PvP Mode" );
        hookStop();
    }
    return 0;
}
HPExport void plugin_init (void) {
    addAtcommand("pvpmode",pvpmode);
    addHookPost( "battle->check_target", battle_check_target_post );
    addHookPre( "map->quit", map_quit_prepk );
    addHookPre( "pc->dead", pc_dead_prepk );
    addHookPre("pc->damage",pc_damage_receivedpk);
    addHookPre("pc->setpos",pc_setpos_delaypk);
 
    
}
Viewed 988 times, submitted by Guest.