Added mob name support to some script commands (#7228)

Thanks to @Atemo for the idea.
This commit is contained in:
Lemongrass3110 2022-09-03 19:07:28 +02:00 committed by GitHub
parent 02a4831728
commit df57b5b7d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 34 deletions

View File

@ -6532,12 +6532,14 @@ Examples:
---------------------------------------
*monster "<map name>",<x>,<y>,"<name to show>",<mob id>,<amount>{,"<event label>",<size>,<ai>};
*monster "<map name>",<x>,<y>,"<name to show>","<mob name>",<amount>{,"<event label>",<size>,<ai>};
*areamonster "<map name>",<x1>,<y1>,<x2>,<y2>,"<name to show>",<mob id>,<amount>{,"<event label>",<size>,<ai>};
*areamonster "<map name>",<x1>,<y1>,<x2>,<y2>,"<name to show>","<mob name>",<amount>{,"<event label>",<size>,<ai>};
This command will spawn a monster on the specified coordinates on the specified
map. If the script is invoked by a character, a special map name, "this", will
be recognized to mean the name of the map the invoking character is located at.
This command works fine in the item scripts.
This command will spawn <amount> monsters with <mob id> or <mob name> on the specified
coordinates on the specified map. If the script is invoked by a character, a special
<map name>, "this", will be recognized to mean the name of the map the invoking character
is located at. This command works fine in item scripts.
The same command arguments mean the same things as described above in the
beginning of this document when talking about permanent monster spawns. Monsters
@ -6616,11 +6618,13 @@ For more good examples see just about any official 2-1 or 2-2 job quest script.
*areamobuseskill "<map name>",<x>,<y>,<range>,<mob id>,<skill id>,<skill level>,<cast time>,<cancelable>,<emotion>,<target type>;
*areamobuseskill "<map name>",<x>,<y>,<range>,<mob id>,"<skill name>",<skill level>,<cast time>,<cancelable>,<emotion>,<target type>;
*areamobuseskill "<map name>",<x>,<y>,<range>,"<mob name>",<skill id>,<skill level>,<cast time>,<cancelable>,<emotion>,<target type>;
*areamobuseskill "<map name>",<x>,<y>,<range>,"<mob name>","<skill name>",<skill level>,<cast time>,<cancelable>,<emotion>,<target type>;
This command will make all monsters of the specified mob ID in the specified
area use the specified skill. Map name, x, and y define the center of the area,
This command will make all monsters of the specified <mob id> or <mob name> in the specified
area use the specified skill. <map name>, <x>, and <y> define the center of the area,
which extending <range> cells in each direction (ex: a range of 3 would create
a 7x7 square). The skill can be specified by skill ID or name. <cast time> is in
a 7x7 square). The skill can be specified by <skill id> or <skill name>. <cast time> is in
milliseconds (1000 = 1 second), and the rest should be self-explanatory.
<target type> can be:

View File

