viewing paste topic/11004- pkmode.c | Athena

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
#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(pk) {
    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 ( 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 ) {
        ssd->pkmode = 1;
        clif->message( sd->fd, "Your PK state is now ON" );
    } else {
        ssd->pkmode = 0;
        clif->message( sd->fd, "Your PK state is now OFF" );
    }
    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;
}
 
HPExport void plugin_init (void) {
    addAtcommand("pk",pk);
    addHookPost( "battle->check_target", battle_check_target_post );
}
Viewed 1424 times, submitted by AnnieRuru.