New to Quest but ambitious to write rpgs that help me teach principles of music online

I want NPCs to collect items off screen and present them at a hub periodically.
How do I get them to have random items. If it is a string list how do they select from the list a random amount of random items? I assume it is Pickering with a random command but I can't get it to work.
Please help. I am not a coder and have been using the Web version


Honestly, I would use a series of if statements and getrandomInt functions and variables. But that's just me.

I suppose you would need something like this...

obj.selectobject => {
  this.holding = GetObject(PickOneString("paper;pen;scissors"))
}

It's relatively simple to pick one object from a list. Picking a random number of random items is also simple, but there's more than one way to do it. Basically, how do you want it to decide how many items to choose?

I'll assume you have a list of objects to choose from objects_to_choose, and want to store the result in a list result.

Here's one example, that will choose between 3 and 7 objects:

result = NewObjectList()
for (i, 1, GetRandomInt (3, 7)) {
  not_chosen_yet = ListExclude (objects_to_choose, result)
  list add (result, PickOneObject (not_chosen_yet))
}

Or you could do this, which chooses a more open-ended number:

result = NewObjectList()
while (ListCount (result) < ListCount (objects_to_choose) and RandomChance (50)) {
  not_chosen_yet = ListExclude (objects_to_choose, result)
  list add (result, PickOneObject (not_chosen_yet))
}

In this example, as long as there are more objects to choose, the script will have a 50/50 chance of picking another one, or stopping.

This is assuming that the NPCs are just randomly choosing objects from a list. If you want to make this take time, you could have a turnscript do something like this:

not_chosen_yet = FilterByNotAttribute (objects_to_choose, "parent", npc)
if (ListCount (GetDirectChildren (npc)) = 0 or RandomChance (60) and ListCount (not_chosen_yet) > 0)  {
  obj = PickOneObject (not_chosen_yet)
  MoveObject (obj, npc)
}
else {
  // Have the NPC return to the hub with the objects they picked up
}

This way the NPC has a 60% chance each turn of picking up another object, and a 40% chance of returning to the hub with the objects they have collected. In this case I'm using the NPC's inventory rather than a result list.

A lot of this depends on how you want the NPC to act, and how you want the information to be stored. There are a lot of different ways to do this, and I don't know which ones are best for the situation you're looking at. In one of my first games, I had an NPC who would walk around the house when the player wasn't present, with a random chance of picking up objects and putting them back where they belong. So if the player moves an object, the NPC can put it back, and if the player leaves objects in the house that don't belong there, they will eventually end up in the trashcan.


Log in to post a reply.

Support

Forums