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.14 by elmex, Fri Mar 24 23:29:18 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 1
41};
42 8
43sub teleport { 9sub teleport {
44 my ($pl, $map, $x, $y) = @_; 10 my ($pl, $map, $x, $y) = @_;
45 11
46 return if $pl->ob->map->path eq $map 12 return if $pl->ob->map->path eq $map
56 $portal->apply ($pl->ob); 22 $portal->apply ($pl->ob);
57 23
58 $portal->free; 24 $portal->free;
59} 25}
60 26
61sub on_player_death { 27my %follow;
62 my ($event) = @_;
63 28
64 my $ob = $event->{who}; 29my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub {
65 my $name = $ob->name;
66
67 delete $follow{$name};
68
69 while (my ($k, $v) = each %follow) {
70 if ($v->[0] eq $name) {
71 delete $follow{$k};
72 }
73 }
74
75 0
76}
77
78sub on_clock {
79 my ($event) = @_;
80
81 return 0 unless %follow;
82
83 while (my ($name, $v) = each %follow) { 30 while (my ($name, $v) = each %follow) {
84 my ($target, $his, $mine) = @$v; 31 my ($target, $his, $mine) = @$v;
85 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 32 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
86 33
87 if ($who && $other && $other->ob->map) { 34 if ($who && $other && $other->ob->map) {
106 delete $follow{$name}; 53 delete $follow{$name};
107 $who->ob->message ("$target is gone..."); 54 $who->ob->message ("$target is gone...");
108 } 55 }
109 } 56 }
110 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
111 0 106 0
112} 107}
113 108
114 109
115 110

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines