# Make SURE there is no BOM in this file! It causes functions to be seen as non-existent!
# This flips a coin. Luck determines what it can land on.
# Fake flipping is not possible with this.
# $1 is the number of times to flip.
sub flip
{
local('$toRet $h $t $x');
$toRet = "[ ";
$h = 0;
$t = 0;
while ($1 > 0)
{
$x = round(rand());
if ($x == 1) # Heads is at 0, Tails is at 1.
{
$t++;
}
else
{
$h++;
}
$toRet = "$toRet " . @coinIRC[$x] . " ";
$1--;
}
return "$toRet ]: $h Heads, $t Tails";
}
# Rigging coin flips is occasionally needed.
# $1 is the list containing any or all of H, T, or X.
sub rig
{
local('@results $toRet $h $t');
$toRet = "[ ";
$h = 0;
$t = 0;
foreach $t ($1)
{
if ($t eq "H")
{
$toRet = "$toRet " . @coinIRC[0] . " ";
$h++;
}
else if ($t eq "T")
{
$toRet = "$toRet " . @coinIRC[1] . " ";
$t++;
}
else if ($t eq "X")
{
$toRet = "$toRet " . @coinIRC[2] . " ";
}
else
{
echo("$t is not a valid coin result!");
}
}
return "$toRet ]: $h Heads, $t Tails";
}
# This helper method handles calling the flip method.
# $1 is the channel to send the message to.
# $2 is the number of flips to make.
sub IRCCoin
{
this('$n $a $toRet');
$n = "coin";
if ($2 > 1)
{
$n = "coins";
}
$a = flip("$2");
$toRet = "\c00,01flips $2 $n! The results: $a"; # $n coin[s] isn't showing.
sendAction($1, $toRet);
return;
}
# This handles the coin flipping methods by me.
alias coin
{
local('@word');
@word = split(' ',$0-);
# /coin flip [<numFlips>]
if (lc(@word[1]) eq lc("flip"))
{
if (size(@word) < 3)
{
push(@word, "1");
}
IRCCoin("$active", int(@word[2]));
}
# /coin rig @("H" and/or "T" and/or "X")
else if (lc(@word[1]) eq lc("rig"))
{
this('@rigging $toRet');
@rigging = subarray(@word, 2);
$toRet = rig(@rigging);
call("/me rigs some coins! The results: $toRet");
}
else
{
say("\bERROR!\b Invalid command! (See the debug information)");
echo(@word);
}
}
# The coin remote.
on public
{
if (lc(getProperty("remotesOn")) eq lc("false") ||
lc(getProperty("remotesOn")) eq lc("off"))
{
return;
}
local('@word');
@word = split(' ',$0-);
if (@word[1] eq "#coin")
{
IRCRoll("$0", 1); #Only allow one coin to be flipped right now.
}
return;
}
global('@coinIRC');
@coinIRC = @("\b\c00,01H\c00,01\b", "\b\c01,00T\c00,01\b", "\b\c01,04X\c00,01\b");
setProperty("client.encoding", "UTF-8");