Menus

I wanted to create a gun with 4 modes to choose from, The gun will initiate a different reaction when used by a n object or if the gun is set to a different mode, can anyone tell me how to code something like that? I've checked the tutorial and unfourtunately I'm not even good at making a basic menu.


From the title, I believe you want to add a menu in which the players can change the mode. As an example, I will call the four modes Normal, Simple, Advanced and Expert.
This time, I added a verb called "change mode" for the gun, and there is a script running.
You may want to use a similar code:

ShowMenu ("Pick a mode", Split("Normal;Simple;Advanced;Expert"), false) {
  if (result="Normal") {
    GUN.mode = "normal"
  }
  if (result="Simple") {
    GUN.mode = "simple"
  }
  if (result="Advanced") {
    GUN.mode = "advanced"
  }
  if (result="Expert") {
    GUN.mode = "expert"
  }
}

Oh, also, make an attribute for the gun, let's call it "mode" for now.
It's a string list, and basically will be set after the menu.
For example, clicking on the expert option from above will make the mode contains the string "expert".

Now now, what's the use for doing this?
Just for an example, though, I added an attribute called "Attack" to the gun. So, if the mode is changed, the Attack will also change, and along with that, the player's Atk will change because there's a change script for GUN.Attack, in which:

if (GUN.worn=true) {
  player.Atk = GUN.Attack
}

considering the player's atk without gun is a 0.

Full code:

<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="testing2">
    <gameid>b23b3fc5-5ecb-48c7-940a-f83b382073d7</gameid>
    <version>1.0</version>
    <firstpublished>2020</firstpublished>
    <roomenter type="script">
    </roomenter>
    <start type="script">
    </start>
    <feature_advancedwearables />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <firstenter type="script">
    </firstenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <statusattributes type="stringdictionary">
        <item>
          <key>Atk</key>
          <value></value>
        </item>
      </statusattributes>
      <Atk type="int">0</Atk>
    </object>
    <object name="GUN">
      <inherit name="editor_object" />
      <inherit name="wearable" />
      <attr name="feature_startscript" type="boolean">false</attr>
      <mode>normal</mode>
      <changemode type="script">
        ShowMenu ("Pick a mode", Split("Normal;Simple;Advanced;Expert"), false) {
          if (result="Normal") {
            GUN.mode = "normal"
          }
          if (result="Simple") {
            GUN.mode = "simple"
          }
          if (result="Advanced") {
            GUN.mode = "advanced"
          }
          if (result="Expert") {
            GUN.mode = "expert"
          }
        }
      </changemode>
      <changedmode type="script">
        if (this.mode="normal") {
          GUN.Attack = 50
        }
        if (this.mode="advanced") {
          GUN.Attack = 70
        }
        if (this.mode="simple") {
          GUN.Attack = 15
        }
        if (this.mode="expert") {
          GUN.Attack = 10
        }
      </changedmode>
      <Attack type="int">50</Attack>
      <feature_wearable />
      <onafterwear type="script">
        player.Atk = player.Atk + GUN.Attack
      </onafterwear>
      <onafterremove type="script">
        player.Atk = 0
      </onafterremove>
      <usestandardverblist />
      <changedAttack type="script">
        if (GUN.worn=true) {
          player.Atk = GUN.Attack
        }
      </changedAttack>
      <inventoryverbs type="stringlist">
        <value>Look at</value>
        <value>Drop</value>
        <value>Wear</value>
        <value>Remove</value>
        <value>Change mode</value>
      </inventoryverbs>
    </object>
  </object>
  <verb>
    <property>changemode</property>
    <pattern>change mode</pattern>
    <defaultexpression>"You can't change mode " + object.article + "."</defaultexpression>
  </verb>
</asl>

There may be useless or meaningless things added though due to my brain being so slow today :v
Hope it helps xD


The menu code shown above could be simpler:

ShowMenu ("Pick a mode", Split("Normal;Simple;Advanced;Expert"), true) {
  gun.mode = LCase (result)
}

Then in the "use on" script, or anywhere it matters what the current mode is, you can do:

switch (gun.mode) {
  case ("simple") {
    // do something here
  }
  case ("normal") {
    // do something else here
  }
  case ("advanced", "expert") {
    // do it like this if there's any circumstances where 2 modes do the same thing
  }
}
Or a more advanced option [click to expand]…

If you have multiple items you want to set the mode of, or if you'd like to do it without the menu, you could use a command. I'd probably do something like:

if (HasAttribute (object, "availablemodes")) {
  options = NewStringList()
  if (IsDefined ("text")) {
    if (ListContains (object.availablemodes, LCase(text))) {
      list add (options, LCase(text))
    }
    else {
      foreach (mode, object.availablemodes) {
        if (Instr (mode, LCase (text)) > 0) {
          list add (options, LCase(text))
        }
      }
    }
    if (ListCount (options) = 0) {
      options = object.availablemodes
      msg (CapFirst(object.article)+" doesn't have a "+text+" mode.<br/>You can choose from:")
    }
    else if (ListCount (options) > 1) {
      msg ("Which mode did you mean?")
    }
  }
  else {
    options = object.availablemodes
    msg ("Which mode would you like to set "+object.article+" to?")
  }
  if (ListCount (options) = 1) {
    object.mode = ListItem (options, 0)
  }
  else {
    menu = NewStringList()
    foreach (mode, options) {
      list add (menu, "{command:set "+GetDisplayAlias(object)+" mode to "+mode+":"+CapFirst(mode)+"}")
    }
    SuppressTurnscripts()
    msg (FormatList (menu, ", ", ", or", "")+"?")
  }
}
else {
  SuppressTurnscripts()
  msg (CapFirst(object.article)+" doesn't have a mode you can set.")
}

with the command pattern: ^(set |mode |to (?<text>.+?) )+(?<object>.+?)(mode|to|(?<text>.+?)| )*$

So then the player can type set gun to normal mode or mode gun advanced or whatever, and it should work fine. Or they can type set mode gun and it will ask them what mode they want.

With this command, you would give the gun a stringlist attribute availablemodes which is a list of all the modes it has. You could put "set mode" on its displayverbs, which will present the player with a list of options, or you could put "set mode simple" or whatever on the displayverbs, so they can choose directly (though if you have a lot of modes, this would clutter the verbs list)


Log in to post a reply.

Support

Forums