Skip to content

Commit

Permalink
Added several warning messages (#4062)
Browse files Browse the repository at this point in the history
* 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 9aa5f7d
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 130 deletions.
3 changes: 2 additions & 1 deletion src/common/mapindex.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ unsigned short mapindex_name2idx(const char* name, const char *func) {
if( (i = strdb_iget(mapindex_db, map_name)) ) if( (i = strdb_iget(mapindex_db, map_name)) )
return i; 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; return 0;
} }


Expand Down
4 changes: 2 additions & 2 deletions src/map/atcommand.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ ACMD_FUNC(mapmove)
return -1; return -1;
} }


mapindex = mapindex_name2id(map_name); mapindex = mapindex_name2idx(map_name, nullptr);
if (mapindex) if (mapindex)
m = map_mapindex2mapid(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. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.


if (battle_config.warp_suggestions_enabled) if (battle_config.warp_suggestions_enabled)
Expand Down
6 changes: 3 additions & 3 deletions src/map/npc.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
/*========================================== /*==========================================
* Disable / Enable NPC * 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); struct npc_data* nd = npc_name2id(name);


if (nd==NULL) if (nd==NULL)
{ {
ShowError("npc_enable: Attempted to %s a non-existing NPC '%s' (flag=%d).\n", (flag&3) ? "show" : "hide", name, flag); 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) { if (flag&1) {
Expand All @@ -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 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 ); 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;
} }


/*========================================== /*==========================================
Expand Down
2 changes: 1 addition & 1 deletion src/map/npc.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ const char *npc_get_script_event_name(int npce_index);
void npc_setcells(struct npc_data* nd); void npc_setcells(struct npc_data* nd);
void npc_unsetcells(struct npc_data* nd); void npc_unsetcells(struct npc_data* nd);
bool npc_movenpc(struct npc_data* nd, int16 x, int16 y); 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_setdisplayname(struct npc_data* nd, const char* newname);
void npc_setclass(struct npc_data* nd, short class_); void npc_setclass(struct npc_data* nd, short class_);
struct npc_data* npc_name2id(const char* name); struct npc_data* npc_name2id(const char* name);
Expand Down
62 changes: 38 additions & 24 deletions src/map/script.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ static struct str_data_struct {
int (*func)(struct script_state *st); int (*func)(struct script_state *st);
int val; int val;
int next; int next;
const char *name;
bool deprecated; bool deprecated;
} *str_data = NULL; } *str_data = nullptr;
static int str_data_size = 0; // size of the data static int str_data_size = 0; // size of the data
static int str_num = LABEL_START; // next id to be assigned static int str_num = LABEL_START; // next id to be assigned


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

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


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


switch( bl->type ) { switch( bl->type ) {
Expand Down Expand Up @@ -1366,6 +1366,8 @@ const char* parse_simpleexpr(const char *p)
if( str_data[l].type == C_INT && str_data[l].deprecated ){ if( str_data[l].type == C_INT && str_data[l].deprecated ){
ShowWarning( "Usage of deprecated constant '%s'.\n", get_str(l) ); ShowWarning( "Usage of deprecated constant '%s'.\n", get_str(l) );
ShowWarning( "This constant was deprecated and could become unavailable anytime soon.\n" ); 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 #endif


Expand Down Expand Up @@ -2303,14 +2305,16 @@ bool script_get_constant(const char* name, int* value)
if( str_data[n].deprecated ){ if( str_data[n].deprecated ){
ShowWarning( "Usage of deprecated constant '%s'.\n", name ); ShowWarning( "Usage of deprecated constant '%s'.\n", name );
ShowWarning( "This constant was deprecated and could become unavailable anytime soon.\n" ); 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 #endif


return true; return true;
} }


/// Creates new constant or parameter with given value. /// 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); int n = add_str(name);


Expand All @@ -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].type = isparameter ? C_PARAM : C_INT;
str_data[n].val = value; str_data[n].val = value;
str_data[n].deprecated = deprecated; 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 ) else if( str_data[n].type == C_PARAM || str_data[n].type == C_INT )
{// existing parameter or constant {// existing parameter or constant
Expand Down Expand Up @@ -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); sd = map_id2sd(st->rid);


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


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


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


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


switch (type) { switch (type) {
case UMOB_SIZE: md->status.size = md->base_status->size = (unsigned char)value; break; 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_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_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; case UMOB_MASTERAID: md->master_id = value; break;
Expand Down Expand Up @@ -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_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_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_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_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_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; case UPET_LOOKDIR: unit_setdir(bl, (uint8)value); break;
Expand Down
3 changes: 2 additions & 1 deletion src/map/script.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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); const char* script_get_constant_str(const char* prefix, int64 value);
bool script_get_parameter(const char* name, int* value); bool script_get_parameter(const char* name, int* value);
bool script_get_constant(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_hardcoded_constants(void);


void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value); void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
Expand Down
Loading

0 comments on commit 9aa5f7d

Please sign in to comment.