--- deliantra/maps/perl/follow.ext 2006/02/07 01:03:44 1.7 +++ deliantra/maps/perl/follow.ext 2006/03/25 04:47:56 1.15 @@ -4,6 +4,7 @@ # TODO: check for player leaving # implement a 'follow' command +# don't follow on damned ground my %follow; @@ -18,6 +19,7 @@ && abs ($other->ob->x - $who->x) <= 1 && abs ($other->ob->y - $who->y) <= 1) { $who->message ("Following player '$args', to stop, type: 'follow"); + $other->ob->message ("$name is now following your every step..."); $follow{$name} = [ $args, [$other->ob->map->path, $other->ob->x, $other->ob->y], @@ -44,27 +46,44 @@ && abs ($pl->ob->x - $x) <= 1 && abs ($pl->ob->y - $y) <= 1; - my $portal = cf::object::new ("exit"); + my $portal = cf::object::new "exit"; $portal->set_slaying ($map); $portal->set_hp ($x); $portal->set_sp ($y); - $portal->apply ($pl->ob, 0); + $portal->apply ($pl->ob); $portal->free; } +sub on_player_death { + my ($event) = @_; + + my $ob = $event->{who}; + my $name = $ob->name; + + delete $follow{$name}; + + while (my ($k, $v) = each %follow) { + if ($v->[0] eq $name) { + delete $follow{$k}; + } + } + + 0 +} + sub on_clock { my ($event) = @_; - return unless %follow; + return 0 unless %follow; while (my ($name, $v) = each %follow) { my ($target, $his, $mine) = @$v; my ($who, $other) = (cf::player::find $name, cf::player::find $target); - if ($who && $other) { + if ($who && $other && $other->ob->map) { my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { @@ -80,11 +99,11 @@ teleport $who, @$mine; } else { delete $follow{$name}; - $who->ob->message ("$target is gone where you can't follow..."); + $who->ob->message ("You can't follow $target anymore!"); } } else { delete $follow{$name}; - $who->ob->message ("$name or $target is gone..."); + $who->ob->message ("$target is gone..."); } } }