@ -10935,6 +10935,7 @@ BUILDIN_FUNC(guildchangegm)
/*==========================================
* Spawn a monster:
* *monster "<map name>",<x>,<y>,"<name to show>",<mob id>,<amount>{,"<event label>",<size>,<ai>};
* *monster "<map name>",<x>,<y>,"<name to show>","<mob name>",<amount>{,"<event label>",<size>,<ai>};
*------------------------------------------*/
BUILDIN_FUNC(monster)
{
@ -10942,7 +10943,7 @@ BUILDIN_FUNC(monster)
int x = script_getnum(st,3);
int y = script_getnum(st,4);
const char* str = script_getstr(st,5);
int class_ = script_getnum(st,6);
int class_;
int amount = script_getnum(st,7);
const char* event = "";
unsigned int size = SZ_SMALL;
@ -10952,6 +10953,26 @@ BUILDIN_FUNC(monster)
int16 m;
int i;
if( script_isstring( st, 6 ) ){
const char* name = script_getstr( st, 6 );
std::shared_ptr<s_mob_db> mob = mobdb_search_aegisname( name );
if( mob == nullptr ){
ShowWarning( "buildin_monster: Attempted to spawn non-existing monster \"%s\"\n", name );
return SCRIPT_CMD_FAILURE;
}
class_ = mob->id;
}else{
class_ = script_getnum( st, 6 );
if( class_ >= 0 && !mobdb_checkid( class_ ) ){
ShowWarning( "buildin_monster: Attempted to spawn non-existing monster class %d\n", class_ );
return SCRIPT_CMD_FAILURE;
}
}
if (script_hasdata(st, 8)) {
event = script_getstr(st, 8);
check_event(st, event);
@ -10973,11 +10994,6 @@ BUILDIN_FUNC(monster)
}
}
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)
@ -11044,7 +11060,7 @@ BUILDIN_FUNC(areamonster)
int x1 = script_getnum(st,5);
int y1 = script_getnum(st,6);
const char* str = script_getstr(st,7);
int class_ = script_getnum(st,8);
int class_;
int amount = script_getnum(st,9);
const char* event = "";
unsigned int size = SZ_SMALL;
@ -11054,6 +11070,26 @@ BUILDIN_FUNC(areamonster)
int16 m;
int i;
if( script_isstring( st, 8 ) ){
const char* name = script_getstr( st, 8 );
std::shared_ptr<s_mob_db> mob = mobdb_search_aegisname( name );
if( mob == nullptr ){
ShowWarning( "buildin_areamonster: Attempted to spawn non-existing monster \"%s\"\n", name );
return SCRIPT_CMD_FAILURE;
}
class_ = mob->id;
}else{
class_ = script_getnum( st, 8 );
if( class_ >= 0 && !mobdb_checkid( class_ ) ){
ShowWarning( "buildin_areamonster: Attempted to spawn non-existing monster class %d\n", class_ );
return SCRIPT_CMD_FAILURE;
}
}
if (script_hasdata(st,10)) {
event = script_getstr(st, 10);
check_event(st, event);
@ -11062,7 +11098,7 @@ BUILDIN_FUNC(areamonster)
if (script_hasdata(st, 11)) {
size = script_getnum(st, 11);
if (size > 3) {
ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_);
ShowWarning( "buildin_areamonster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_ );
return SCRIPT_CMD_FAILURE;
}
}
@ -11070,16 +11106,11 @@ BUILDIN_FUNC(areamonster)
if (script_hasdata(st, 12)) {
ai = static_cast<enum mob_ai>(script_getnum(st, 12));
if (ai >= AI_MAX) {
ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_);
ShowWarning( "buildin_areamonster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_ );
return SCRIPT_CMD_FAILURE;
}
}
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)
@ -21839,13 +21870,12 @@ static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
}
/*==========================================
* areamobuseskill "Map Name",<x>,<y>,<range>,<Mob ID>,"Skill Name"/<Skill ID>,<Skill Lv>,<Cast Time>,<Cancelable>,<Emotion>,<Target Type>;
* areamobuseskill "<Map Name>",<x>,<y>,<range>,"<Mob name>"/<Mob ID>,"<Skill Name>"/<Skill ID>,<Skill Lv>,<Cast Time>,<Cancelable>,<Emotion>,<Target Type>;
*------------------------------------------*/
BUILDIN_FUNC(areamobuseskill)
{
struct block_list center;
int16 m;
int range,mobid,skill_id,skill_lv,casttime,emotion,target,cancel;
if( (m = map_mapname2mapid(script_getstr(st,2))) < 0 ) {
ShowError("areamobuseskill: invalid map name.\n");
@ -21855,8 +21885,31 @@ BUILDIN_FUNC(areamobuseskill)
center.m = m;
center.x = script_getnum(st,3);
center.y = script_getnum(st,4);
range = script_getnum(st,5);
mobid = script_getnum(st,6);
int range = script_getnum( st,5 );
uint16 mobid;
if( script_isstring( st, 6 ) ){
const char* name = script_getstr( st, 6 );
std::shared_ptr<s_mob_db> mob = mobdb_search_aegisname( name );
if( mob == nullptr ){
ShowWarning( "buildin_areamobuseskill: Attempted to use skill of non-existing monster \"%s\"\n", name );
return SCRIPT_CMD_FAILURE;
}
mobid = mob->id;
}else{
mobid = script_getnum( st, 6 );
if( !mob_db.exists( mobid ) ){
ShowWarning( "buildin_areamobuseskill: Attempted to use skill of non-existing monster class %d\n", mobid );
return SCRIPT_CMD_FAILURE;
}
}
int skill_id;
if (script_isstring(st, 7)) {
const char *name = script_getstr(st, 7);
@ -21872,13 +21925,17 @@ BUILDIN_FUNC(areamobuseskill)
return SCRIPT_CMD_FAILURE;
}
}
if( (skill_lv = script_getnum(st,8)) > battle_config.mob_max_skilllvl )
skill_lv = battle_config.mob_max_skilllvl;
casttime = script_getnum(st,9);
cancel = script_getnum(st,10);
emotion = script_getnum(st,11);
target = script_getnum(st,12);
int skill_lv = script_getnum( st, 8 );
if( skill_lv > battle_config.mob_max_skilllvl ){
skill_lv = battle_config.mob_max_skilllvl;
}
int casttime = script_getnum( st, 9 );
int cancel = script_getnum( st, 10 );
int emotion = script_getnum( st, 11 );
int target = script_getnum( st, 12 );
map_foreachinallrange(buildin_mobuseskill_sub, &center, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target);
return SCRIPT_CMD_SUCCESS;
@ -26529,9 +26586,9 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(itemskill,"vi?"),
BUILDIN_DEF(produce,"i"),
BUILDIN_DEF(cooking,"i"),
BUILDIN_DEF(monster,"siisii???"),
BUILDIN_DEF(monster,"siisvi???"),
BUILDIN_DEF(getmobdrops,"i"),
BUILDIN_DEF(areamonster,"siiiisii???"),
BUILDIN_DEF(areamonster,"siiiisvi???"),
BUILDIN_DEF(killmonster,"ss?"),
BUILDIN_DEF(killmonsterall,"s?"),
BUILDIN_DEF(clone,"siisi????"),
@ -26836,7 +26893,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(mercenary_set_faith,"ii"),
BUILDIN_DEF(readbook,"ii"),
BUILDIN_DEF(setfont,"i"),
BUILDIN_DEF(areamobuseskill,"siiiiviiiii"),
BUILDIN_DEF(areamobuseskill,"siiivviiiii"),
BUILDIN_DEF(progressbar,"si"),
BUILDIN_DEF(progressbar_npc, "si?"),
BUILDIN_DEF(pushpc,"ii"),