diff options
author | Joseph Botosh <rumly111@gmail.com> | 2015-09-28 12:05:31 +0300 |
---|---|---|
committer | Joseph Botosh <rumly111@gmail.com> | 2015-09-28 12:05:31 +0300 |
commit | 5d87a5aff44fbc5a6acb15afad26141fa8633094 (patch) | |
tree | b6ba1bb66f7317b97747d6b33de79de52b475e95 | |
parent | b7a9760e769738058ddbd99bc56d809de26ee99a (diff) | |
download | serverdata-5d87a5aff44fbc5a6acb15afad26141fa8633094.tar.gz serverdata-5d87a5aff44fbc5a6acb15afad26141fa8633094.tar.bz2 serverdata-5d87a5aff44fbc5a6acb15afad26141fa8633094.tar.xz serverdata-5d87a5aff44fbc5a6acb15afad26141fa8633094.zip |
Add new movegraph functions:
- npc_pausemove - temporary pause moving (useful for dialogs)
- npc_resumemove - resume move
- npc_turntoxy - turn NPC toward given coordinates
-rw-r--r-- | npc/functions/npcmovegraph.txt | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/npc/functions/npcmovegraph.txt b/npc/functions/npcmovegraph.txt index 69ea86ab..278c80a8 100644 --- a/npc/functions/npcmovegraph.txt +++ b/npc/functions/npcmovegraph.txt @@ -354,6 +354,8 @@ function script movetonextpoint { .@dist = distance(.@cx, .@cy, .@next_x1, .@next_y1); npcdebug "moving to " + getvariableofnpc(.movegraphlabels$[.@next_idx], strnpcinfo(3)) + " ("+.@next_x1 + "," + .@next_y1 + ") [distance=" + .@dist + "] flags=" + getvariableofnpc(.mg_flags, strnpcinfo(3)); } + set getvariableofnpc(.move_target_x, strnpcinfo(3)), .@next_x1; + set getvariableofnpc(.move_target_y, strnpcinfo(3)), .@next_y1; npcwalkto .@next_x1, .@next_y1; return; } @@ -377,3 +379,50 @@ function script firstmove { movetonextpoint; return; } + + +function script npc_pausemove { + stopnpctimer; + .@move_after = 0; + + if (isunitwalking()) + { + .@move_after = 1; + npcwalkto .x, .y; + npcstop; + } + set getvariableofnpc(.move_after_pause, strnpcinfo(3)), .@move_after; + + return 0; +} + + +function script npc_resumemove { + startnpctimer; + + if (getvariableofnpc(.move_after_pause, strnpcinfo(3))) + { + .@x = getvariableofnpc(.move_target_x, strnpcinfo(3)); + .@y = getvariableofnpc(.move_target_y, strnpcinfo(3)); + npcwalkto .@x, .@y; + } + + return 0; +} + + +// npc_turntoxy(x,y) +// turn npc toward an object at position (x,y) +function script npc_turntoxy { + .@target_x = getarg(0); + .@target_y = getarg(1); + .@dx = abs(.@target_x - .x); + .@dy = abs(.@target_y - .y); + + if (.@dx > .@dy) + .dir = .@target_x >= .x ? 6 : 2; + else + .dir = .@target_y >= .y ? 0 : 4; + + return 0; +} |