Updated npcspeed, npcwalkto and npcstop script commands (#8354)

* Added the optional parameter <npc name> to npcspeed to change the walking speed of the npc with the said name.
  Usage : npcspeed( <speed value> {,"<npc name>"} );

* Added the optional parameter <npc name> to npcwalkto to move the npc with the said name at the given coordinates.
  Usage : npcwalkto( <x>,<y> {,"<npc name>"} } );

* Added the optional parameters `<npc name>` and `<flag>` to `npcstop` to stop the movement of the npc with the said name with options.
  Usage : `npcstop( {"<npc name>", {"<flag>"}});`

Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
Co-authored-by: Aleos <aleos89@users.noreply.github.com>
This commit is contained in:
Atemo
2024-06-16 14:57:59 +02:00
committed by GitHub
parent fcf74b0dfc
commit 6451925430
6 changed files with 128 additions and 45 deletions

View File

@@ -16071,48 +16071,120 @@ BUILDIN_FUNC(chatmes)
return SCRIPT_CMD_SUCCESS;
}
// change npc walkspeed [Valaris]
/**
* Change npc walkspeed.
* npcspeed <speed value> {,"<npc name>"};
*/
BUILDIN_FUNC(npcspeed)
{
struct npc_data* nd;
int speed;
npc_data* nd;
speed = script_getnum(st,2);
nd =(struct npc_data *)map_id2bl(st->oid);
if (script_hasdata(st, 3))
nd = npc_name2id(script_getstr(st, 3));
else
nd = map_id2nd(st->oid);
if( nd ) {
nd->speed = speed;
if (nd == nullptr) {
if (script_hasdata(st, 3))
ShowError("buildin_npcspeed: %s is a non-existing NPC.\n", script_getstr(st, 3));
else
ShowError("buildin_npcspeed: non-existing NPC.\n");
return SCRIPT_CMD_FAILURE;
}
int speed = script_getnum(st, 2);
if (speed < MIN_WALK_SPEED || speed > MAX_WALK_SPEED) {
ShowError("buildin_npcspeed: invalid speed %d (min: %d, max: %d).\n", speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
return SCRIPT_CMD_FAILURE;
}
nd->speed = speed;
return SCRIPT_CMD_SUCCESS;
}
// make an npc walk to a position [Valaris]
/**
* Make an npc walk to a position.
* npcwalkto <x>,<y> {,"<npc name>"} };
*/
BUILDIN_FUNC(npcwalkto)
{
struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
int x=0,y=0;
npc_data* nd;
x=script_getnum(st,2);
y=script_getnum(st,3);
if (script_hasdata(st, 4))
nd = npc_name2id(script_getstr(st, 4));
else
nd = map_id2nd(st->oid);
if(nd) {
if (!nd->status.hp)
status_calc_npc(nd, SCO_FIRST);
if (nd == nullptr) {
if (script_hasdata(st, 4))
ShowError("buildin_npcwalkto: %s is a non-existing NPC.\n", script_getstr(st, 4));
else
status_calc_npc(nd, SCO_NONE);
unit_walktoxy(&nd->bl,x,y,0);
ShowError("buildin_npcwalkto: non-existing NPC.\n");
return SCRIPT_CMD_FAILURE;
}
if( nd->bl.m < 0 ){
ShowError( "buildin_npcwalkto: NPC is not on a map.\n" );
return SCRIPT_CMD_FAILURE;
}
struct map_data* mapdata = map_getmapdata( nd->bl.m );
int x = script_getnum(st, 2);
int y = script_getnum(st, 3);
if( x < 0 || x >= mapdata->xs || y < 0 || y >= mapdata->ys ){
ShowWarning( "buildin_npcwalkto: coordinates %d/%d are out of bounds in map %s(%dx%d).\n", x, y, mapdata->name, mapdata->xs, mapdata->ys );
return SCRIPT_CMD_FAILURE;
}
if (!nd->status.hp)
status_calc_npc(nd, SCO_FIRST);
else
status_calc_npc(nd, SCO_NONE);
unit_walktoxy(&nd->bl,x,y,0);
return SCRIPT_CMD_SUCCESS;
}
// stop an npc's movement [Valaris]
/**
* Stop an npc's movement.
* npcstop {"<npc name>", {"<flag>"}};
*/
BUILDIN_FUNC(npcstop)
{
struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
npc_data* nd;
if(nd) {
unit_stop_walking(&nd->bl,1|4);
if (script_hasdata(st, 2))
nd = npc_name2id(script_getstr(st, 2));
else
nd = map_id2nd(st->oid);
if (nd == nullptr) {
if (script_hasdata(st, 2))
ShowError("buildin_npcstop: %s is a non-existing NPC.\n", script_getstr(st, 2));
else
ShowError("buildin_npcstop: non-existing NPC.\n");
return SCRIPT_CMD_FAILURE;
}
int flag = USW_FIXPOS | USW_MOVE_FULL_CELL | USW_FORCE_STOP;
if (script_hasdata(st, 3)) {
flag = script_getnum(st, 3);
if (flag < USW_NONE || flag > USW_ALL) {
ShowError("buildin_npcstop: invalid flag %d.\n", flag);
return SCRIPT_CMD_FAILURE;
}
if (flag & USW_FORCE_STOP)
nd->ud.state.force_walk = false;
}
unit_stop_walking( &nd->bl, flag );
return SCRIPT_CMD_SUCCESS;
}
@@ -27607,9 +27679,9 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(mobcount,"ss"),
BUILDIN_DEF(getlook,"i?"),
BUILDIN_DEF(getsavepoint,"i?"),
BUILDIN_DEF(npcspeed,"i"), // [Valaris]
BUILDIN_DEF(npcwalkto,"ii"), // [Valaris]
BUILDIN_DEF(npcstop,""), // [Valaris]
BUILDIN_DEF(npcspeed,"i?"),
BUILDIN_DEF(npcwalkto,"ii?"),
BUILDIN_DEF(npcstop,"??"),
BUILDIN_DEF(getmapxy,"rrr??"), //by Lorky [Lupus]
BUILDIN_DEF(mapid2name,"i"),
BUILDIN_DEF(checkoption1,"i?"),