MenuMate Tutorial

Revision as of 11:52, 30 November 2008 by imported>Speedo (created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This tutorial shows a basic example of menu creation with MenuMate. We will create a basic menu interface for a bank-type mod, which allows the player to deposit and withdraw money from a bank account. The menu created in this tutorial is included in the MenuMate download.

Goals

Our menu will consist of three dialogs:

  • The main menu. Will show the player their account balance and allow them to choose between making a deposit or withdrawal.
  • The deposit menu. Allows the player to enter an amount of gold to deposit, up to the amount they currently are carrying.
  • The withdrawal menu. Allows the player to enter an amount of gold they wish to withdraw from their account, up to their current account balance.

Implementation

Script

We still need a small script to support our menu XML. This script will display the menu and contain several variables used by the menu.

scn BankDemoScript

int accountBalance ; player's account balance

ref playerRef ; ref used to display the player's name
int playerGold ; player's current gold
int minVar ; minimum amount for the counterbuttons
int temp ; used for player input
int invert ; toggle for the inversion of the counterbuttons

begin GameMode
  ; initialize the variables
  set playerRef to player
  set playerGold to player.GetItemCount Gold001
  set minVar to 0
  set temp to 0
  set invert to 0
  
  ; display the menu
  mmLoadMenu "demo.xml"
  StopQuest BankDemo
end

XML

The XML of our desired menu is as follows:

<?xml version="1.0" ?>

<menu>
  <start>main</start>
  <dialog>deposit</dialog>
  <dialog>withdraw</dialog>
</menu>

<main>
  <text format="Greetings %n!%rYour balance is %.0f gold, what do you wish to do?">
    <param>playerRef</param>
    <param>accountBalance</param>
  </text>
  
  <linkbutton target="deposit">
    <text format="Make a deposit"/>
  </linkbutton>
  
  <linkbutton target="withdraw">
    <text format="Withdraw money"/>
  </linkbutton>
  
  <exitbutton>
    <text format="Nothing"/>
  </exitbutton>
</main>

<deposit>
  <text format="Deposit Amount: %.0f%rYou have %.0f gold">
    <param>temp</param>
    <param>playerGold</param>
  </text>
  
  <togglebutton targetvar="invert" truetext="subtracting" falsetext="adding">
    <text format="Toggle Add/Subtract%r(currently [STATE])"/>
  </togglebutton>
  
  <counterbutton targetvar="temp" amount="1" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="10" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="100" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="1000" invertvar="invert" maxvar="playerGold" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <exitbutton>
    <text format="Finish"/>
    <script>
      set BankDemo.accountBalance to BankDemo.accountBalance + BankDemo.temp &#10;
      player.RemoveItem 0000000F BankDemo.temp &#10;
      MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
    </script>
  </exitbutton>
  
  <exitbutton>
    <text format="Cancel"/>
  </exitbutton>
</deposit>

<withdraw>
  <text format="Withdraw Amount: %.0f%rYour balance is %.0f gold">
    <param>temp</param>
    <param>accountBalance</param>
  </text>
  
  <togglebutton targetvar="invert" truetext="subtracting" falsetext="adding">
    <text format="Toggle Add/Subtract%r(currently [STATE])"/>
  </togglebutton>
  
  <counterbutton targetvar="temp" amount="1" invertvar="invert" maxvar="accountBalance" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="10" invertvar="invert" maxvar="accountBalance" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="100" invertvar="invert" maxvar="accountBalance" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="1000" invertvar="invert" maxvar="accountBalance" minvar="minVar">
    <text format="[STATE]"/>
  </counterbutton>
  
  <exitbutton>
    <text format="Finish"/>
    <script>
      set BankDemo.accountBalance to BankDemo.accountBalance - BankDemo.temp &#10;
      player.AddItem 0000000F BankDemo.temp &#10;
      MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
    </script>
  </exitbutton>
  
  <exitbutton>
    <text format="Cancel"/>
  </exitbutton>
</withdraw>