ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.1
Committed: Fri Feb 3 21:22:53 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
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 $who->ob->teleport ($other->ob->map, $other->ob->x, $other->ob->y);
34 } else {
35 warn "follow: $name or $target is gone, removing from follow list\n";
36 delete $follow{$name};
37 }
38 }
39 }
40
41
42
43