Skip to content
Permalink
Browse files

Added several warning messages (#4062)

* enablenpc / disablenpc / hideoffnpc / hideonnpc now display the npc source when the npc named doesn't exist
* Added the NPC source to status_set_viewdata when no view data has been found
* Added export_deprecated_constant3 to display the constant name replacing the deprecated
* Removed the debug message from `@ warp` when the map name is wrong
* Added clif_name_area to UMOB_LEVEL on setunitdata and a capvalue to UPET_HUNGER
* areamonster now checks if the monster ID exists

Thanks to @Normynator and @aleos89 for the review!
  • Loading branch information...
Atemo committed Apr 10, 2019
1 parent c772262 commit 9aa5f7d8345d9d89ec9e8b44060e92703f3d43b8
Showing with 153 additions and 130 deletions.
  1. +2 −1 src/common/mapindex.cpp
  2. +2 −2 src/map/atcommand.cpp
  3. +3 −3 src/map/npc.cpp
  4. +1 −1 src/map/npc.hpp
  5. +38 −24 src/map/script.cpp
  6. +2 −1 src/map/script.hpp
  7. +98 −97 src/map/script_constants.hpp
  8. +7 −1 src/map/status.cpp
@@ -115,7 +115,8 @@ unsigned short mapindex_name2idx(const char* name, const char *func) {
if( (i = strdb_iget(mapindex_db, map_name)) )
return i;

ShowDebug("(%s) mapindex_name2id: Map \"%s\" not found in index list!\n", func, map_name);
if (func)
ShowDebug("(%s) mapindex_name2id: Map \"%s\" not found in index list!\n", func, map_name);
return 0;
}

@@ -504,11 +504,11 @@ ACMD_FUNC(mapmove)
return -1;
}

mapindex = mapindex_name2id(map_name);
mapindex = mapindex_name2idx(map_name, nullptr);
if (mapindex)
m = map_mapindex2mapid(mapindex);

