--- deliantra/maps/perl/follow.ext 2006/06/12 14:13:39 1.17 +++ deliantra/maps/perl/follow.ext 2006/07/11 15:37:31 1.18 @@ -6,39 +6,6 @@ # implement a 'follow' command # don't follow on damned ground -my %follow; - -cf::register_command follow => 0, sub { - my ($who, $args) = @_; - - my $name = $who->name; - - if ($args ne "" && $name ne $args) { - if (my $other = cf::player::find $args) { - if ($other->ob->map->path eq $who->map->path - && abs ($other->ob->x - $who->x) <= 1 - && abs ($other->ob->y - $who->y) <= 1) { - $who->message ("Following player '$args', to stop, type: 'follow"); - $other->ob->message ("$name is now following your every step..."); - $follow{$name} = [ - $args, - [$other->ob->map->path, $other->ob->x, $other->ob->y], - [$who->map->path, $who->x, $who->y], - ]; - } else { - $who->message ("You must stand directly beside '$args' to follow her/him"); - delete $follow{$name}; - } - } else { - $who->message ("Cannot follow '$args': no such player"); - delete $follow{$name}; - } - } else { - $who->message ("follow mode off"); - delete $follow{$name}; - } -}; - sub teleport { my ($pl, $map, $x, $y) = @_; @@ -57,24 +24,10 @@ $portal->free; } -sub on_player_death { - my ($ob) = @_; - - my $name = $ob->name; - - delete $follow{$name}; - - while (my ($k, $v) = each %follow) { - if ($v->[0] eq $name) { - delete $follow{$k}; - } - } - - 0 -} +my %follow; -sub on_clock { - return 0 unless %follow; +my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { + warn "follow\n";#d# while (my ($name, $v) = each %follow) { my ($target, $his, $mine) = @$v; @@ -104,9 +57,58 @@ } } + $_[0]->w->stop unless keys %follow; +}); + +cf::register_command follow => 0, sub { + my ($who, $args) = @_; + + my $name = $who->name; + + if ($args ne "" && $name ne $args) { + if (my $other = cf::player::find $args) { + if ($other->ob->map->path eq $who->map->path + && abs ($other->ob->x - $who->x) <= 1 + && abs ($other->ob->y - $who->y) <= 1) { + $who->message ("Following player '$args', to stop, type: 'follow"); + $other->ob->message ("$name is now following your every step..."); + $follow{$name} = [ + $args, + [$other->ob->map->path, $other->ob->x, $other->ob->y], + [$who->map->path, $who->x, $who->y], + ]; + $timer->start; + } else { + $who->message ("You must stand directly beside '$args' to follow her/him"); + delete $follow{$name}; + } + } else { + $who->message ("Cannot follow '$args': no such player"); + delete $follow{$name}; + } + } else { + $who->message ("follow mode off"); + delete $follow{$name}; + } +}; + +sub on_player_death { + my ($ob) = @_; + + my $name = $ob->name; + + delete $follow{$name}; + + while (my ($k, $v) = each %follow) { + if ($v->[0] eq $name) { + delete $follow{$k}; + } + } + 0 } +