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.8 by root, Tue Feb 7 02:08:22 2006 UTC vs.
Revision 1.14 by elmex, Fri Mar 24 23:29:18 2006 UTC

2 2
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 8
8my %follow; 9my %follow;
9 10
10cf::register_command follow => 0, sub { 11cf::register_command follow => 0, sub {
11 my ($who, $args) = @_; 12 my ($who, $args) = @_;
34 } 35 }
35 } else { 36 } else {
36 $who->message ("follow mode off"); 37 $who->message ("follow mode off");
37 delete $follow{$name}; 38 delete $follow{$name};
38 } 39 }
40 1
39}; 41};
40 42
41sub teleport { 43sub teleport {
42 my ($pl, $map, $x, $y) = @_; 44 my ($pl, $map, $x, $y) = @_;
43 45
44 return if $pl->ob->map->path eq $map 46 return if $pl->ob->map->path eq $map
45 && abs ($pl->ob->x - $x) <= 1 47 && abs ($pl->ob->x - $x) <= 1
46 && abs ($pl->ob->y - $y) <= 1; 48 && abs ($pl->ob->y - $y) <= 1;
47 49
48 my $portal = cf::object::new ("exit"); 50 my $portal = cf::object::new "exit";
49 51
50 $portal->set_slaying ($map); 52 $portal->set_slaying ($map);
51 $portal->set_hp ($x); 53 $portal->set_hp ($x);
52 $portal->set_sp ($y); 54 $portal->set_sp ($y);
53 55
54 $portal->apply ($pl->ob, 0); 56 $portal->apply ($pl->ob);
55 57
56 $portal->free; 58 $portal->free;
59}
60
61sub on_player_death {
62 my ($event) = @_;
63
64 my $ob = $event->{who};
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
57} 76}
58 77
59sub on_clock { 78sub on_clock {
60 my ($event) = @_; 79 my ($event) = @_;
61 80
62 return unless %follow; 81 return 0 unless %follow;
63 82
64 while (my ($name, $v) = each %follow) { 83 while (my ($name, $v) = each %follow) {
65 my ($target, $his, $mine) = @$v; 84 my ($target, $his, $mine) = @$v;
66 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 85 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
67 86
86 } else { 105 } else {
87 delete $follow{$name}; 106 delete $follow{$name};
88 $who->ob->message ("$target is gone..."); 107 $who->ob->message ("$target is gone...");
89 } 108 }
90 } 109 }
110
111 0
91} 112}
92 113
93 114
94 115
95 116

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines