help with machine that lets you manufacture custom items

trying to make a machine that lets you make custom swords, not looking for balance in gameplay, as I'm making another text adventure that is testing quest capabilities.
Example:
You: "Machine, generate new sword."
Machine: whirrs to life
(script starts)
game creates new object
game asks what you want the sword to be called, sets alias to answer.
game asks you to describe the sword as if you were looking at it.
game asks you to set sword stats like durability, damage and that stuff, makes you use the money feature to pay for the sword's increased ability, so if you're poor you have a weak sword as you don't pay that much
game moves sword from inside the machine to container
(script ends)
The sword you requested leaves an output, and falls into a bucket.

pick up the sword
You pick up the sword.


This kind of pretty much handles everything but figuring the price and making the player pay for it. (I set a take script on the sword which says "You haven't paid for it." and the player can't pick it up until that is changed.)

I don't know how your money system works.

It shouldn't be too hard to add that part once you see how this works.

Paste it into a new game to play around with it and make it behave like you want it to behave.

handled = false
msg ("Name the sword.")
get input {
  result = Trim(result)
  create (result)
  obj = GetObject(result)
  game.new_sword = obj
  msg ("Describe what it looks like.")
  get input {
    obj.description = result
    msg ("Enter durability (1 -10) (or whatever)")
    get input {
      if (not IsNumeric(result)) {
        msg ("You messed that all up. No sword for you!")
        destroy (obj.name)
        return (false)
      }
      result = ToInt(result)
      if (result > 0 and result < 11) {
        obj.durability = result
        msg ("What's the damage? [1 - 10]")
        get input {
          if (IsNumeric(result)) {
            result = ToInt(result)
            if (result > 0 and result < 11) {
              obj.damage = result
              msg ("You hear a resounding WHIRRR.")
              MoveObjectHere (obj)
              msg (CapFirst(obj.name) + " is here.")
              obj.take => {
                msg ("You haven't paid for it yet!")
              }
              handled = true
            }
          }
        }
      }
    }
  }
}
on ready {
  if (not handled) {
    msg ("You messed that all up. No sword for you!")
    destroy (obj.name)
  }
}

get input {
  result = Trim(result)
  create (result)
  obj = GetObject(result)

This is problematic. If the player enters the name of an object that already exists (like "player") the create will fail and you end up giving the player the ability to change the description and stats of any object.

Better to use:

swordname = GetUniqueElementName ("sword")
msg ("Name the sword.")
get input {
  alias = Trim(result)
  if (LengthOf (alias) = 0)) {
    alias = "The sword with no name"
  }
  msg ("Describe what it looks like.")
  get input {
    description = Trim (result)
    msg ("Enter durability (1 -10) (or whatever)")
    get input {
      if (not IsInt(result)) {
        msg ("That's not a number!")
      }
      else {
        durability = ToInt(result)
        if (durability < 1 or durability > 10) {
          msg ("That's not a legal durability.")
        }
        else {
          msg ("Enter damage (1+)")
          get input {
            if (not IsInt(result)) {
              msg ("That's not a number!")
            }
            else {
              damage = ToInt(result)
              if (damage < 1) {
                msg ("That's not a legal damage.")
              }
              else {
                create (swordname)
                newsword = GetObject (swordname)
                newsword.look = description
                newsword.durability = durability
                newsword.damage = damage
                newsword.price = durability * (2 + damage) + GetRandomInt (-2, 6)
              }
            }
          }
        }
      }
    }
  }
}
on ready {
  newsword = GetObject (swordname)
  if (newsword = null) {
    msg ("The machine clatters to a halt and a red light flashes. You might need to start over if you want a sword.")
  }
  else {
    MoveObject (newsword, bucket)
    msg ("The machine whirrs, and a {object:" + swordname + "} drops out into the {object:bucket}. If you want to buy it, it will cost " + FormatMoney (newsword.price) + ".")
    newsword.take => {
      msg ("It will cost " +FormatMoney (this.price) + " to take this.")
      if (game.pov.money >= this.price) {
        game.buying = this
        Ask ("Would you like to buy " + GetDisplayName (this) + "?") {
          if (result) {
            game.pov.money = game.pov.money - game.buying.price
            game.buying.parent = game.pov
            game.pov.buying.take = true
            msg ("You take it.")
          }
          else {
            msg ("You leave it.")
          }
        }
      }
      else {
        msg ("You can't afford it.")
      }
    }
  }
}

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums