Clone Function/Attribute Question ^_^

Anonynn
07 Feb 2017, 04:13Hello! I might be shooting in the dark here, but is there a way to create a function that upon picking up a cloned item it assigns a random set of attributes?
I know I could probably make an "if script" in the function, I was just wondering if there was an alternative way that I hadn't considered/thought about :) Thank you!
Anonynn.
The Pixie
07 Feb 2017, 08:05I had a load of them for Deeper. For example:
<!--
Creates a monster from the given prototype and level, in the given room.
Gives treasure too via GiveTreasure
Note that a bigger scaling factor makes higher level monsters easier
-->
<function name="CreateFromPrototypeLevel" parameters="obj, level, room"><![CDATA[
o = CloneObjectAndMove(obj, room)
if (level < 1) {
level = 1
}
if (level > ListCount(obj.types)) {
level = ListCount(obj.types)
}
scalingfactor = 3
if (HasInt(obj, "scalingfactor")) {
scalingfactor = obj.scalingfactor
}
o.alias = CapFirst(StringListItem(obj.types, level - 1))
o.listalias = null
do(o, "colourmylistalias")
o.desc = StringListItem(obj.descs, level - 1)
o.level = level
o.hitpoints = 3 * o.hitpoints / 4 + 20 * level / scalingfactor
o.defence = o.defence + level / scalingfactor
o.armour = o.armour + (level - 2) / scalingfactor
o.attackbonus = o.attackbonus + level / scalingfactor
o.damagedicenumber = o.damagedicenumber + (level - 1) / scalingfactor
o.damagebonus = o.damagebonus + (level - 2) / scalingfactor
o.damagedicesides = o.damagedicesides + (level - 3) / scalingfactor
o.descs = null
o.types = null
o.original = null
foreach (attack, GetDirectChildren(obj)) {
newattack = CloneObjectAndMove (attack, o)
newattack.attackbonus = newattack.attackbonus + level / scalingfactor
newattack.damagedicenumber = newattack.damagedicenumber + (level - 1) / scalingfactor
newattack.damagebonus = newattack.damagebonus + (level - 2) / scalingfactor
newattack.damagedicesides = newattack.damagedicesides + (level - 3) / scalingfactor
}
GiveTreasure (o)
]]></function>
<!--
Gives this monster treasure at random. By default, 5% of the time, but altered by
the monster's treasurechance attribute.
Treasure is picked at random from three rooms
rank1 if level less than 6
rank2 if level is 6 to 15
rank3 if level over 15
-->
<function name="GiveTreasure" parameters="obj">
if (RandomChance(obj.treasurechance)) {
if (RandomChance(3)) {
CreateScroll(obj.level, obj)
}
if (RandomChance(3)) {
CreateProtectionPotion(obj)
}
if (RandomChance(3)) {
CreateArmour(obj.level, obj)
}
if (RandomChance(6)) {
CloneObjectAndMove(masterhealingpotion, obj)
}
else {
master = GetTreasureMaster(obj.level)
CreateTreasure (master, obj)
}
GiveTreasure(obj)
}
</function>
<!--
Returns a string based on the input string, using text substitutions as the text
processor.
Additional these substitutions will be made:
%gem% a gem
%metal% a precious metal
%stone% an ornamental stone
-->
<function name="Randomise" parameters="s" type="string">
data = NewDictionary()
dictionary add (data, "fulltext", s)
s = ProcessTextSection(s, data)
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>
<!--
Creates a randomised treasure from the given prototype in the given room.
-->
<function name="CreateTreasure" parameters="obj, room">
o = CloneObjectAndMove(obj, room)
if (HasString(o, "look")) o.look = Randomise(o.look)
o.price = o.price - GetRandomInt(o.price/-4, o.price/4)
</function>
hegemonkhan
07 Feb 2017, 08:09<object name="data_object">
</object>
// this is to hold your desired attributes for use by the 'GetAttributeNames' Function (using an example of character attributes):
// (think of this as your effective 'attribute list' as the 'GetAttributenames' Function takes all of an Object's Attributes and puts them into a list. SO, ONLY PUT IN YOUR DESIRED ATTRIBUTES HERE, don't put in any other attribtes --- actually, I may need to handle whatever default/built-in attributes are given automatically... doh... let me know if this is an issue and I'll try to handle it for you)
<object name="character_attribute_data_object">
<inherit name="character_attribute_type" />
<attr name="condition_stringlist_attribute" type="simplestringlist">normal;alive</attr>
<attr name="strength_integer_attribute" type="int">0</attr>
// etc etc etc attributes
</object>
// this is to give your data object its needed attributes, that which though you do NOT want to be used by the 'GetAttributeNames' Function, as which you still need these attributes available for use in the Function:
<type name="character_attribute_type">
<attr name="parent" type="object">data_object</attr>
<attr name="alias" type="string">character attribute data object</attr>
<attr name="min_value_for_these_integer_attributes" type="int">0</attr>
<attr name="max_value_for_these_integer_attributes" type="int">100</attr>
<attr name="list_of_conditions_stringlist_attribute" type="simplestringlist">normal;alive;undead;poisoned;diseased;cursed;confused;parayled;asleep;etc etc etc</attr>
</type>
<function name="hk_in_progress_function_for_anonynn" parameters="cloned_object_parameter, data_object_parameter">
// creating a copy attribute stringlist (as a temporary-local VARIABLE: a stringlist Variable) so we can manipulate/work-with it in our/this Function:
attribute_stringlist_variable = NewStringList ()
foreach (attribute_variable, GetAttributeNames (data_object_parameter, false)) {
list add (attribute_stringlist_variable, attribute_variable)
}
// getting a random number for the getting of a random number-set of attributes to generate on the clone object:
random_number_set_of_attributes_variable = GetRandomInt (1, ListCount (attribute_stringlist_variable))
// generating/creating the random set of attributes and their values onto the cloned object:
// (ask if you need any parts of this explained)
for (not_used_variable, 1, random_number_set_of_attributes_variable) {
attribute_variable = StringListItem (attribute_stringlist_variable, GetRandomInt (0, ListCount (attribute_stringlist_variable) - 1))
if (TypeOf (data_object_parameter, attribute_variable) = "int") {
set (cloned_object_parameter, attribute_variable, GetRandomInt (GetInt (data_object_parameter, min_value_for_these_integer_attributes), GetInt (data_object_parameter, min_value_for_these_integer_attributes)))
}
// etc 'else if' handling for the other Attribute Types (let me know if you want/need the other attribute types to be handled)
else {
msg ("Coding Error")
}
list remove (attribute_stringlist_variable, attribute_variable)
}
</function>
P.S.
let me know, if you want this Function to also handle (and/or create) multiple and/or random cloned objects, as right now I just built it for taking in an already selected+created single clone object.
Talon
10 Feb 2017, 17:28This stuff looks very interesting, have been using the ClonePrototype function alot, now i can see much more of where the logic behind it is..
one question i have though is there a way to reference the closed object.. like pulling an item out of a magicians hat, easily enough to have the object appear with a new alias, but i've had some trouble having it referred to as the action triggers