--- deliantra/server/ext/schmorplog.ext 2008/04/30 10:36:01 1.15 +++ deliantra/server/ext/schmorplog.ext 2008/05/01 06:47:03 1.17 @@ -1,5 +1,7 @@ #! perl # depends=irc +# statistics-package + use Fcntl; use Coro::AIO; @@ -36,7 +38,7 @@ my $pl = $hitter->contr or return; - ++$hitter->{stats_kill}{$ob->name_pl}; + ++$hitter->{stats_kill}{$ob->name}; }, ); @@ -99,3 +101,53 @@ }, ); +cf::register_script_function "statistician::talk" => sub { + my ($who, $msg, $npc) = @_; + + my ($cmd, $args) = split /\s+/, $msg, 2; + + $args ||= $who->name; + + if ($cmd eq "deaths") { + cf::async { + my $pl = cf::player::find $args + or return $who->reply ($npc, "I don't know any person named '$args'."); + + my $s = $pl->ob->{stats_death} + or return $who->reply ($npc, "$args didn't die even once."); + + my $rep = "$args died a total of " . $pl->ob->get_ob_key_value ("schmorplog_death_count") . " times, among them:\n\n\n\n"; + + for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { + $rep .= "$s->{$_} times due to $_.\n\n"; + } + + $who->reply ($npc, $rep); + }; + } elsif ($cmd eq "kills") { + cf::async { + my $pl = cf::player::find $args + or return $who->reply ($npc, "I don't know any person named '$args'."); + + my $s = $pl->ob->{stats_kill} + or return $who->reply ($npc, "I don't know of I that $args has killed so far."); + + my $rep = sprintf "\n\nC<%6s> %s\n\n", "#", "Name"; + for (sort { $s->{$a} <=> $s->{$b} } keys %$s) { + $rep .= sprintf "C<%6s> %s\n\n", $s->{$_}, $_; + } + + $who->reply ($npc, $rep); + }; + } elsif ($cmd eq "hi") { + $who->reply ($npc, "Hello!\n\n" + . "I am a statistician, I keep statistics about all people here.\n\n" + . "To know how often somebody died, ask C I\n\n" + . "To know how many kills somebody scored, ask C I"); + } else { + $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?"); + } + + $cmd = lc $cmd; +}; +