Index: src/map/script.c
===================================================================
--- src/map/script.c (revision 17307)
+++ src/map/script.c (working copy)
@@ -15359,7 +15359,6 @@
}
// <--- [zBuffer] List of player cont commands
// [zBuffer] List of mob control commands --->
-//## TODO always return if the request/whatever was successfull [FlavioJS]
/// Makes the unit walk to target position or map
/// Returns if it was successfull
@@ -15372,19 +15371,22 @@
bl = map_id2bl(script_getnum(st,2));
if( bl == NULL )
- {
script_pushint(st, 0);
- }
- else if( script_hasdata(st,4) )
- {
+ else if( script_hasdata(st,4) ) {
int x = script_getnum(st,3);
int y = script_getnum(st,4);
- script_pushint(st, unit_walktoxy(bl,x,y,0));// We'll use harder calculations.
- }
- else
- {
+ if( script_pushint(st, unit_can_reach_pos(bl,x,y,0)) )
+ add_timer(gettick()+50, unit_delay_walktoxy_timer, bl->id, (x<<16)|(y&0xFFFF)); // Need timer to avoid mismatches
+ } else {
int map_id = script_getnum(st,3);
- script_pushint(st, unit_walktobl(bl,map_id2bl(map_id),65025,1));
+ struct block_list* tbl = map_id2bl(map_id);
+ if( tbl == NULL ) {
+ ShowError("script:unitwalk: bad target destination\n");
+ script_pushint(st, 0);
+ return 1;
+ }
+ else if (script_pushint(st, unit_can_reach_bl(bl, tbl, distance_bl(bl, tbl)+1, 1, NULL, NULL)))
+ add_timer(gettick()+50, unit_delay_walktobl_timer, bl->id, map_id); // Need timer to avoid mismatches
}
return 0;
Index: src/map/unit.c
===================================================================
--- src/map/unit.c (revision 17307)
+++ src/map/unit.c (working copy)
@@ -298,7 +298,7 @@
return 0;
}
-static int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
+int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
{
struct block_list *bl = map_id2bl(id);
@@ -308,6 +308,19 @@
return 1;
}
+int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data)
+{
+ struct block_list *bl = map_id2bl(id);
+
+ if (!bl || bl->prev == NULL)
+ return 0;
+
+ struct unit_data* ud = unit_bl2ud(bl);
+ unit_walktobl(bl, map_id2bl(data), 0, 1);
+ ud->target_to = 0;
+ return 1;
+}
+
//flag parameter:
//&1 -> 1/0 = easy/hard
//&2 -> force walking
@@ -2513,6 +2526,7 @@
add_timer_func_list(unit_walktoxy_timer,"unit_walktoxy_timer");
add_timer_func_list(unit_walktobl_sub, "unit_walktobl_sub");
add_timer_func_list(unit_delay_walktoxy_timer,"unit_delay_walktoxy_timer");
+ add_timer_func_list(unit_delay_walktobl_timer,"unit_delay_walktobl_timer");
return 0;
}
Index: src/map/unit.h
===================================================================
--- src/map/unit.h (revision 17307)
+++ src/map/unit.h (working copy)
@@ -68,61 +68,57 @@
unsigned dead_sit : 2;
};
-// PC, MOB, PET \82ɋ\A4\92ʂ\B7\82鏈\97\9D\82\F0\82P\82ɂ܂Ƃ߂\E9\8Cv\89\E6
+// PC, MOB, PET
-// \95\E0\8Ds\8AJ\8En
-// \96߂\E8\92l\82́A0 ( \90\AC\8C\F7 ), 1 ( \8E\B8\94s )
+// Does walk action for unit
int unit_walktoxy( struct block_list *bl, short x, short y, int easy);
int unit_walktobl( struct block_list *bl, struct block_list *target, int range, int easy);
int unit_run(struct block_list *bl);
int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir);
+int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data);
+int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data);