MenuMate Tutorial

From the Oblivion ConstructionSet Wiki
Revision as of 20:55, 7 December 2008 by imported>Speedo (→‎XML)
Jump to navigation Jump to search

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 name="main"/>
  <dialog name="deposit"/>
  <dialog name="withdraw"/>
  <dialog name="buttondemo"/>
</menu>

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

<!-- This dialog inverts its counterbuttons via a togglebutton + toggle variable -->
<deposit>
  <text format="Deposit Amount: %.0f%rYou have %.0f gold">
    <param name="temp"/>
    <param name="playerGold"/>
  </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 

      player.RemoveItem 0000000F BankDemo.temp 

      MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
    </script>
  </exitbutton>
  
  <exitbutton>
    <text format="Cancel"/>
  </exitbutton>
</deposit>

<!-- This dialog makes use of the toggle key(s) to invert its counters -->
<withdraw>
  <text format="Withdraw Amount: %.0f%rYour balance is %.0f gold%r%rHold one of these keys to decrease the amount: [INVERTKEYS]">
    <param name="temp"/>
    <param name="accountBalance"/>
  </text>
  
  <counterbutton targetvar="temp" amount="1" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="10" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="100" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <counterbutton targetvar="temp" amount="1000" maxvar="accountBalance" minvar="minVar" usekeyinvert="1">
    <text format="[STATE]"/>
  </counterbutton>
  
  <exitbutton>
    <text format="Finish"/>
    <script>
      set BankDemo.accountBalance to BankDemo.accountBalance - BankDemo.temp 

      player.AddItem 0000000F BankDemo.temp 

      MessageBox "Your new balance is %.0f gold" BankDemo.accountBalance
    </script>
  </exitbutton>
  
  <exitbutton>
    <text format="Cancel"/>
  </exitbutton>
</withdraw>