How do I make it so in every room, there are different chances (or equal chances) of different objects spawning in. Like rocks, sticks, leaves, etc. And a maximum to how much spawns in a room at once. Trying to best to avoid Libraries.
The first.
firsttime {
SpawnZombie (this)
}
You can also do it with attributes, but it's trickier.
if (game.spawn = 2) {
SpawnZombie (this)
}
else {
msg ("...But nothing came.")
}
I think Empherdaen wants each room to have its own random "window-dressing", i.e., random stackable crafting objects for the player to collect. I haven't dealt with cloning, so am not equipped to advise about that.
Hey again Enpherdaen here is the first part in that same series https://www.youtube.com/watch?v=BUGNbe2--Yk it shows how to make randomized room spawner for items.
Oh, very sorry. I misunderstood the question. I have reading difficulties, if you haven't noticed.
Here is one way to do it...
I have a Split variable that contains the index list of room descriptions.
that is then randomized.
Then the rooms are numbered 1 through 20
That way, the 5th entry in the list is the description for room #5
Then a switch to select which room description to show.
The same could be used to random items, one to a room.
You could also use a for loop to seed stuff in each room.
http://textadventures.co.uk/games/view/g4jaujz2ceipk6vi3cfx0a/wumpus-3-0
(filler for getting my edited post, updated/posted)
here's an example:
(not fully complete, some more error and exception handling can be added to the 'spawn_data_object.set_spawn_script_attribute' as I got tired, and can still be refactored/stream-lined/improved further such as reducing some code redundency via using Delegates with the Script Attributes, and the code logic/design itself can probably be done better too)
<game name="example_game">
<attr name="pov" type="object">player</attr>
<attr name="start" type="script">
do (start_data_object, "start_script_attribute")
</attr>
</game>
<object name="start_data_object">
<attr name="start_script_attribute" type="script">
do (visitable_data_object, "set_visitable_objectlist_script_attribute")
do (visitable_data_object, "set_visitable_objectlist_count_script_attribute")
do (spawn_data_object, "set_spawn_objectlist_script_attribute")
do (spawn_data_object, "set_spawn_objectlist_count_script_attribute")
do (spawn_data_object, "set_spawn_script_attribute")
</attr>
</object>
<object name="spawn_data_object">
<attr name="max_spawn_count_integer_attribute" type="int">0</attr>
<attr name="spawn_objectlist_count_integer_attribute" type="int">0</attr>
<attr name="spawn_objectlist_attribute" type="objectlist">rock;stick;leaf;bush;cave;bear;wolf</attr>
<attr name="set_max_spawn_count_script_attribute" type="script">
if (not HasInt (this, "spawn_objectlist_count_integer_attribute")) {
do (this, "set_spawn_objectlist_count_script_attribute")
}
msg ("Max Spawn Count? (0 to " + this.spawn_objectlist_count_integer_attribute + ")")
get input {
if (IsInt (result)) {
input_integer_variable = ToInt (result)
if (input_integer_variable >= 0 and input_integer_variable <= this.spawn_objectlist_count_integer_attribute) {
this.max_spawn_count_integer_attribute = input_integer_variable
} else {
do (this, "set_max_spawn_count_script_attribute")
}
} else {
do (this, "set_max_spawn_count_script_attribute")
}
}
</attr>
<attr name="set_spawn_objectlist_count_script_attribute" type="script">
if (not HasAttribute (this, "spawn_objectlist_attribute")) {
do (this, "set_spawn_objectlist_script_attribute")
}
this.spawn_objectlist_count_integer_attribute = ListCount (this.spawn_objectlist_attribute)
</attr>
<attr name="set_spawn_objectlist_script_attribute" type="script">
if (not HasAttribute (this, "spawn_objectlist_attribute")) {
this.spawn_objectlist_attribute = NewObjectList ()
}
foreach (object_variable, GetDirectChildren (this)) {
if (not ListContains (this.spawn_objectlist_attribute, object_variable)) {
list add (this.spawn_objectlist_attribute, object_variable)
}
}
foreach (object_variable, this.spawn_objectlist_attribute) {
if (not Contains (this, object_variable)) {
list remove (this.spawn_objectlist_attribute, object_variable)
}
}
</attr>
<attr name="set_spawn_script_attribute" type="script">
foreach (visitable_object_variable, visitable_data_object.visitable_objectlist_attribute) {
spawn_objectlist_variable = NewObjectList ()
foreach (spawn_object_variable, this.spawn_objectlist_attribute) {
list add (spawn_objectlist_variable, spawn_object_variable)
}
do (this, "set_max_spawn_count_script_attribute")
ask ("Random?") {
if (result) {
for (not_used_variable, 1, this.max_spawn_count_integer_attribute) {
spawn_object_variable = ObjectListItem (spawn_objectlist_variable, GetRandomInt (0, this.max_spawn_count_integer_attribute - 1))
list remove (spawn_objectlist_variable, spawn_object_variable)
clone_object_variable = CloneObject (spawn_object_variable)
clone_object_variable.name_of_original_object_string_attribute = spawn_object_variable.name
clone_object_variable.parent = visitable_object_variable
}
} else {
for (not_used_variable, 1, this.max_spawn_count_integer_attribute) {
show menu ("Select Item", spawn_objectlist_variable, false) {
spawn_object_variable = result
list remove (spawn_objectlist_variable, spawn_object_variable)
clone_object_variable = CloneObject (spawn_object_variable)
clone_object_variable.name_of_original_object_string_attribute = spawn_object_variable.name
clone_object_variable.parent = visitable_object_variable
}
}
}
}
}
</attr>
<object name="rock">
<inherit name="spawn_type" />
</object>
<object name="stick">
<inherit name="spawn_type" />
</object>
<object name="leaf">
<inherit name="spawn_type" />
</object>
<object name="bush">
<inherit name="spawn_type" />
</object>
<object name="cave">
<inherit name="spawn_type" />
</object>
<object name="bear">
<inherit name="spawn_type" />
</object>
<object name="wolf">
<inherit name="spawn_type" />
</object>
</object>
<object name="visitable_data_object">
<attr name="visitable_objectlist_attribute" type="objectlist">room;room_2;room_3;room_4</attr>
<attr name="set_visitable_objectlist_count_script_attribute" type="script">
if (not HasAttribute (this, "visitable_objectlist_attribute")) {
do (this, "set_visitable_objectlist_script_attribute")
}
this.visitable_objectlist_count_integer_attribute = ListCount (this.visitable_objectlist_attribute)
</attr>
<attr name="set_visitable_objectlist_script_attribute" type="script">
if (not HasAttribute (this, "visitable_objectlist_attribute")) {
this.visitable_objectlist_attribute = NewObjectList ()
}
foreach (object_variable, GetDirectChildren (this)) {
if (not ListContains (this.visitable_objectlist_attribute, object_variable)) {
list add (this.visitable_objectlist_attribute, object_variable)
}
}
foreach (object_variable, this.visitable_objectlist_attribute) {
if (not Contains (this, object_variable)) {
list remove (this.visitable_objectlist_attribute, object_variable)
}
}
</attr>
<object name="room">
<inherit name="visitable_type" />
</object>
<object name="room_2">
<inherit name="visitable_type" />
</object>
<object name="room_3">
<inherit name="visitable_type" />
</object>
<object name="room_4">
<inherit name="visitable_type" />
</object>
</object>
<object name="player_data_object">
<attr name="player_objectlist_attribute" type="objectlist">player</attr>
<object name="player">
<inherit name="player_type" />
<attr name="parent" type="object">room</attr>
</object>
</object>
<type name="player_type">
</type>
<type name="visitable_type">
</type>
<type name="spawn_type">
<inherit name="clone_type" />
</type>
<type name="clone_type">
<attr name="name_of_original_object_string_attribute" type="string">unknown</attr>
</type>
ask if you need any help implementing/adapting/adjusting this example into/for your game, and/or if it doesn't work (got errors), and/or need help with understanding it or how it works, or whatever else you need help with or whatever.