View Single Post
  #1  
Old 02-15-2004, 08:57 AM
Monrezz's Avatar
Monrezz
Dragon
 
Join Date: Mar 2003
Location: #loc
Posts: 745
Default Money Conversion Quest

Just written a simple perl money conversion quest that converts the money given to the NPC to it's highest possible coinage.

e.g.
Give the NPC 10 copper = 1 silver returned.
Give the NPC 100 copper = 1 gold returned.
Give the NPC 50 copper, 5 silver and 19 gold = 2 platinum returned.


If you give the NPC a value that it can't upgrade it will give you the coin back and tell you it cannot be upgraded.
e.g.
Give the NPC 7 copper = 7 copper returned.
Give the NPC 8 gold = 8 gold returned.


If you give the NPC coinage that adds up to a decimal value it will be rounded down to the nearest full coin.
e.g.
Give the NPC 11 copper = 1 silver returned.
Give the NPC 19 gold = 1 platinum returned.
Give the NPC 55 copper, 97 silver and 107 gold = 117 platinum returned.


Not sure if this could help anyone but it was kinda fun to do and thought someone could use it. Just stick the following into a .pl file:

Code:
sub EVENT_SAY
{
	if($text =~ /Hail/i){
	quest::say("Greetings $name. Would you like me to [convert] some money?");}

	if($text =~ /convert/i){
	quest::say("Give me some loose change and I will change it into the highest coinage I can. I will always round down - I have to make a living somehow!");}
}

sub EVENT_ATTACK
{
	if(($ulevel > $mlevel) && ($mlevel < 51))
	{
	quest::say("Please, somebody help me! $name is attacking me!");
	quest::emote("calls out for help.");}

	else
	{
        @responses =
        ("Time do die, $name!",
        "That was a bad idea, $name!",
	"Prepare to die $name!",
	"Foolish $race, you think you can defeat me?");
        my $length = $#responses + 1;
        $length = rand($length);
        $length = int $length;
        quest::say($responses[$length]);
	}
}

sub EVENT_DEATH
{
	quest::say("My comrades will avenge my death!");
}

sub EVENT_ITEM
{
	$myplatinum = (($copper/1000) + ($silver/100) + ($gold/10) + $platinum);
	$mygold = (($copper/100) + ($silver/10) + $gold + (10*$platinum));
	$mysilver = (($copper/10) + $silver + (10*$gold) + (100*$platinum));
	$mycopper = ($copper + (10*$silver) + (100*$gold) + (1000*$platinum));

if($mycopper < 10){
	quest::say("Sorry, but I need at least 10 copper to upgrade you into silver. Here, have your money back.");
	quest::givecash($copper,0,0,0);}

if((($mycopper >= 10) && ($mycopper < 100)) || (($mysilver >= 1) && ($mysilver < 10))){
	quest::say("You gave me coins worth a total value of $mysilver silver. Here you go:");
	quest::givecash(0,$mysilver,0,0);}

if((($mycopper >= 100) && ($mycopper < 1000)) || (($mysilver >= 10) && ($mysilver < 100)) || (($mygold >= 1) && ($mygold < 10))){
	quest::say("You gave me coins worth a total value of $mygold gold. Here you go:");
	quest::givecash(0,0,$mygold,0);}

if(($mycopper >= 1000) || ($mysilver >= 100) || ($mygold >= 10) || ($myplatinum >= 1)){
	quest::say("You gave me coins worth a total value of $myplatinum platinum. Here you go:");
	quest::givecash(0,0,0,$myplatinum);}
}
__________________

kRPG Profile
Reply With Quote