Newsgroups: rec.arts.int-fiction
Path: nntp.gmd.de!Dortmund.Germany.EU.net!Germany.EU.net!howland.reston.ans.net!vixen.cso.uiuc.edu!usenet.ucs.indiana.edu!news.cs.indiana.edu!shulick@raisin.ucs.indiana.edu
From: "Sam Hulick" <shulick@raisin.ucs.indiana.edu>
Subject: Inform: Another donation for you coders
Message-ID: <1995Sep5.144558.10610@news.cs.indiana.edu>
Organization: Vallen Software
Date: Tue, 5 Sep 1995 14:45:47 -0500
Lines: 101


Here is a simple money system I use in my game, including buying
things.  I must give credit for the money object to someone else who gave
me the idea.  I figured out the rest ;)  Enjoy.

[ moneyBefore;
   Insert, PutOn, Wear, Drop: "Don't bother.";
   Take: playcash.capacity = playcash.capacity + self.capacity;
         remove self;
         "You feel a bit richer now.";
];

! To be moved to the player in Initialise()
Object playcash "money"
 with  parse_name [ i j;
          if (self.capacity == 0) j = 'lack'; else j = 'money';
          while (NextWord() == 'money' or 'cash' or j) i++;
          return i;
       ],
       short_name [;
          if (self.capacity == 0) print "embarrassing lack of money";
          else print "money";
          rtrue;
       ],
       capacity 0,
       article "your",
       before [;
        PutOn, Insert, Drop, Give, GiveR, Transfer:
           if (self.capacity == 0) "But you don't even have any money!";
       ],
       description [ d r;
          if (self.capacity ~= 0)
          {
             print "It's your cash.  You count $";
             if (self.capacity > 999)
             {
                d = self.capacity / 1000;
                r = self.capacity % 1000;
                print d, ","; 
                if (r < 10) print "00";
                else { if (r < 100) print "0"; }
                print r;
             }
             else print self.capacity;
             ".";
          }
          "You, my friend, are broke.";
       ];

! here's how to implement money:
Object tbill "twenty dollar bill"
 with  name "twenty" "bill",
       description "ooh, money.",
       before #r$moneyBefore,
       capacity 50;  !worth $50

Be sure to REPLACE BuySub!  And also REPLACE RTakeSub--new routines
follow...


[ BuySub lft;
   if (noun has animate) { print (The) noun, " wouldn't go for that.^";
       rtrue; }
   if (noun.&price == 0 || noun.price == 0) "That's not for sale.";
   if (playcash notin player || playcash.capacity == 0) "But you have \
        no money!";   

   if (noun.price > playcash.capacity)
   {
      lft = noun.price - playcash.capacity;
      print "You can't afford ", (the) noun, ".  You need ";
      EnglishNumber(lft);
      " more dollar";
      if (lft == 1) "."; else "s.";
   }

   playcash.capacity = playcash.capacity - noun.price;
   noun.price = 0;
   move noun to player;
   print "You purchase ", (the) noun; ".";
];

And in RTakeSub..

[ RTakeSub fromobj i j k postonobj;
  if (noun==player) return L__M(##Take,2);
 [...snip snip...]

after that last line up there, add this:

  if (noun.&price ~= 0 && noun.price > 0) "You can't just take that!  \
        You'll have to purchase it.";


Enjoy!

-- 
--- Sam Hulick ------------- shulick@indiana.edu ---------------------
Systems Consultant        | Homepage:
Indiana College Placement |    http://copper.ucs.indiana.edu/~shulick/
  and Assessment Center   | PGP public key available on request
