diff options
author | Emistry Haoyan <equinox1991@gmail.com> | 2019-05-18 00:53:57 +0800 |
---|---|---|
committer | Emistry Haoyan <equinox1991@gmail.com> | 2019-05-18 22:16:11 +0800 |
commit | f909e40bbc8783139fd6ccfb6f7108206e81c601 (patch) | |
tree | db6a46ea15254b3b1a9c1bfb54107e25f15f84cf /src | |
parent | 647a3d2513746a17636bea354ad5a56c1db853e1 (diff) | |
download | hercules-f909e40bbc8783139fd6ccfb6f7108206e81c601.tar.gz hercules-f909e40bbc8783139fd6ccfb6f7108206e81c601.tar.bz2 hercules-f909e40bbc8783139fd6ccfb6f7108206e81c601.tar.xz hercules-f909e40bbc8783139fd6ccfb6f7108206e81c601.zip |
Add new atcommand *reloadnpc
- `@reloadnpc <path>` - unloads all NPCs in a file and reload it again.
- Be aware that mapflags and monster spawned directly are not removed.
Diffstat (limited to 'src')
-rw-r--r-- | src/map/atcommand.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 09303912b..68272e67e 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4454,6 +4454,38 @@ ACMD(unloadnpc) return true; } +/// Unload existing NPC within the NPC file and reload it. +/// Usage: @reloadnpc npc/sample_npc.txt +ACMD(reloadnpc) +{ + if (!*message) { + clif->message(fd, msg_fd(fd, 1385)); // Usage: @unloadnpcfile <file name> + return false; + } else if (npc->unloadfile(message) == true) { + clif->message(fd, msg_fd(fd, 1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed. + + FILE *fp = fopen(message, "r"); + // check if script file exists + if (fp == NULL) { + clif->message(fd, msg_fd(fd, 261)); + return false; + } + fclose(fp); + + // add to list of script sources and run it + npc->addsrcfile(message); + npc->parsesrcfile(message, true); + npc->read_event_script(); + + clif->message(fd, msg_fd(fd, 262)); + } else { + clif->message(fd, msg_fd(fd, 1387)); // File not found. + return false; + } + + return true; +} + /*========================================== * time in txt for time command (by [Yor]) *------------------------------------------*/ @@ -10107,6 +10139,7 @@ static void atcommand_basecommands(void) ACMD_DEF(addperm), ACMD_DEF2("rmvperm", addperm), ACMD_DEF(unloadnpcfile), + ACMD_DEF(reloadnpc), ACMD_DEF(cart), ACMD_DEF(cashmount), ACMD_DEF(join), |