Issue with a Crafting System

In the game I am currently making, I am going to have a crafting system as it is a survival game. I plan on making it so the player types in "craft (item)" and if the player possesses the required items, it duplicates an unseen object and adds it into their inventory. As an object is made, the objects used to make it must be deleted. Problem is, there are likely going to be many of those objects in the game so I don't know how to tell quest which of the clones to delete. Ex: Stones + Sticks = Fire Pit, so the stones and sticks in the player's inventory must be deleted, but not the sticks and stones that are randomly generated in the room and other rooms.


Here, look at this. It's a stacking library.
https://textadventures.co.uk/forum/samples/topic/3515/stackable-library

It's complicated, but you get the point.


Here is another stacking library:
https://github.com/ThePix/quest/wiki/StackLib


The easiest way is probably to have an attribute which is a reference to the unseen object it's a clone of. In the initialisation script for each of the unseen items, you'd have this.prototype = this. Then when you need to find how many fish the player is holding, you can do:
carried_fish = FilterByAttribute(GetAllChildObjects(player), "prototype", unseen_fish_object)
and use ListCount() to get the number, or delete items 0, 1, 2, etc for however many your recipe needs. I'm not sure what you'd be crafting from a fish, but it's just an example.

In this case, you'd probably want to define a couple of functions

<function name="GetNumberCarried" parameters="object">
  carried = FilterByAttribute(ScopeReachableInventory(), "prototype", object)
  return ListCount(carried)
</function>

<function name="ConsumeIngredient" parameters="object, number">
  carried = FilterByAttribute(ScopeReachableInventory(), "prototype", object)
  if (ListCount(carried) < number) {
    error ("You don't have "+number+" of "+GetDisplayAlias(object))
  }
  for (i, 1, number) {
    to_destroy = ListItem(carried, 0)
    list remove (carried, to_destroy)
    destroy (to_destroy.name)
  }
</function>

So for your campfire example, you could have something likeā€¦

case (campfire) {
  sticks = GetNumberCarried(stick)
  stones = GetNumberCarried(stone)
  if (sticks > 4) {
    sticks = "enough"
  }
  else {
    sticks = sticks + "/4"
  }
  if (stones > 4) {
    stones = "enough"
  }
  else {
    stones = stones + "/2"
  }
  if (sticks+stones = "enoughenough") {
    ConsumeIngredient (stick, 4)
    ConsumeIngredient (stone, 2)
    CloneObjectAndMoveHere (campfire)
  }
  else {
    msg ("You don't have enough sticks and stones. You have "+sticks+" sticks and "+stones+" stones.")
  }
}

Or, if you're likely to be carrying more than one of the same item, you could follow the advice above and use a stacking library; which means one inventory slot can hold multiples of the same item, and also (I assume) provides an easy way to find out if you're carrying a certain object.

The way I'm building my stacking library (I didn't like any of the existing ones), the objects all start in the player's inventory, but invisible. That way you can easily use the initial object name in the code to refer to the one(s) the player is carrying. (the object has a 'drop' script that clones it if there isn't already one in the destination room then adjusts the "count" attributes of both; a 'take' script that adjusts the inventory limit; and a 'changedcount' script that sets it to invisible if the number is zero, and changes the alias to be singular or plural otherwise)


Umm... That seems pretty advanced for me but so did time and I got that done in 2 days.


Hello I started a survival series never finished but the easiest way to deal with clones and stacking I show in this video.
https://www.youtube.com/watch?v=HD1Gj88KeQE&t=39s


Thanks Onimike.


Wow, onimike!

You should make a thread directing everyone to your videos!

Well played, sir!


No problem Enpherdaen also in that series the first part I make a randomized room spawner https://www.youtube.com/watch?v=BUGNbe2--Yk to help with your other post. And Quest Forum Questers I posted it in forums quite some time ago it never got pinned so I didn't worry, thats why I come back and just direct people because I know most use the GUI editor like myself. I might pick the my videos back up seeing as alot of views have gone up so it seems alot more people are into quest now and I have my second screen back.


I also often reference/mention that 'onimike' has vids, though in past didn't have the link on hand, and now usually too lazy (or I forget that I have the link or where I have the link stored, lol) to get the link at hand and post it... lol


Onimike is there a part 2?


https://www.youtube.com/channel/UCGSCL0CED0oIG8J1mKyDoMw/videos


Enpherdaen it is 6 parts in total i show how to make item spawner, then stack objects and using object types, then chop down tree, then the final 3 parts i show how to do day night cycle and campfire. Here is full playlist https://www.youtube.com/playlist?list=PLVDq5KtDCqnYLM7jcdkdGBFGidzgqIYWW sorry their not in order will fix later but they are numbered.


Log in to post a reply.

Support

Forums