Fixed a bug in reloadnpcfile (#5553)

Introduced in d098c01b

Fixes #5541
Fixes #4846

Thanks to @Triedge and @Stingor
This commit is contained in:
Lemongrass3110
2020-11-17 12:41:34 +01:00
committed by GitHub
parent 602c6035e5
commit 4f853c96e9
3 changed files with 35 additions and 21 deletions

View File

@@ -563,6 +563,27 @@ int npc_event_doall_id(const char* name, int rid)
return c;
}
// runs the specified event on all NPCs with the given path
int npc_event_doall_path( const char* event_name, const char* path ){
s_mapiterator* iter = mapit_geteachnpc();
npc_data* nd;
int count = 0;
while( ( nd = (npc_data*)mapit_next( iter ) ) != nullptr ){
if( nd->path && strcasecmp( nd->path, path ) == 0 ){
char name[EVENT_NAME_LENGTH];
safesnprintf( name, EVENT_NAME_LENGTH, "%s::%s", nd->exname, event_name );
count += npc_event_do( name );
}
}
ShowStatus( "Event '" CL_WHITE "%s" CL_RESET "' executed with '" CL_WHITE "%d" CL_RESET "' NPCs.\n", event_name, count );
return count;
}
/*==========================================
* Clock event execution
* OnMinute/OnClock/OnHour/OnDay/OnDDHHMM
@@ -2526,7 +2547,7 @@ int npc_addsrcfile(const char* name, bool loadscript)
file_prev->next = file;
if (loadscript)
return npc_parsesrcfile(file->name, true);
return npc_parsesrcfile(file->name);
return 1;
}
@@ -3233,7 +3254,7 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
* @param filepath : filename with path wich we are parsing
* @return new index for next parsing
*/
static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, bool runOnInit) {
static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath) {
int16 dir = 0;
short m, x, y, xs = 0, ys = 0; // [Valaris] thanks to fov
struct script_code *script;
@@ -3345,20 +3366,6 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
nd->u.scr.timerid = INVALID_TIMER;
if( runOnInit ) {
char evname[EVENT_NAME_LENGTH];
struct event_data *ev;
snprintf(evname, ARRAYLENGTH(evname), "%s::%s", nd->exname, script_config.init_event_name);
if( ( ev = (struct event_data*)strdb_get(ev_db, evname) ) ) {
//Execute OnInit
run_script(nd->u.scr.script,ev->pos,0,nd->bl.id);
}
}
return end;
}
@@ -4401,7 +4408,7 @@ static const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, con
* @param runOnInit : should we exec OnInit when it's done ?
* @return 0:error, 1:success
*/
int npc_parsesrcfile(const char* filepath, bool runOnInit)
int npc_parsesrcfile(const char* filepath)
{
int16 m, x, y;
int lines = 0;
@@ -4570,7 +4577,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit)
if( strcasecmp(w1,"function") == 0 )
p = npc_parse_function(w1, w2, w3, w4, p, buffer, filepath);
else
p = npc_parse_script(w1,w2,w3,w4, p, buffer, filepath,runOnInit);
p = npc_parse_script(w1,w2,w3,w4, p, buffer, filepath);
}
else if( (i=0, sscanf(w2,"duplicate%n",&i), (i > 0 && w2[i] == '(')) && count > 3 )
p = npc_parse_duplicate(w1,w2,w3,w4, p, buffer, filepath);
@@ -4756,7 +4763,7 @@ int npc_reload(void) {
// Reloading npcs now
for (nsl = npc_src_files; nsl; nsl = nsl->next) {
ShowStatus("Loading NPC file: %s" CL_CLL "\r", nsl->name);
npc_parsesrcfile(nsl->name,false);
npc_parsesrcfile(nsl->name);
}
ShowInfo ("Done loading '" CL_WHITE "%d" CL_RESET "' NPCs:" CL_CLL "\n"
"\t-'" CL_WHITE "%d" CL_RESET "' Warps\n"
@@ -4907,7 +4914,7 @@ void do_init_npc(void){
ShowStatus("Loading NPCs...\r");
for( file = npc_src_files; file != NULL; file = file->next ) {
ShowStatus("Loading NPC file: %s" CL_CLL "\r", file->name);
npc_parsesrcfile(file->name,false);
npc_parsesrcfile(file->name);
}
ShowInfo ("Done loading '" CL_WHITE "%d" CL_RESET "' NPCs:" CL_CLL "\n"
"\t-'" CL_WHITE "%d" CL_RESET "' Warps\n"