• 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!

Feature Random Attributes

Holloweye

New Member
Joined
Jul 13, 2007
Messages
52
Reaction score
4
INFORMATION

This code will give you the option to make a attribute randomized each time a item is created.


IMPLEMENTATION

Find this in Item.cpp:
Code:
	setDefaultDuration();
	if(it.isFluidContainer() || it.isSplash())
		setFluidType(amount);
	else if(it.stackable && amount)
		count = amount;
	else if(it.charges && amount)
		setCharges(amount);

After that code add this:
Code:
//NEW - RANDOM
	if(it.armorRndMin > -1 && it.armorRndMax > it.armorRndMin)
           setAttribute("armor", it.armorRndMin + rand() % (it.armorRndMax+1 - it.armorRndMin));
    if(it.defenseRndMin > -1 && it.defenseRndMax > it.defenseRndMin)
           setAttribute("defense", it.defenseRndMin + rand() % (it.defenseRndMax+1 - it.defenseRndMin));
    if(it.extraDefenseRndMin > -1 && it.extraDefenseRndMax > it.extraDefenseRndMin)
           if(it.extraDefenseChance == -1 || (it.extraDefenseChance >= rand() % 101) )
                    setAttribute("extradefense", it.extraDefenseRndMin + rand() % (it.extraDefenseRndMax+1 - it.extraDefenseRndMin));
    if(it.attackRndMin > -1 && it.attackRndMax > it.attackRndMin)
           setAttribute("attack", it.attackRndMin + rand() % (it.attackRndMax - it.attackRndMin));
    if(it.extraAttackRndMin > -1 && it.extraAttackRndMax > it.extraAttackRndMin)
           if(it.extraAttackChance == -1 || (it.extraAttackChance >= rand() % 101) )
                    setAttribute("extraattack", it.extraAttackRndMin + rand() % (it.extraAttackRndMax+1 - it.extraAttackRndMin));
    if(it.chargesRndMin > -1 && it.chargesRndMax > it.chargesRndMin)
           setAttribute("charges", it.chargesRndMin + rand() % (it.chargesRndMax+1 - it.chargesRndMin));
    if(it.attackSpeedRndMin > -1 && it.attackSpeedRndMax > it.attackSpeedRndMin)
           if(it.attackSpeedChance == -1 || (it.attackSpeedChance >= rand() % 101) )
                    setAttribute("attackSpeed", it.attackSpeedRndMin + rand() % (it.attackSpeedRndMax+1 - it.attackSpeedRndMin) );
    //NEW - RANDOM

Find this in Items.h:
Code:
int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
			runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;

Below that code add this:
Code:
//NEW - RANDOM
		int32_t armorRndMin, armorRndMax, defenseRndMin, defenseRndMax, extraDefenseRndMin, extraDefenseRndMax, attackRndMin, attackRndMax, extraAttackRndMin,
            extraAttackRndMax, chargesRndMin, chargesRndMax, attackSpeedRndMin, attackSpeedRndMax;
        int32_t extraAttackChance, extraDefenseChance, attackSpeedChance;
        //NEW - RANDOM

Find this in Items.cpp:
Code:
corpseType = RACE_NONE;
	fluidSource = FLUID_NONE;
	clientCharges = false;
	allowDistRead = false;

Below that add this:
Code:
//NEW - RANDOM
	armorRndMin = -1;
	armorRndMax = -1;
	defenseRndMin = -1;
	defenseRndMax = -1;
	extraDefenseRndMin = -1;
	extraDefenseRndMax = -1;
	attackRndMin = -1;
	attackRndMax = -1;
	extraAttackRndMin = -1;
	extraAttackRndMax = -1;
	chargesRndMin = -1;
	chargesRndMax = -1;
	attackSpeedRndMin = -1;
	attackSpeedRndMax = -1;
	attackSpeedChance = -1;
	extraAttackChance = -1;
	extraDefenseChance = -1;
    //NEW - RANDOM

Find this in Items.cpp:
Code:
else if(tmpStrValue == "armor")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.armor = intValue;

Replace with this:
Code:
else if(tmpStrValue == "armor")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.armor = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                       it.armorRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                       it.armorRndMax = intValue;
			}

Find this in Items.cpp:
Code:
else if(tmpStrValue == "defense")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.defense = intValue;
}

Replace with this:
Code:
else if(tmpStrValue == "defense")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.defense = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                       it.defenseRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                       it.defenseRndMax = intValue;
			}

Find this in Items.cpp:
Code:
else if(tmpStrValue == "extradefense" || tmpStrValue == "extradef")
			{
                if(readXMLInteger(itemAttributesNode, "chance", intValue))
                      it.extraDefenseChance = intValue;
}

Replace with this:
Code:
else if(tmpStrValue == "extradefense" || tmpStrValue == "extradef")
			{
                if(readXMLInteger(itemAttributesNode, "chance", intValue))
                      it.extraDefenseChance = intValue;
		        if(readXMLInteger(itemAttributesNode, "value", intValue))
                      it.extraDefense = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                      it.extraDefenseRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                      it.extraDefenseRndMax = intValue;
			}

Find this in Items.cpp:
Code:
	else if(tmpStrValue == "attack")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.attack = intValue;
}

Replace with this:
Code:
else if(tmpStrValue == "attack")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.attack = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                       it.attackRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                       it.attackRndMax = intValue;
			}

Find this in Items.cpp:
Code:
else if(tmpStrValue == "extraattack" || tmpStrValue == "extraatk")
			{
                if(readXMLInteger(itemAttributesNode, "chance", intValue))
                       it.extraAttackChance = intValue;
}

