1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
# implement a 'follow' command |
4 |
|
|
|
5 |
|
|
my %follow; |
6 |
|
|
|
7 |
|
|
cf::register_command follow => 0, sub { |
8 |
|
|
my ($who, $args) = @_; |
9 |
|
|
|
10 |
|
|
my $name = $who->name; |
11 |
|
|
|
12 |
|
|
if ($args ne "" && $name ne $args) { |
13 |
|
|
if (cf::player::find $args) { |
14 |
|
|
$who->message ("following player '$args', to stop, type: 'follow"); |
15 |
|
|
$follow{$name} = $args; |
16 |
|
|
} else { |
17 |
|
|
$who->message ("cannot follow '$args': no such player"); |
18 |
|
|
} |
19 |
|
|
} else { |
20 |
|
|
$who->message ("follow mode off"); |
21 |
|
|
delete $follow{$name}; |
22 |
|
|
} |
23 |
|
|
}; |
24 |
|
|
|
25 |
|
|
sub on_clock { |
26 |
|
|
my ($event) = @_; |
27 |
|
|
|
28 |
|
|
return unless %follow; |
29 |
|
|
|
30 |
|
|
while (my ($name, $target) = each %follow) { |
31 |
|
|
my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
32 |
|
|
if ($who && $other) { |
33 |
root |
1.2 |
$who->ob->teleport ($other->ob->map, $other->ob->x, $other->ob->y) |
34 |
|
|
if $who->ob->map->path ne $other->ob->map->path; |
35 |
root |
1.1 |
} else { |
36 |
|
|
warn "follow: $name or $target is gone, removing from follow list\n"; |
37 |
|
|
delete $follow{$name}; |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|