Implemented suggestion "Script Command to block commands" http://rathena.org/board/topic/88888-script-command-to-block-commands/

-- Added new script commands: 'enable_command', 'disable_command'
-- Added new config 'atcommand_enable_npc' at conf/battle/gm.conf
-- Thank Kichi for the patch file

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
This commit is contained in:
Cydh Ramdh 2014-01-27 19:34:29 +07:00
parent 5988c7ab6d
commit 03108701c0
9 changed files with 51 additions and 7 deletions

View File

@ -31,3 +31,6 @@ ban_hack_trade: 5
// modifies @iteminfo to not display the minimum item drop rate (since it can't tell the mob level)
// modifies @whodrops to display the users' real drop rate as per renewal_drop formula
atcommand_mobinfo_type: 1
// Only group with level more than or equal this value can use atcommand while talking with NPC.
atcommand_enable_npc: 0

View File

@ -4764,6 +4764,15 @@ Example:
// Item Universal_Catalog_Gold (10 uses, effect: open shop)
searchstores 10,1;
---------------------------------------
*enable_command;
*disable_command;
These commands toggle the ability to use atcommand while interacting with an NPC.
The default setting, 'atcommand_enable_npc', is defined in 'conf/battle/gm.conf'.
---------------------------------------
//
4,1.- End of item-related commands

View File

@ -9717,6 +9717,10 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
if ( !message || !*message )
return false;
//If cannot use atcomamnd while talking with NPC [Kichi]
if (sd->npc_id && sd->state.disable_atcommand_on_npc)
return false;
//Block NOCHAT but do not display it as a normal message
if ( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCOMMAND )
return true;

View File

@ -7346,6 +7346,7 @@ static const struct _battle_data {
{ "feature.autotrade_sit", &battle_config.feature_autotrade_sit, 1, 0, 1, },
{ "disp_serverbank_msg", &battle_config.disp_serverbank_msg, 0, 0, 1, },
{ "warg_can_falcon", &battle_config.warg_can_falcon, 0, 0, 1, },
{ "atcommand_enable_npc", &battle_config.atcommand_enable_npc, 0, 0, 100, },
};
#ifndef STATS_OPT_OUT
/**

View File

@ -529,6 +529,7 @@ extern struct Battle_Config
int disp_serverbank_msg;
int warg_can_falcon;
int atcommand_enable_npc;
} battle_config;
void do_init_battle(void);

View File

@ -10604,8 +10604,7 @@ void clif_parse_EquipItem(int fd,struct map_session_data *sd)
if (index < 0 || index >= MAX_INVENTORY)
return; //Out of bounds check.
if(sd->npc_id) {
if (!sd->npc_item_flag)
if(sd->npc_id && !sd->npc_item_flag) {
return;
} else if (sd->state.storage_flag || sd->sc.opt1)
; //You can equip/unequip stuff while storage is open/under status changes
@ -10650,8 +10649,7 @@ void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
return;
}
if (sd->npc_id) {
if (!sd->npc_item_flag)
if (sd->npc_id && !sd->npc_item_flag) {
return;
} else if (sd->state.storage_flag || sd->sc.opt1)
; //You can equip/unequip stuff while storage is open/under status changes

View File

@ -208,6 +208,7 @@ struct map_session_data {
unsigned int permanent_speed : 1; // When 1, speed cannot be changed through status_calc_pc().
unsigned int banking : 1; //1 when we using the banking system 0 when closed
unsigned int hpmeter_visible : 1;
bool disable_atcommand_on_npc; //Prevent to use atcommand while talking with NPC [Kichi]
} state;
struct {
unsigned char no_weapon_damage, no_magic_damage, no_misc_damage;

View File

@ -3077,6 +3077,7 @@ struct script_state* script_alloc_state(struct script_code* script, int pos, int
st->oid = oid;
st->sleep.timer = INVALID_TIMER;
st->npc_item_flag = battle_config.item_enabled_npc;
st->atcommand_enable_npc = battle_config.atcommand_enable_npc;
return st;
}
@ -3701,6 +3702,7 @@ static void script_attach_state(struct script_state* st)
sd->st = st;
sd->npc_id = st->oid;
sd->npc_item_flag = st->npc_item_flag; // load default.
sd->state.disable_atcommand_on_npc = (pc_get_group_level(sd) >= st->atcommand_enable_npc) ? false : true;
#ifdef SECURE_NPCTIMEOUT
if( sd->npc_idle_timer == INVALID_TIMER )
sd->npc_idle_timer = add_timer(gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0);
@ -18324,6 +18326,28 @@ BUILDIN_FUNC(bonus_script) {
return SCRIPT_CMD_SUCCESS;
}
/** Allows player to use atcommand while talking with NPC
* @author [Cydh], [Kichi] */
BUILDIN_FUNC(enable_command) {
TBL_PC* sd = script_rid2sd(st);
if (!sd)
return SCRIPT_CMD_FAILURE;
sd->state.disable_atcommand_on_npc = false;
return SCRIPT_CMD_SUCCESS;
}
/** Prevents player to use atcommand while talking with NPC
* @author [Cydh], [Kichi] */
BUILDIN_FUNC(disable_command) {
TBL_PC* sd = script_rid2sd(st);
if (!sd)
return SCRIPT_CMD_FAILURE;
sd->state.disable_atcommand_on_npc = true;
return SCRIPT_CMD_SUCCESS;
}
#include "../custom/script.inc"
// declarations that were supposed to be exported from npc_chat.c
@ -18809,6 +18833,8 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(vip_time,"i?"),
BUILDIN_DEF(bonus_script,"si????"),
BUILDIN_DEF(getgroupitem,"i"),
BUILDIN_DEF(enable_command,""),
BUILDIN_DEF(disable_command,""),
#include "../custom/script_def.inc"

View File

@ -134,6 +134,7 @@ struct script_state {
unsigned npc_item_flag : 1;
unsigned mes_active : 1; // Store if invoking character has a NPC dialog box open.
unsigned char* funcname; // Stores the current running function name
uint8 atcommand_enable_npc;
};
struct script_reg {