Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated npcspeed, npcwalkto and npcstop script commands #8354

Merged
merged 11 commits into from
Jun 16, 2024
4 changes: 2 additions & 2 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7962,12 +7962,12 @@ Return values:
---------------------------------------

*npcspeed( <speed value> {,"<npc name>"} );
*npcwalkto( <x>,<y> {,"<speed value>" {,"<npc name>"} } );
*npcwalkto( <x>,<y> {,"<npc name>"} } );
*npcstop( {"<npc name>"} );

These commands will make the NPC object in question move around the map.

'npcspeed' will set the NPCs walking speed to a specified value. As in the
'npcspeed' will perma set the NPCs walking speed to a specified value. As in the
Atemo marked this conversation as resolved.
Show resolved Hide resolved
@speed GM command, MAX_WALK_SPEED (1000) is the slowest possible speed while MIN_WALK_SPEED (20) is the fastest
possible (instant motion). DEFAULT_NPC_WALK_SPEED (200) is the default NPC walking speed.

Expand Down
25 changes: 6 additions & 19 deletions src/map/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16100,38 +16100,25 @@ BUILDIN_FUNC(npcspeed)

/**
* Make an npc walk to a position.
* npcwalkto <x>,<y> {,"<speed>" {,"<npc name>"} };
* npcwalkto <x>,<y> {,"<npc name>"} };
*/
BUILDIN_FUNC(npcwalkto)
{
npc_data* nd;

if (script_hasdata(st, 5))
nd = npc_name2id(script_getstr(st, 5));
if (script_hasdata(st, 4))
nd = npc_name2id(script_getstr(st, 4));
else
nd = map_id2nd(st->oid);

if (nd == nullptr) {
if (script_hasdata(st, 5))
ShowError("buildin_npcwalkto: %s is a non-existing NPC.\n", script_getstr(st, 5));
if (script_hasdata(st, 4))
ShowError("buildin_npcwalkto: %s is a non-existing NPC.\n", script_getstr(st, 4));
else
ShowError("buildin_npcwalkto: non-existing NPC.\n");
return SCRIPT_CMD_FAILURE;
}

if (script_hasdata(st, 4)) {
int speed = script_getnum(st, 4);

if (speed != nd->speed) {
if (speed < MIN_WALK_SPEED || speed > MAX_WALK_SPEED) {
ShowError("buildin_npcwalkto: invalid speed %d (min: %d, max: %d).\n", speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
return SCRIPT_CMD_FAILURE;
}
nd->speed = speed;
nd->ud.state.speed_changed = 1;
}
}

int x = script_getnum(st, 2);
int y = script_getnum(st, 3);

Expand Down Expand Up @@ -27644,7 +27631,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(getlook,"i?"),
BUILDIN_DEF(getsavepoint,"i?"),
BUILDIN_DEF(npcspeed,"i?"),
BUILDIN_DEF(npcwalkto,"ii??"),
BUILDIN_DEF(npcwalkto,"ii?"),
BUILDIN_DEF(npcstop,"?"),
BUILDIN_DEF(getmapxy,"rrr??"), //by Lorky [Lupus]
BUILDIN_DEF(mapid2name,"i"),
Expand Down