Advice on Cloning or something else!

Anonynn
So...I ran into a problem the other day. Someone got an article of clothing in my game and then ended up finding the same article of clothing later on. In the "Object Inventory" the second find of the clothing item was stated as "worn" and when they put the object on again, it double the stats that it's supposed to give. How I generally do things in my game is I create a list like "Equipment" for example, and build items there in the list and then set up scripts that moves those items into the game.

I was wondering if there is a better way of doing this like for example cloning the main objects leaving those objects in the "Equipment" section and sending their clones into the game for the player to find? I'm not sure what I should do to solve this problem.

Any advice?

The Pixie
My game Deeper does this a lot. Here is an example of a function that takes a prototype object and a location, clones the prototype in the location and then modifies the description and price it to give variety.

<function name="CreateTreasure" parameters="obj, room">
o = CloneObjectAndMove(obj, room)
if (HasString(o, "look")) o.look = RandomisePlus(o.look)
o.price = o.price - GetRandomInt(o.price/-4, o.price/4)
</function>



<function name="Randomise" parameters="s" type="string">
mylist = Split (s, "{")
output = StringListItem (mylist, 0)
list remove (mylist, output)
count = 0
foreach (s1, mylist) {
list1 = Split (s1, "}")
if (not ListCount (list1) = 2) {
error ("Unable to parse: " + s)
}
s2 = StringListItem (list1, 0)
list2 = Split (s2, "|")
pos = GetRandomInt (0, ListCount (list2) - 1)
extra = StringListItem (list2, pos)
output = output + extra + StringListItem (list1, 1)
count = count + 1
}
return (output)
</function>



<function name="RandomisePlus" parameters="s" type="string">
s = Randomise(s)
s = Replace(s, "%gem%", PickOneStr("ruby|sapphire|crystal|amethyst|emerald|diamond|opal|moonstone|chrysoberyl|garnet|jade|onyx|sunstone|topaz|tourmaline|turquoise"))
s = Replace(s, "%metal%", PickOneStr("electrum|gold|silver|white gold|crown gold|meteorite iron|mithril|adamantine|blood alloy"))
s = Replace(s, "%stone%", PickOneStr("alabaster|soapstone|chlorite|wonderstone|limestone|onyx|obsidian|marble|moonstone|coral|amber"))
return (s)
</function>



<!--
Randomly picks asubstring of the given string, or a string from a string list. Substrings should be separated by a vertical bar.
-->
<function name="PickOneStr" parameters="lst" type="string">
if (TypeOf(lst) = "string") {
lst = Split(lst, "|")
}
index = GetRandomInt(0, ListCount(lst) - 1)
return (StringListItem(lst, index))
</function>


Anonynn
Hmm. Looks really interesting. So I could use this in my game? Or would you have problems with that? Do you foresee anything having trouble carrying over from the code? Or should I create a modified version somehow? Also, thanks Pix!

The Pixie
Anything I post on the forum is free for others to use and modify as they see fit, so go ahead and do what you want with it.

Thinking about it, I should have explained how to use it. Set up your prototype as normal, but give is an integer attribute called "price". Give it an alias too. For the description (the "look" attribute), you can put in a list of options like this:

The sword was {long|broken|rusty} and made of %metal%.

It will randomly select one of long, broken and rusty, and pick a metal from the list in RandomisePlus (you could use the text processor to get random text, but then it would change each time the item is examined; this way the description is set in stone when the item is created).

The %metal% thing is for when you want to use the same list of options several times. You can do %gem% and %stone%. The RandomisePlus is specific to what I wanted in my game, you may well want to add other options. Just realised you also need PickOneStr, so I edited my post to include that.

The Pixie
Better still, use the code here:
viewtopic.php?f=18&t=6263

Anonynn
Just curious do either one of those account for like "text processor" descriptions or "size limitation" functions? What I mean is, I have all articles of clothing in my game described in the player.object's, 'look at 'description when it's worn.

The Pixie
Not sure I understand, but the functions on the other thread are compatible with text processor commands, so if you had a text processor command that tells the player is the garment is too big or too small, I think it will work.

Anonynn
Oh okay!

What I meant was......well, for example. Let's say I have an item called:

"Dirty Shoe"

I set up the prototype... color red/blue/green, laces frayed/leather/string etc

In my player.object, "look at" script, I have the descriptions of the game's current clothing and how each piece fits on the player's body type and etc. If I were to use the Prototype Function. How would I program the text processor to modify the cloned item to fit in those descriptions? @_@ Does that make sense?

Like for example. I have a fixed item..

"Brown Boots" they look brown and are made of leather, and have so and so

"Prototype Boots" they look colorinserthere and are made of bootmaterialhere, and have so and so

The Pixie
Thinking about it, there is an issue for the text processor. The problem for any cloned item, whether from my functions or not, is that you will not know the name of the item in advance. If the prototype is "boots", the first cline will be "boots1", the second "boots2", etc. The text processor requires the name of the object, eg:
{if boots2.size>4:they are too big for you. }

So I have updated my functions so you can use #### as a stand-in for the object name:
{if ####.size>4:they are too big for you. }

So the answer is now: Yes.

Anonynn
Great!

Actually, why wouldn't text processor work for that? I mean if you create a prototype "boot" and know in advance you'll be using a clone of that proto-type labeled boots1 ...couldn't you just type a predetermined description of "boots1" and leave #### for all the color and material names?

The Pixie
If it is a value in the prototype, that will be fine. I was assuming your clone was a random size, and so you need to test the size of the clone, not the prototype.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums