#include "common/hercules.h" #include #include #include #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); }