Location Menu

metalmario991
30 May 2016, 23:29
For my game, I wanna make it so you can take a vechile to a different location. I wanna know how I would do this. I know I can do this with the menu option, but I don't know how to make it so the option the player picks, will be where they are taken.

HegemonKhan
31 May 2016, 01:35
you need to create a String/Object List Attribute which holds the names of the rooms you want to be able to travel to, which you use to goto that room.

Object List Attributes can only be created directly via in-code, as it is unfortunately missing from the GUI~Editor. But, you can use a String List Attribute too, you just have to use an additional Script/Function: 'GetObject(your_string_list_string_choice)', for it.

here's sample code for using each Attribute Type:

Object List Attribute:

<object name="player">
<attr name="parent" type="object">room</attr>
</object>

<object name="room">
</object>

<object name="room2">
</object>

<object name="room3">
</object>

<object name="vehicle_object">
<attr name="alias" type="string">vehicle</attr>
<attr name="parent" type="object">room</attr>
<attr name="travel_location_objectlist_attribute" type="objectlist">
<value>room</value>
<value>room2</value>
<value>room3</value>
</attr>
<attr name="travel" type="script">
vehicle_travel_function
</attr>
<attr name="displayverbs" type="stringlist">
<value>travel</value>
</attr>
</object>

<function name="vehicle_travel_function">
show menu ("Travel Location?", vehicle_object.travel_location_objectlist_attribute, false) {
if (not player.parent = result) {
player.parent = result
vehicle_object.parent = result
msg ("You get into the vehicle and travel to " + result + ".")
} else {
msg ("You're already at this location, silly.")
}
}
</function>

<verb>
<property>travel</property>
<pattern>travel</pattern>
<defaultexpression>You can't travel there.</defaultexpression>
</verb>


String List Attribute:

<object name="player">
<attr name="parent" type="object">room</attr>
</object>

<object name="room">
</object>

<object name="room2">
</object>

<object name="room3">
</object>

<object name="vehicle_object">
<attr name="alias" type="string">vehicle</attr>
<attr name="parent" type="object">room</attr>
<attr name="travel_location_stringlist_attribute" type="stringlist">
<value>room</value>
<value>room2</value>
<value>room3</value>
</attr>
<attr name="travel" type="script">
vehicle_travel_function
</attr>
<attr name="displayverbs" type="stringlist">
<value>travel</value>
</attr>
</object>

<function name="vehicle_travel_function">
show menu ("Travel Location?", vehicle_object.travel_location_stringlist_attribute, false) {
object_variable = GetObject (result)
if (not player.parent = object_variable) {
player.parent = object_variable
vehicle_object.parent = object_variable
msg ("You get into the vehicle and travel to " + result + ".")
} else {
msg ("You're already at this location, silly.")
}
}
</function>

<verb>
<property>travel</property>
<pattern>travel</pattern>
<defaultexpression>You can't travel there.</defaultexpression>
</verb>