Triggers, Variables and Scripts

Posted by Ankka on Fri 15 Jun 2001 02:18 PM — 5 posts, 21,455 views.

Finland #0
In this mud I play there is a guild based on reputation. Players can check their reputation with command which produces text something like this:

Reputation bar:
[@####:::::::::....]

All dots meaning one piece of reputation,
colons meaning 10 pieces,
#'s meaning 100 and @'s meaning 1000 pieces of reputation.

So I want to change this bar into numbers. What is the best way to do this? I think I should make a trigger which whenever finds eg. a dot, adds one to my reputation variable but I don't know how to do it.

Sorry for bad english ;)
#1
In perlscript the code would look something like the following...you'd have to change it to interface with mushclient a bit. Replace $raw_string with whatever you pass to the script from your trigger.

$raw_string = "[@#:::....]";

@individual_chars = split(//, $raw_string);
$atsign = 0;
$hash = 0;
$colon = 0;
$period = 0;

foreach (@individual_chars)
{
if (/@/)
{
$atsign++;
}
elsif (/\#/)
{
$hash++;
}
elsif (/:/)
{
$colon++;
}
elsif (/\./)
{
$period++;
}
}

$reputation = (1000 * $atsign) +
(100 * $hash) +
(10 * $colon) +
$period;

$world->send($reputation);
#2
Upon a bit of testing, I realize I made a mistake. Apparently @@ is a special magic thing in Perl. So...before you split the string, replace @'s with ^'s with this line:

$raw_string =~ s/\@/\^/g;

And change the line in the foreach that matches on @'s to match on ^'s with:

if (/\^/)

Sorry bout that, it worked with my initial (only 1 @) test.
Finland #3
Never used PerlScript before and it contained some bugs but finally got it to work right.

Thanks very much, couldn't do it without you.
Finland #4
Oh, just noticed that there weren't any bugs i just typoed part of the script :)