ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
(Generate patch)

Comparing deliantra/maps/perl/follow.ext (file contents):
Revision 1.11 by root, Fri Feb 17 19:36:36 2006 UTC vs.
Revision 1.19 by root, Sun Jul 16 17:52:57 2006 UTC

3# TODO: skip arena 3# TODO: skip arena
4# TODO: check for player leaving 4# TODO: check for player leaving
5 5
6# implement a 'follow' command 6# implement a 'follow' command
7# don't follow on damned ground 7# don't follow on damned ground
8
9my %follow;
10
11cf::register_command follow => 0, sub {
12 my ($who, $args) = @_;
13
14 my $name = $who->name;
15
16 if ($args ne "" && $name ne $args) {
17 if (my $other = cf::player::find $args) {
18 if ($other->ob->map->path eq $who->map->path
19 && abs ($other->ob->x - $who->x) <= 1
20 && abs ($other->ob->y - $who->y) <= 1) {
21 $who->message ("Following player '$args', to stop, type: 'follow");
22 $other->ob->message ("$name is now following your every step...");
23 $follow{$name} = [
24 $args,
25 [$other->ob->map->path, $other->ob->x, $other->ob->y],
26 [$who->map->path, $who->x, $who->y],
27 ];
28 } else {
29 $who->message ("You must stand directly beside '$args' to follow her/him");
30 delete $follow{$name};
31 }
32 } else {
33 $who->message ("Cannot follow '$args': no such player");
34 delete $follow{$name};
35 }
36 } else {
37 $who->message ("follow mode off");
38 delete $follow{$name};
39 }
40};
41 8
42sub teleport { 9sub teleport {
43 my ($pl, $map, $x, $y) = @_; 10 my ($pl, $map, $x, $y) = @_;
44 11
45 return if $pl->ob->map->path eq $map 12 return if $pl->ob->map->path eq $map
55 $portal->apply ($pl->ob); 22 $portal->apply ($pl->ob);
56 23
57 $portal->free; 24 $portal->free;
58} 25}
59 26
60sub on_clock { 27my %follow;
61 my ($event) = @_;
62 28
63 return unless %follow; 29my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub {
64
65 while (my ($name, $v) = each %follow) { 30 while (my ($name, $v) = each %follow) {
66 my ($target, $his, $mine) = @$v; 31 my ($target, $his, $mine) = @$v;
67 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 32 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
68 33
69 if ($who && $other && $other->ob->map) { 34 if ($who && $other && $other->ob->map) {
87 } else { 52 } else {
88 delete $follow{$name}; 53 delete $follow{$name};
89 $who->ob->message ("$target is gone..."); 54 $who->ob->message ("$target is gone...");
90 } 55 }
91 } 56 }
57
58 $_[0]->w->stop unless keys %follow;
59});
60
61cf::register_command follow => 0, sub {
62 my ($who, $args) = @_;
63
64 my $name = $who->name;
65
66 if ($args ne "" && $name ne $args) {
67 if (my $other = cf::player::find $args) {
68 if ($other->ob->map->path eq $who->map->path
69 && abs ($other->ob->x - $who->x) <= 1
70 && abs ($other->ob->y - $who->y) <= 1) {
71 $who->message ("Following player '$args', to stop, type: 'follow");
72 $other->ob->message ("$name is now following your every step...");
73 $follow{$name} = [
74 $args,
75 [$other->ob->map->path, $other->ob->x, $other->ob->y],
76 [$who->map->path, $who->x, $who->y],
77 ];
78 $timer->start;
79 } else {
80 $who->message ("You must stand directly beside '$args' to follow her/him");
81 delete $follow{$name};
82 }
83 } else {
84 $who->message ("Cannot follow '$args': no such player");
85 delete $follow{$name};
86 }
87 } else {
88 $who->message ("follow mode off");
89 delete $follow{$name};
90 }
91};
92
93sub on_player_death {
94 my ($ob) = @_;
95
96 my $name = $ob->name;
97
98 delete $follow{$name};
99
100 while (my ($k, $v) = each %follow) {
101 if ($v->[0] eq $name) {
102 delete $follow{$k};
103 }
104 }
105
106 0
92} 107}
93 108
94 109
95 110
96 111

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines