Skip to content
Permalink
Browse files
Implemented suggestion "Script Command to block commands" http://rath…
…ena.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>
  • Loading branch information
cydh committed Jan 27, 2014
1 parent 5988c7a commit 03108701c00a8ab79d9c8b80805196fe353819db
Showing with 51 additions and 7 deletions.
  1. +4 −1 conf/battle/gm.conf
  2. +9 −0 doc/script_commands.txt
  3. +4 −0 src/map/atcommand.c
  4. +1 −0 src/map/battle.c
  5. +1 −0 src/map/battle.h
  6. +4 −6 src/map/clif.c
  7. +1 −0 src/map/pc.h
  8. +26 −0 src/map/script.c
  9. +1 −0 src/map/script.h
@@ -30,4 +30,7 @@ ban_hack_trade: 5
// modifies @mobinfo to display the users' real drop rate as per renewal_drop formula
// 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
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

This comment has been minimized.

Copy link
@aleos89

aleos89 Jan 27, 2014

Contributor

Wouldn't it be better to make this a group permission rather than a battle_config?

This comment has been minimized.

Copy link
@cydh

cydh Jan 27, 2014

Author Contributor

ahh rite, I'll make it later. or will u make it? haha

@@ -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
@@ -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;
@@ -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
/**
@@ -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);
@@ -10604,9 +10604,8 @@ 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)
return;
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
else if (pc_cant_act2(sd))
@@ -10650,9 +10649,8 @@ void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
return;
}

if (sd->npc_id) {
if (!sd->npc_item_flag)
return;
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
else if (pc_cant_act2(sd))
@@ -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;
@@ -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"

@@ -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 {

0 comments on commit 0310870

Please sign in to comment.