Replace with this:
Code:
else if(tmpStrValue == "extraattack" || tmpStrValue == "extraatk")
			{
                if(readXMLInteger(itemAttributesNode, "chance", intValue))
                       it.extraAttackChance = intValue;
                if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.extraAttack = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                       it.extraAttackRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                       it.extraAttackRndMax = intValue;
			}

Find this in Items.cpp:
Code:
else if(tmpStrValue == "attackspeed")
			{
                if(readXMLInteger(itemAttributesNode, "chance", intValue))
                       it.attackSpeedChance = intValue;
}

Replace with this:
Code:
else if(tmpStrValue == "attackspeed")
			{
                if(readXMLInteger(itemAttributesNode, "chance", intValue))
                       it.attackSpeedChance = intValue;
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.attackSpeed = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                       it.attackSpeedRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                       it.attackSpeedRndMax = intValue;
			}

Find this in Items.cpp:
Code:
else if(tmpStrValue == "charges")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.charges = intValue;
}

Replace with this:
Code:
else if(tmpStrValue == "charges")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
                       it.charges = intValue;
                if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                       it.chargesRndMin = intValue;
                if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                       it.chargesRndMax = intValue;
			}



EXAMPLE

Code:
<item id="2380" article="a" name="hand axe">
		<attribute key="weight" value="1800" />
		<attribute key="defense" value="5" />
		<attribute key="attack" random_min="5" random_max="8" />
		<attribute key="extraattack" chance="50" random_min="10" random_max="30" />
		<attribute key="weaponType" value="axe" />
	</item>
In this example there is 50% chance that the item will have extra attack and it will be random 10-30 and the attack is random between 5-8.

Attributes that have Random_min/Random_max suppport:
- Armor
- Defense
- ExtraDefense
- Attack
- ExtraAttack
- AttackSpeed
- Charges

Attributes that have Chance support:
- ExtraDefense
- ExtraAttack
- AttackSpeed


NOTES
When done Rebuild All!!
 
Last edited:
This is just freakin awesome!
In my opinion the next TFS update would have this with a option in config like "useRandomAttributes = true/false" So you don't have to remove all the attributes on every single item if you no longer want to have it :)

REP++ Ofcourse!
 
When I running server then I get crash in script systems,before I compile TFS no was crash
 
if you cannot rebuild delete folder with .o files and compile xD
I have only old version of this(from request section) and many other changes in source

Also for safety reasons you shouldnt ask for ready exe
 
But I don't understand.When in console is "Loading Script System" then is error. Compile was without any errors
 
Very nice, I searched for something like this.

Bad that you can get a random attribute only when it created. It would be cool when you could loot such items with random attr. from monsters :D

@down
I don't know, but i will try later.
 
Last edited:
it ISNT randomizing when looted? well, didnt tried but if youre right I'll be very sad ;f
 
good, its quite logical that it have to be randonized when created ANY way, but you know, tfs structure seems to be irrational sometimes
 
Not work for 0.3.5, if i replace command for this:
//NEW - RANDOM
if(it.armorRndMin > -1 && it.armorRndMax > it.armorRndMin)
setArmor(it.armorRndMin + rand() % (it.armorRndMax+1 - it.armorRndMin));
if(it.defenseRndMin > -1 && it.defenseRndMax > it.defenseRndMin)
setDefense(it.defenseRndMin + rand() % (it.defenseRndMax+1 - it.defenseRndMin));
if(it.extraDefenseRndMin > -1 && it.extraDefenseRndMax > it.extraDefenseRndMin)
if(it.extraDefenseChance == -1 || (it.extraDefenseChance >= rand() % 101) )
setExtraDefense(it.extraDefenseRndMin + rand() % (it.extraDefenseRndMax+1 - it.extraDefenseRndMin));
if(it.attackRndMin > -1 && it.attackRndMax > it.attackRndMin)
setAttack(it.attackRndMin + rand() % (it.attackRndMax - it.attackRndMin));
if(it.extraAttackRndMin > -1 && it.extraAttackRndMax > it.extraAttackRndMin)
if(it.extraAttackChance == -1 || (it.extraAttackChance >= rand() % 101) )
setExtraAttack(it.extraAttackRndMin + rand() % (it.extraAttackRndMax+1 - it.extraAttackRndMin));
if(it.chargesRndMin > -1 && it.chargesRndMax > it.chargesRndMin)
setCharges(it.chargesRndMin + rand() % (it.chargesRndMax+1 - it.chargesRndMin));
if(it.attackSpeedRndMin > -1 && it.attackSpeedRndMax > it.attackSpeedRndMin)
if(it.attackSpeedChance == -1 || (it.attackSpeedChance >= rand() % 101) )
setAttackSpeed(it.attackSpeedRndMin + rand() % (it.attackSpeedRndMax+1 - it.attackSpeedRndMin) );
//NEW - RANDOM

I have debug in start TFS in "Loading script systems"
 
Not work for me.
I got build but when i change my items.xml my ot no open
ERRO:
.EXE
[10/08/2010 12:32:01] >> Loading items
[10/08/2010 12:32:01] [Warning - Items::loadFromXml] Cannot load items file.
[10/08/2010 12:32:01] Line: 2412, Info: Extra content at the end of the document

Items.xml
<item id="2400" article="a" name="magic sword">
<attribute key="description" value="It is the Sword of Valor." />
<attribute key="weight" value="4200" />
<attribute key="defense" value="35" />
<attribute key="attack" random_min="5" random_max="8" />
<attribute key="extraattack" chance="50" random_min="10" random_max="30" />
<attribute key="weaponType" value="sword" />
<attribute key="extradef" value="3" />
</item>

Line 2412 Items.xml
<item id="2246" name="burnt down firewood">
<attribute key="weight" value="420" />
</item>

EDIT:
I got it =)
i fixed the error
 
Last edited:
Back
Top