• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Random Attributes

Holloweye

New Member
Joined
Jul 13, 2007
Messages
52
Reaction score
4
So I have been trying to make so that every item that is created can have a random armor,attack,... value. What I tried with was to do that when you read the attributes from the xml file it become random:

else if(tmpStrValue == "armor")
{
if(readXMLInteger(itemAttributesNode, "random_min", intMinValue))
if(readXMLInteger(itemAttributesNode, "random_max", intMaxValue))
if(intMaxValue > intMinValue)
it.armor = intMinValue + rand() % (intMaxValue - intMinValue);
if(readXMLInteger(itemAttributesNode, "value", intValue))
it.armor = intValue;
}

But I noticed that this will only be random 1 time the problem with that is that the ItemType only get random. So lets say I made a leather armor with armor 1-10. So lets say the random value was 3 then all armors would have 3 in armor. And if I restart the server it might be 8 or something and all armors would have 8 in armor.

I would like to have so that all leather armors would have have diffrent and random value each time. Anyone could help me?
 
ok, deleted whole object folder ant then just compiled and it works:D
great
And the lowest value seems to be most frequent(created 8 items, 6x arm4, 1x arm7 and 1x arm5)

Yeah I did find out why. I tried the:
it.armorRndMin + rand() % (it.armorRndMax - it.armorRndMin))
part for it self turns out if you make random 4-8 it will be 4-7 so all you need to do is change it to this:
it.armorRndMin + rand() % (it.armorRndMax+1 - it.armorRndMin))

So now I made a simple test program made 100 randoms and I got perfect result:

4: 18
5: 24
6: 17
7: 24
8: 17

Looks like a good random now :).
 
Last edited:
Code:
<item id="2467" article="a" name="leather armor">
	<attribute key="weight" value="6000" />
	<attribute key="armor" random_min="4" />
[COLOR="Red"]	<attribute key="absorbPercentFire" random_min="4" random_max="8" [B]chanceToGetThisAttribute="10"[/B]/>[/COLOR]
	<attribute key="slotType" value="body" />
</item>
chanceToGetThisAttribute="10"
10 = 10%
you have idea how to make this?
 
Last edited:
you mean chance to start randomizing and if failed just ignore this attr?
kind of
Code:
else
{
if hereuserandomization from1to100 <=(or it was =<?)(readXMLInteger(itemAttributesNode, "chance", intValue))
{
        if(readXMLInteger(itemAttributesNode, "random_min", intValue))
	{
                it.armorRndMin = intValue;
        }
        if(readXMLInteger(itemAttributesNode, "random_max", intValue))
        {
                it.armorRndMax = intValue;
        }
}
}
 
Code:
<item id="2467" article="a" name="leather armor">
	<attribute key="weight" value="6000" />
	<attribute key="armor" random_min="4" />
[COLOR="Red"]	<attribute key="absorbPercentFire" random_min="4" random_max="8" [B]chanceToGetThisAttribute="10"[/B]/>[/COLOR]
	<attribute key="slotType" value="body" />
</item>
chanceToGetThisAttribute="10"
10 = 10%
you have idea how to make this?

Yeah I have done it. I realease the whole thing on the code section: http://otland.net/f35/random-attributes-71833/#post736133


you mean chance to start randomizing and if failed just ignore this attr?
kind of
Code:
else
{
if hereuserandomization from1to100 <=(or it was =<?)(readXMLInteger(itemAttributesNode, "chance", intValue))
{
        if(readXMLInteger(itemAttributesNode, "random_min", intValue))
	{
                it.armorRndMin = intValue;
        }
        if(readXMLInteger(itemAttributesNode, "random_max", intValue))
        {
                it.armorRndMax = intValue;
        }
}
}

It dont work that way. If you would do it like that then everyitem that use that attribute will either have random or not on that attribute. Hard to explain.
 
Last edited:
Back
Top