summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-02-26 15:10:11 -0300
committershennetsind <ind@henn.et>2014-02-26 15:10:11 -0300
commit0732f55931524c1a2cf703805d61e955c4afea29 (patch)
tree1cebeda0e411870028588f8462357d422ee1dd9e /src/map
parent950e3ebcdbbde96b090fa681ce88ecf4069f2f64 (diff)
downloadhercules-0732f55931524c1a2cf703805d61e955c4afea29.tar.gz
hercules-0732f55931524c1a2cf703805d61e955c4afea29.tar.bz2
hercules-0732f55931524c1a2cf703805d61e955c4afea29.tar.xz
hercules-0732f55931524c1a2cf703805d61e955c4afea29.zip
Improved mapindex_name2id errors for scripts
NPC Error is now printed as well as the original message as proposed by Emistry in http://hercules.ws/board/topic/1864-mapindex-name2id-display-which-npc-caused-this/ Special Thanks to Haru! Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script.c45
-rw-r--r--src/map/script.h1
2 files changed, 31 insertions, 15 deletions
diff --git a/src/map/script.c b/src/map/script.c
index e355db828..03ebb80a3 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -5060,7 +5060,7 @@ BUILDIN(warp)
else if(strcmp(str,"SavePoint")==0 || strcmp(str,"Save")==0)
ret = pc->setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT);
else
- ret = pc->setpos(sd,mapindex->name2id(str),x,y,CLR_OUTSIGHT);
+ ret = pc->setpos(sd,script->mapindexname2id(st,str),x,y,CLR_OUTSIGHT);
if( ret ) {
ShowError("buildin_warp: moving player '%s' to \"%s\",%d,%d failed.\n", sd->status.name, str, x, y);
@@ -5137,7 +5137,7 @@ BUILDIN(areawarp)
if( strcmp(str,"Random") == 0 )
index = 0;
- else if( !(index=mapindex->name2id(str)) )
+ else if( !(index=script->mapindexname2id(st,str)) )
return true;
map->foreachinarea(script->buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3);
@@ -5201,7 +5201,7 @@ BUILDIN(warpchar) {
if(strcmp(str, "SavePoint") == 0)
pc->setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT);
else
- pc->setpos(sd, mapindex->name2id(str), x, y, CLR_TELEPORT);
+ pc->setpos(sd, script->mapindexname2id(st,str), x, y, CLR_TELEPORT);
return true;
}
@@ -5249,7 +5249,7 @@ BUILDIN(warpparty)
y = pl_sd->bl.y;
break;
case 4:
- map_index = mapindex->name2id(str);
+ map_index = script->mapindexname2id(st,str);
break;
case 2:
//"SavePoint" uses save point of the currently attached player
@@ -5347,7 +5347,7 @@ BUILDIN(warpguild)
break;
case 3: // m,x,y
if(!map->list[pl_sd->bl.m].flag.noreturn && !map->list[pl_sd->bl.m].flag.nowarp)
- pc->setpos(pl_sd,mapindex->name2id(str),x,y,CLR_TELEPORT);
+ pc->setpos(pl_sd,script->mapindexname2id(st,str),x,y,CLR_TELEPORT);
break;
}
}
@@ -8547,7 +8547,7 @@ BUILDIN(savepoint) {
str = script_getstr(st,2);
x = script_getnum(st,3);
y = script_getnum(st,4);
- mapid = mapindex->name2id(str);
+ mapid = script->mapindexname2id(st,str);
if( mapid )
pc->setsavepoint(sd, mapid, x, y);
@@ -10630,7 +10630,7 @@ BUILDIN(warpwaitingpc) {
else if( strcmp(map_name,"SavePoint") == 0 )
pc->setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT);
else
- pc->setpos(sd, mapindex->name2id(map_name), x, y, CLR_OUTSIGHT);
+ pc->setpos(sd, script->mapindexname2id(st,map_name), x, y, CLR_OUTSIGHT);
}
mapreg->setreg(script->add_str("$@warpwaitingpcnum"), i);
return true;
@@ -10700,7 +10700,7 @@ BUILDIN(setmapflagnosave) {
x=script_getnum(st,4);
y=script_getnum(st,5);
m = map->mapname2mapid(str);
- map_index = mapindex->name2id(str2);
+ map_index = script->mapindexname2id(st,str2);
if(m >= 0 && map_index) {
map->list[m].flag.nosave=1;
@@ -11542,7 +11542,7 @@ BUILDIN(mapwarp) {
if((m=map->mapname2mapid(mapname))< 0)
return true;
- if(!(index=mapindex->name2id(str)))
+ if(!(index=script->mapindexname2id(st,str)))
return true;
switch(check_val) {
@@ -11728,7 +11728,7 @@ BUILDIN(warppartner)
x=script_getnum(st,3);
y=script_getnum(st,4);
- map_index = mapindex->name2id(str);
+ map_index = script->mapindexname2id(st,str);
if (map_index) {
pc->setpos(p_sd,map_index,x,y,CLR_OUTSIGHT);
script_pushint(st,1);
@@ -15689,7 +15689,7 @@ BUILDIN(warpportal) {
spx = script_getnum(st,2);
spy = script_getnum(st,3);
- map_index = mapindex->name2id(script_getstr(st, 4));
+ map_index = script->mapindexname2id(st,script_getstr(st, 4));
tpx = script_getnum(st,5);
tpy = script_getnum(st,6);
@@ -16142,7 +16142,7 @@ BUILDIN(waitingroom2bg) {
map_name = script_getstr(st,2);
if( strcmp(map_name,"-") != 0 )
{
- map_index = mapindex->name2id(map_name);
+ map_index = script->mapindexname2id(st,map_name);
if( map_index == 0 )
{ // Invalid Map
script_pushint(st,0);
@@ -16184,7 +16184,7 @@ BUILDIN(waitingroom2bg_single) {
bg_id = script_getnum(st,2);
map_name = script_getstr(st,3);
- if( (map_index = mapindex->name2id(map_name)) == 0 )
+ if( (map_index = script->mapindexname2id(st,map_name)) == 0 )
return true; // Invalid Map
x = script_getnum(st,4);
@@ -16229,7 +16229,7 @@ BUILDIN(bg_warp)
bg_id = script_getnum(st,2);
map_name = script_getstr(st,3);
- if( (map_index = mapindex->name2id(map_name)) == 0 )
+ if( (map_index = script->mapindexname2id(st,map_name)) == 0 )
return true; // Invalid Map
x = script_getnum(st,4);
y = script_getnum(st,5);
@@ -18007,7 +18007,7 @@ BUILDIN(bg_create_team) {
map_name = script_getstr(st,2);
if( strcmp(map_name,"-") != 0 ) {
- map_index = mapindex->name2id(map_name);
+ map_index = script->mapindexname2id(st,map_name);
if( map_index == 0 ) { // Invalid Map
script_pushint(st,0);
return true;
@@ -19105,6 +19105,20 @@ void script_hardcoded_constants(void) {
script->set_constant("Option_Costume",OPTION_COSTUME,false);
}
+/**
+ * a mapindex_name2id wrapper meant to help with invalid name handling
+ **/
+unsigned short script_mapindexname2id (struct script_state *st, const char* name) {
+ unsigned short index;
+
+ if( !(index=mapindex->name2id(name)) ) {
+ script->reportsrc(st);
+ return 0;
+ }
+ return index;
+}
+
+
void script_defaults(void) {
// aegis->athena slot position conversion table
unsigned int equip[SCRIPT_EQUIP_TABLE_SIZE] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW,EQP_COSTUME_HEAD_LOW,EQP_COSTUME_HEAD_MID,EQP_COSTUME_HEAD_TOP,EQP_COSTUME_GARMENT,EQP_SHADOW_ARMOR, EQP_SHADOW_WEAPON, EQP_SHADOW_SHIELD, EQP_SHADOW_SHOES, EQP_SHADOW_ACC_R, EQP_SHADOW_ACC_L};
@@ -19358,5 +19372,6 @@ void script_defaults(void) {
script->array_cpy_list = script_array_cpy_list;
/* */
script->hardcoded_constants = script_hardcoded_constants;
+ script->mapindexname2id = script_mapindexname2id;
}
diff --git a/src/map/script.h b/src/map/script.h
index 5ce77799a..7ab7f17c6 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -696,6 +696,7 @@ struct script_interface {
unsigned int *(*array_cpy_list) (struct script_array *sa);
/* */
void (*hardcoded_constants) (void);
+ unsigned short (*mapindexname2id) (struct script_state *st, const char* name);
};
struct script_interface *script;