;EmeraldBOT Economy ;(C) 2002-2006 Andrew Fader ;This script may be freely used and distributed provided this message remains present ;Initialization type stuff on 1:CONNECT:{ ;%login is a list of everyone who is logged in. after the bot logs off, so does everyone else. set -s %login $null echo Setting login to null. ;see what day it is checkforupdate } on 1:DISCONNECT:{ ;just in case, we'll do it here too set -s %login $null } on 1:QUIT:{ ;if someone logs off IRC, log him out if $nick isin %login { if $nick !ison $chan { set %login $remove(%login,$nick) echo it appears that $nick is logged out } } } ;Aliases alias dayinc { ;go to the next day inc %day $timepassed(%lastdate,$date) %lastdate = $date echo It is now day %day $+ . } alias checkforupdate { if $date = %lastdate { } else { dayinc } } alias timepassed { return $calc(($ctime($2) - $ctime($1)) / 60 / 60 / 24) } alias moneygive { ;give money to someone in the money.ini file var %funds $funds($1) if (%funds == $null) { set -s %funds 0 } set -s %funds $calc(%funds + $2) writeini money.ini $1 funds %funds } alias debtgive { ;debt is given by !welfare and that should be it var %debt $debt($1) if (%debt == $null) { set -s %debt 0 } set -s %debt $calc(%debt + $2) writeini money.ini $1 debt %debt } alias giveitem { ;items - syntax: /giveitem user item writeini money.ini $1 items $items($1) $2 } alias takeitem { ;items - syntax: /takeitem user item var %j = 0 while %j <= $numtok($items($1),32) { if $gettok($items($1),%j,32) = $2 { echo $items($1) - $2 = $deltok($items($1),%j,32) if $deltok($items($1),%j,32) != $null { writeini money.ini $1 items $deltok($items($1),%j,32) } else { remini money.ini $1 items } goto 3 } inc %j } :3 } alias priv { return $readini money.ini $1 checkfunds } alias funds { return $readini money.ini $1 funds } alias debt { return $readini money.ini $1 debt } alias pass { return $readini money.ini $1 password } alias items { return $readini money.ini $1 items } alias checkpass { if $pass($1) != $null { if $nick !isin %login { msg %origin You aren't logged in. halt } } } ;Commands on 1:TEXT:!checkfunds*:*:{ calcorg if ($2 == $null) { %nick = $nick } else { %nick = $2 } if ($priv(%nick) == off) { if (%nick != $nick) { msg %origin %nick has a private account. halt } } var %funds $funds(%nick) var %debt $debt(%nick) if (%funds == $null) { set -s %funds 0 } if (%debt == $null) { set -s %debt 0 } msg %origin %nick has %funds emeralds and owes %debt emeralds. } on 1:TEXT:!funds*:*:{ ;duplicate of !checkfunds calcorg if ($2 == $null) { %nick = $nick } else { %nick = $2 } if ($priv(%nick) == off) { if (%nick != $nick) { msg %origin %nick has a private account. halt } } var %funds $funds(%nick) var %debt $debt(%nick) if (%funds == $null) { set -s %funds 0 } if (%debt == $null) { set -s %debt 0 } msg %origin %nick has %funds emeralds and owes %debt emeralds. } on 1:TEXT:!worth*:*:{ ;duplicate of !checkfunds calcorg if ($2 == $null) { %nick = $nick } else { %nick = $2 } if ($priv(%nick) == off) { if (%nick != $nick) { msg %origin %nick has a private account. halt } } var %funds $funds(%nick) var %debt $debt(%nick) if (%funds == $null) { set -s %funds 0 } if (%debt == $null) { set -s %debt 0 } msg %origin %nick has %funds emeralds and owes %debt emeralds. } on 5:TEXT:!interbank*:*:{ ;turn on and off the foreign transfers calcorg if $2 = off { set -s %interbank 0 msg %origin Foreign transfers are now locked down. } elseif $2 = on { set -s %interbank 1 msg %origin Foreign transfers are now enabled. } elseif $2 = $null { if %interbank = 1 { msg %origin Foreign transfers are enabled. } elseif %interbank = 0 { msg %origin Foreign transfers are locked down. } else { msg %origin Something is terribly, terribly wrong with foreign transfers. } } } ;!transfer to@bank amount on 1:TEXT:!transfer*:*:{ ;this is a complicated economy command really, so I won't comment it right now calcorg checkpass $nick if ($2 = $null) { msg %origin Syntax: !transfer @ halt } set -s %funds $funds($nick) set -s %debt $debt($nick) set -s %transfersend $gettok($2,1,64) set -s %bankalias $gettok($2,2,64) set -s %arpchan %origin if %bankalias = $null { set -s %bank 3 } if %bankalias = e { set -s %bank 3 } if %bankalias = emerald { set -s %bank 3 } if %bankalias = emeraldbot { set -s %bank 3 } if %bankalias = Panic { set -s %bank 1 } if %bankalias = p { set -s %bank 1 } if ($$3 <= $calc(%funds - %debt)) { echo ok, $3 is less than or equal to funds - debt if ($$3 > 0) { echo ok, $3 is greater than zero if (%bank == 3) { echo bank is 3 moneygive %transfersend $ceil($$3) moneygive $nick - $+ $ceil($$3) msg %origin Successfully transferred € $+ $ceil($$3) from $nick (on EmeraldBOT) to %transfersend (on EmeraldBOT). } if %bank != 3 { if %interbank = 1 { msg #arp ^INTERBANK.ARP 3 %bank 3 set -s %trace %origin $+ $nick $+ $rand(0,400) set -s $eval(% $+ tnick $+ %trace, 1) $nick set -s $eval(% $+ tsend $+ %trace, 1) $lower(%transfersend) set -s $eval(% $+ tchan $+ %trace, 1) %origin set -s $eval(% $+ tamnt $+ %trace, 1) $$3 enable #economy } else { echo interbank is off msg %origin Foreign transfers are currently locked down. } } } else { msg %origin Invalid transfer. } } else { msg %origin Insufficient funds, or debt too high. } } #economy off on 1:TEXT:^INTERBANK.IAM*:?:{ if $2 = 3 { var %retry 1 while %retry < 3 { if $3 = 401 { set -s %pnick $nick disable #economy set -s %retry 8 foreigntransfer } elseif $3 = 501 { if %bank = 1 { msg $nick &ident EmeraldBOT 966631563 msg #arp ^INTERBANK.ARP 3 %bank 3 inc %retry } } else { msg %arpchan Unknown error transferring to bank on $nick $+ . halt } } } } #economy end alias foreigntransfer { echo foreigntransfer works. if %interbank = 1 { if %bank = 1 { echo it's bank 1, panic msg %pnick &ident EmeraldBOT 966631563 echo %trace echo ok, ready to message panic msg %pnick ^INTERBANK.WIR 3 c $lower(%transfersend) 3 0 %trace echo got past messaging panic... } if %bank = 2 { } } else { echo interbank is off } } ;^bankarp 3 3 localbankcode on +3:TEXT:^INTERBANK.ARP*:#:{ if $2 = 3 { if $3 = 3 { msg $nick ^INTERBANK.IAM 3 401 3 } } } on +1:TEXT:^INTERBANK.ARP*:#:{ if $2 = 3 { if $3 = 3 { msg $nick ^INTERBANK.IAM 3 501 3 } } } ;^interbank.tok 3 code trace on 3:TEXT:^INTERBANK.TOK*:?:{ if $2 = 3 { if ($$3 = 201) { set -s %trace $$4 moneygive $eval(% $+ tnick $+ %trace, 2) - $+ $eval(% $+ tamnt $+ %trace, 2) echo moneygive $eval(% $+ tnick $+ %trace, 2) - $+ $eval(% $+ tamnt $+ %trace, 2) msg $eval(% $+ tchan $+ %trace, 2) Successfully transferred € $+ $eval(% $+ tamnt $+ %trace, 2) from $eval(% $+ tnick $+ %trace, 2) (on EmeraldBOT) to $eval(% $+ tsend $+ %trace, 2) (on $nick $+ ). } elseif ($$3 = 98) { msg $eval(% $+ tchan $+ %trace, 2) An error has occurred transferring to $nick (Code 98: General Error) } else { msg $eval(% $+ tchan $+ %trace, 2) An error has occurred transferring to $nick (Code $$3 $+ : Unknown Error) } } else { msg $eval(% $+ tchan $+ %trace, 2) An error has occurred transferring to $nick (Unknown Error: Obsolete Protocol) } } ;^transfer to amount from tracer on 3:TEXT:^INTERBANK.WIR*:?:{ echo receieving a wire if %interbank = 1 { if $2 = 3 { echo proper protocol if $3 = c { if $7 > 0 { if $7 < 1000000000 { echo c = $3 moneygive $4 $7 msg $nick ^INTERBANK.TOK 3 201 $9- } } } elseif $3 = d { msg $nick ^INTERBANK.TOK 3 108 $9- } else { msg $nick ^INTERBANK.TOK 3 102 $9- } } else { msg $nick ^INTERBANK.TOK 3 113 $9- } } else { echo interbank is turned off msg $nick ^INTERBANK.TOK 3 98 $9- } } on +1:TEXT:^INTERBANK.WIR*:?:{ msg $nick ^INTERBANK.TOK 3 99 $9- } on 1:TEXT:!welfare*:*:{ calcorg checkpass $nick ;a non-working welfare calculation mechanism ; set -s %welfare $floor($calc(%issued * .001)) set -s %welfare 500 if ($funds($nick) = $null) { writeini money.ini $nick funds 0 } if ($funds($nick) < %welfare) { var %newfunds %welfare - $funds($nick) moneygive $nick %newfunds debtgive $nick %newfunds msg %origin $nick $+ , you been granted a welfare loan of € $+ %newfunds from the EmeraldBOT Bank. This money is nontransferrable, and we advise that you pay back your debt with !payback as soon as possible. } else { msg %origin $nick $+ , you are not eligible for a welfare loan. } } on 1:TEXT:!payback*:*:{ ;get rid of debt calcorg if $2 != $null { if $2 > 0 { if $debt($nick) >= $2 { if $funds($nick) >= $2 { debtgive $nick - $+ $2 moneygive $nick - $+ $2 msg %origin Paid back € $+ $2 $+ . } else { msg %origin Insufficient funds. (Type !welfare to apply for a welfare loan.) } } else { msg %origin You don't owe that much. } } } else { msg %origin Syntax: !payback } } on 1:TEXT:!items*:*:{ set -s %items GHINT SGHINT XGHINT 50FLIP set -s %unsellable $null calcorg if $2 = $null { msg %origin The following items are for sale: %items } elseif $2 = GHINT { msg %origin GHINT (€50,000) - a hint for 6Ghost. } elseif $2 = SGHINT { msg %origin SGHINT (€100,000) - a hint for 8Super6ghost. } elseif $2 = XGHINT { msg %origin XGHINT (€200,000) - a hint for 11X6ghost. } elseif $2 = 50FLIP { msg %origin 50FLIP (€20,000) - 50 extra flips to use with !flip. } } alias price { if $1 = GHINT { return 50000 } if $1 = SGHINT { return 100000 } if $1 = XGHINT { return 200000 } if $1 = 50FLIP { return 20000 } } on 1:TEXT:!buy*:*:{ calcorg checkpass $nick if $2 != $null { if $2 isin %items { if $calc($funds($nick) - $debt($nick)) >= $price($upper($2)) { giveitem $nick $upper($2) moneygive $nick - $+ $price($upper($2)) echo $nick loses $price($upper($2)) msg %origin $nick has purchased one $upper($2) $+ . } else { msg %origin Insufficient funds. $calc($funds($nick) - $debt($nick)) $+ with debt is less than $price($upper($2)) $+ . } } else { echo $upper($2) isn't in %items msg %origin $2 $+ : Invalid item. } } else { msg %origin $2 $+ : Invalid item. } } on 1:TEXT:!sell*:*:{ calcorg checkpass $nick if $2 != $null { if $2 isin $items($nick) { if $2 !isin %unsellable { takeitem $nick $2 moneygive $nick $price($2) echo $nick gets $price($2) msg %origin $nick has sold a $2 $+ . } else { msg %origin $2 cannot be sold. } } } else { msg %origin $2 $+ : Invalid item. } } on 1:TEXT:!use*:*:{ calcorg checkpass $nick if $2 isin $items($nick) { if $2 = 50FLIP { var %f $readini money.ini $nick f if %f = $null { %f = 0 } echo ... %f flips left echo ... %f goes to $calc(%f + 50) writeini money.ini $nick f $calc(%f + 50) msg %origin $nick used the 50FLIP. Flips have increased from %f to $calc(%f + 50) $+ . takeitem $nick 50FLIP } elseif $2 !isin %items { msg %origin Invalid item. } else { msg %origin $2 has not yet been implemented. } } else { msg %origin You don't have the $2 $+ . } } on 1:TEXT:!inventory*:*:{ calcorg if $2 = $null { var %nick $nick } else { var %nick $2 if $priv(%nick) = off { msg %origin %nick has a private account. halt } } if $items(%nick) != $null { msg %origin Items for %nick $+ : $items(%nick) } else { msg %origin %nick $+ 's inventory is empty. } } alias calcec { set -s %amntusers $ini(money.ini,0) var %findout 1 set -s %issued 0 set -s %cdebt 0 set -s %topamnt 0 set -s %topuser $null ; set -s %botuser $null ; set -s %botamnt 999999999999999999999999999 while %findout <= %amntusers { inc -s %issued $funds($ini(money.ini,%findout)) inc -s %cdebt $debt($ini(money.ini,%findout)) if $funds($ini(money.ini,%findout)) > %topamnt { set -s %topamnt $funds($ini(money.ini,%findout)) set -s %topuser $ini(money.ini,%findout) } ;this figures out the bottom user but it's useless, because it always ends up being someone with 0 ; if $funds($ini(money.ini,%findout)) < %botamnt { ; if $ini(money.ini,%findout) != $null { ; if $funds($ini(money.ini,%findout)) != $null { ; set -s %botamnt $funds($ini(money.ini,%findout)) ; set -s %botuser $ini(money.ini,%findout) ; } ; } ; } inc -s %findout } } on 1:TEXT:!economy:*:{ calcorg calcec msg %origin There have been %issued emeralds issued to %amntusers users with a collective debt of € $+ %cdebt $+ . The richest player is %topuser with € $+ %topamnt $+ . The current welfare payment is €500. Exchange rates: €120 to 1v (Panic). €1 to 8000z (DuoBOT). } on 1:TEXT:!flip*:*:{ calcorg checkpass $nick checkforupdate checkflips $nick var %2wager $$2 if $$2 != $null { if ($floor($$2) > 0 || $$2 = all || $$2 = left) { echo is > 0 or all ;no negative bets please if ($$2 isnum || $$2 = all || $$2 = left) { echo isnum or all or left if ($$2 = left) { msg %origin $nick has $flips($nick) flips remaining for today, day %day $+ . halt } if ($$2 != left) { echo it's not left if $flips($nick) <= 0 { echo no flips left msg %origin $nick $+ , you don't have any flips left for today. halt } } if ($$2 = all) { echo is all if $funds($nick) > 0 { echo has money var %2wager $funds($nick) } } ;numbers, please if (%2wager <= $funds($nick)) { echo wager is <= funds of user if %2wager > 0 { if $rand(1,2) = 1 { msg %origin $nick $+ 's coin flip lands on heads. $nick gets € $+ $floor(%2wager) $+ . ( $+ $calc($flips($nick) - 1) left) moneygive $nick $floor(%2wager) } else { msg %origin $nick $+ 's coin flip lands on tails. $nick loses € $+ $floor(%2wager) $+ . ( $+ $calc($flips($nick) - 1) left) moneygive $nick - $+ $floor(%2wager) } flipdec $nick } } else { msg %origin Insufficient funds, $nick $+ . } } else { msg %origin Invalid flip, $nick $+ . } } else { msg %origin Invalid flip, $nick $+ . } } } alias flips { if $readini money.ini $1 f != $null { return $readini money.ini $1 f } else { return 50 } } alias flipdec { var %f $readini money.ini $1 f if %f = $null { %f = 50 } echo ... %f flips left if %f = $null { echo %f = 50 writeini money.ini $1 f 49 } else { echo ... %f goes to $calc(%f - 1) writeini money.ini $1 f $calc(%f - 1) } echo last flipped on %day writeini money.ini $1 fday %day } alias checkflips { if $readini money.ini $1 fday != %day { echo $readini money.ini $1 fday != %day if $readini money.ini $1 f < 50 { writeini money.ini $1 f 50 } } } on 1:TEXT:!setpassword*:*:{ calcorg if ($pass($nick) = $null) { if $2 != $null { writeini money.ini $nick password $2 msg %origin Your password has been set. } } else { checkpass $nick writeini money.ini $nick password $2 msg %origin Your password has been set. } } on 1:TEXT:!login*:*:{ calcorg if ($2 = $pass($nick)) { set -s %login %login $nick msg %origin You have been logged in as $nick $+ . } else { msg %origin Incorrect password. } } on 1:TEXT:!logout*:*:{ calcorg checkpass $nick if $nick isin %login { set -s %login $remove(%login,$nick) msg %origin You have been logged out. } } on 1:TEXT:!setpublic*:*:{ calcorg checkpass $nick if ($2 = on || $2 = off) { writeini money.ini $nick checkfunds $2 msg %origin Checking your funds and inventory has been set to $2 $+ . } } on 1:TEXT:!mail*:*:{ calcorg checkpass $nick if $2 = $null { msg %origin You have $replace($mail($nick),0,no) message(s). } elseif $2 = check { msg %origin You have $replace($mail($nick),0,no) message(s). } elseif $2 = read { if $3 isnum { if $readini mail.ini $nick $3 != $null { msg %origin Message $3 $readini mail.ini $nick $3 } } } elseif $2 = del { if $3 isnum { if $readini mail.ini $nick $3 != $null { remini mail.ini $nick $3 writeini mail.ini $nick mail $calc($mail($nick) - 1) msg %origin Message $3 has been deleted. } } } elseif $2 = send { if $4- != $null { %message = from $nick at $fulldate $+ . Message reads: $4- sendmail $3 } } else { msg %origin !mail options: check read del send } } on 1:TEXT:!dayc*:*:{ calcorg checkforupdate echo It's %day msg %origin It is $date $+ , day %day $+ . } alias mail { if $readini mail.ini $1 mail != $null { return $readini mail.ini $1 mail } else { return 0 } } alias sendmail { var %i 1 if $readini mail.ini $1 1 != $null { while $readini mail.ini $1 %i != $null { inc %i } } writeini mail.ini $1 %i %message echo we're going from $mail($1) messages to $calc($mail($1) + 1) messages writeini mail.ini $1 mail $calc($mail($1) + 1) msg %origin Message sent to $1 $+ . if $1 isin %login { msg $1 You have one new message from $nick $+ . Type !mail read %i $+  to read it. halt } if $1 ison $chan { msg $1 You have one new message from $nick $+ . Type !mail read %i $+  to read it. halt } }