if (!mapindex) { // m < 0 means on different server! [Kevin]
if (m < 0) { // m < 0 means on different server! [Kevin]
clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.

if (battle_config.warp_suggestions_enabled)
@@ -233,14 +233,14 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
/*==========================================
* Disable / Enable NPC
*------------------------------------------*/
int npc_enable(const char* name, int flag)
bool npc_enable(const char* name, int flag)
{
struct npc_data* nd = npc_name2id(name);

if (nd==NULL)
{
ShowError("npc_enable: Attempted to %s a non-existing NPC '%s' (flag=%d).\n", (flag&3) ? "show" : "hide", name, flag);
return 0;
return false;
}

if (flag&1) {
@@ -267,7 +267,7 @@ int npc_enable(const char* name, int flag)
if( flag&3 && (nd->u.scr.xs >= 0 || nd->u.scr.ys >= 0) )// check if player standing on a OnTouchArea
map_foreachinallarea( npc_enable_sub, nd->bl.m, nd->bl.x-nd->u.scr.xs, nd->bl.y-nd->u.scr.ys, nd->bl.x+nd->u.scr.xs, nd->bl.y+nd->u.scr.ys, BL_PC, nd );

return 0;
return true;
}

/*==========================================
@@ -1203,7 +1203,7 @@ const char *npc_get_script_event_name(int npce_index);
void npc_setcells(struct npc_data* nd);
void npc_unsetcells(struct npc_data* nd);
bool npc_movenpc(struct npc_data* nd, int16 x, int16 y);
int npc_enable(const char* name, int flag);
bool npc_enable(const char* name, int flag);
void npc_setdisplayname(struct npc_data* nd, const char* newname);
void npc_setclass(struct npc_data* nd, short class_);
struct npc_data* npc_name2id(const char* name);
@@ -210,8 +210,9 @@ static struct str_data_struct {
int (*func)(struct script_state *st);
int val;
int next;
const char *name;
bool deprecated;
} *str_data = NULL;
} *str_data = nullptr;
static int str_data_size = 0; // size of the data
static int str_num = LABEL_START; // next id to be assigned

@@ -481,13 +482,12 @@ static void script_dump_stack(struct script_state* st)
/// Reports on the console the src of a script error.
static void script_reportsrc(struct script_state *st)
{
struct block_list* bl;

if( st->oid == 0 )
return; //Can't report source.

bl = map_id2bl(st->oid);
if( bl == NULL )
struct block_list* bl = map_id2bl(st->oid);

if (!bl)
return;

switch( bl->type ) {
@@ -1366,6 +1366,8 @@ const char* parse_simpleexpr(const char *p)
if( str_data[l].type == C_INT && str_data[l].deprecated ){
ShowWarning( "Usage of deprecated constant '%s'.\n", get_str(l) );
ShowWarning( "This constant was deprecated and could become unavailable anytime soon.\n" );
if (str_data[l].name)
ShowWarning( "Please use '%s' instead!\n", str_data[l].name );
}
#endif

@@ -2303,14 +2305,16 @@ bool script_get_constant(const char* name, int* value)
if( str_data[n].deprecated ){
ShowWarning( "Usage of deprecated constant '%s'.\n", name );
ShowWarning( "This constant was deprecated and could become unavailable anytime soon.\n" );
if (str_data[n].name)
ShowWarning( "Please use '%s' instead!\n", str_data[n].name );
}
#endif

return true;
}

/// Creates new constant or parameter with given value.
void script_set_constant(const char* name, int value, bool isparameter, bool deprecated)
void script_set_constant_(const char* name, int value, const char* constant_name, bool isparameter, bool deprecated)
{
int n = add_str(name);

@@ -2319,6 +2323,7 @@ void script_set_constant(const char* name, int value, bool isparameter, bool dep
str_data[n].type = isparameter ? C_PARAM : C_INT;
str_data[n].val = value;
str_data[n].deprecated = deprecated;
str_data[n].name = constant_name;
}
else if( str_data[n].type == C_PARAM || str_data[n].type == C_INT )
{// existing parameter or constant
@@ -10353,6 +10358,11 @@ BUILDIN_FUNC(areamonster)
}
}

if (class_ >= 0 && !mobdb_checkid(class_)) {
ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
return SCRIPT_CMD_FAILURE;
}

sd = map_id2sd(st->rid);

if (sd && strcmp(mapn, "this") == 0)
@@ -11255,39 +11265,43 @@ BUILDIN_FUNC(getareadropitem)
*------------------------------------------*/
BUILDIN_FUNC(enablenpc)
{
const char *str;
str=script_getstr(st,2);
npc_enable(str,1);
return SCRIPT_CMD_SUCCESS;
const char *str = script_getstr(st,2);
if (npc_enable(str,1))
return SCRIPT_CMD_SUCCESS;

return SCRIPT_CMD_FAILURE;
}

/*==========================================
*------------------------------------------*/
BUILDIN_FUNC(disablenpc)
{
const char *str;
str=script_getstr(st,2);
npc_enable(str,0);
return SCRIPT_CMD_SUCCESS;
const char *str = script_getstr(st,2);
if (npc_enable(str,0))
return SCRIPT_CMD_SUCCESS;

return SCRIPT_CMD_FAILURE;
}

/*==========================================
*------------------------------------------*/
BUILDIN_FUNC(hideoffnpc)
{
const char *str;
str=script_getstr(st,2);
npc_enable(str,2);
return SCRIPT_CMD_SUCCESS;
const char *str = script_getstr(st,2);
if (npc_enable(str,2))
return SCRIPT_CMD_SUCCESS;

return SCRIPT_CMD_FAILURE;
}
/*==========================================
*------------------------------------------*/
BUILDIN_FUNC(hideonnpc)
{
const char *str;
str=script_getstr(st,2);
npc_enable(str,4);
return SCRIPT_CMD_SUCCESS;
const char *str = script_getstr(st,2);
if (npc_enable(str,4))
return SCRIPT_CMD_SUCCESS;

return SCRIPT_CMD_FAILURE;
}

/* Starts a status effect on the target unit or on the attached player.
@@ -17756,7 +17770,7 @@ BUILDIN_FUNC(setunitdata)

switch (type) {
case UMOB_SIZE: md->status.size = md->base_status->size = (unsigned char)value; break;
case UMOB_LEVEL: md->level = (unsigned short)value; break;
case UMOB_LEVEL: md->level = (unsigned short)value; clif_name_area(&md->bl); break;
case UMOB_HP: md->base_status->hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break;
case UMOB_MAXHP: md->base_status->hp = md->base_status->max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break;
case UMOB_MASTERAID: md->master_id = value; break;
@@ -17909,7 +17923,7 @@ BUILDIN_FUNC(setunitdata)
case UPET_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break;
case UPET_X: if (!unit_walktoxy(bl, (short)value, pd->bl.y, 2)) unit_movepos(bl, (short)value, md->bl.y, 0, 0); break;
case UPET_Y: if (!unit_walktoxy(bl, pd->bl.x, (short)value, 2)) unit_movepos(bl, pd->bl.x, (short)value, 0, 0); break;
case UPET_HUNGER: pd->pet.hungry = (short)value; clif_send_petdata(map_id2sd(pd->pet.account_id), pd, 2, pd->pet.hungry); break;
case UPET_HUNGER: pd->pet.hungry = cap_value((short)value, 0, 100); clif_send_petdata(map_id2sd(pd->pet.account_id), pd, 2, pd->pet.hungry); break;
case UPET_INTIMACY: pet_set_intimate(pd, (unsigned int)value); clif_send_petdata(map_id2sd(pd->pet.account_id), pd, 1, pd->pet.intimate); break;
case UPET_SPEED: pd->status.speed = (unsigned short)value; status_calc_misc(bl, &pd->status, pd->pet.level); break;
case UPET_LOOKDIR: unit_setdir(bl, (uint8)value); break;
@@ -1959,7 +1959,8 @@ void script_run_autobonus(const char *autobonus, struct map_session_data *sd, un
const char* script_get_constant_str(const char* prefix, int64 value);
bool script_get_parameter(const char* name, int* value);
bool script_get_constant(const char* name, int* value);
void script_set_constant(const char* name, int value, bool isparameter, bool deprecated);
void script_set_constant_(const char* name, int value, const char* constant_name, bool isparameter, bool deprecated);
#define script_set_constant(name, value, isparameter, deprecated) script_set_constant_(name, value, NULL, isparameter, deprecated)
void script_hardcoded_constants(void);

void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
Oops, something went wrong.

0 comments on commit 9aa5f7d

Please sign in to comment.
You can’t perform that action at this time.