• 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?
 
I also saw your thread on otfans while I was at school, I thought this might be a problem when I first read through it, although this is a great idea. Along with that, the chance of looting a leather armor with 10 def should be less than looting one with 2-3, meaning higher rates should be harder to loot
 
I also saw your thread on otfans while I was at school, I thought this might be a problem when I first read through it, although this is a great idea. Along with that, the chance of looting a leather armor with 10 def should be less than looting one with 2-3, meaning higher rates should be harder to loot

Well thats not really the big problem here. When you logout/login your character your equipment and stuff will be saved in a MYSQL table. It will only save the ID then generate the item once you load your character. So it dont have any information about armor. When I was thinking about how this should be done I found my self expanding the MYSQL item table. Adding a "Armor" value. Still some things that I trying to figure out to get it work.
 
That would be a pain, since you would also need more tables for more attributes (I would definitely do ml and other skill boosters too)

How much workload would it put on the server to save the armor and a few other attributes for each item the player has?
 
That would be a pain, since you would also need more tables for more attributes (I would definitely do ml and other skill boosters too)

How much workload would it put on the server to save the armor and a few other attributes for each item the player has?

Yeah I am questioning my self that also. How much power it will take. But on the other hand it only save the players on login/logout and sever saves so maybe it dosent really matter that much.

Edit: it save on logout and server save only.
 
Last edited:
Does it save on login? I thought it was only on log out but I could be wrong. If its only log out then it might not be that bad, just making sure that all your armors have a reasonable weight so people can't hold 1000 armors to lag the server, assuming they even knew it saved anything like that and thought they could abuse it
 
So I worked on it like a hour today on got it to work without adding any fields on the mysql database. So basic I found out that items already have attribute value. Well basicly I just used that value for it.

So here it is.

in Items.cpp

Find the this or the attribute you want to have random access:
Code:
if(readXMLInteger(itemAttributesNode, "value", intValue))
        it.armor = intValue;

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

Items.h

find this:
Code:
int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance, runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;

Replace with this (Ofcourse you will need to add random attributes for each attribute you want to have random):
Code:
int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance, runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder, armorRndMin, armorRndMax;

Items.cpp

In the constructor for the ItemType or if you dont know what it is just add it after these values:
fluidSource = FLUID_NONE;
clientCharges = false;
allowDistRead = false;

add this:
Code:
armorRndMin = -1;
armorRndMax = -1;

Item.cpp

Also in Item the constructor or if you dont know where it is just add after this lines of code:
if(it.isFluidContainer() || it.isSplash())
setFluidType(amount);
else if(it.stackable && amount)
count = amount;
else if(it.charges && amount)
setCharges(amount);

Add:
Code:
if(it.armorRndMin > -1 && it.armorRndMax > it.armorRndMin)
{
    setAttribute("armor", it.armorRndMin + rand() % (it.armorRndMax - it.armorRndMin));
}


So how do we use it now?

Go to the Items.xml in the server/data/items folder. Find a item you want to change on. Lets say I want to make random on the leather armor I would do it like this:

Code:
<item id="2467" article="a" name="leather armor">
	<attribute key="weight" value="6000" />
	<attribute key="armor" random_min="4" random_max="8" />
	<attribute key="slotType" value="body" />
</item>

Remember if the value key is still there it would use it insted of the random ones. So basicly just remove the value and add random_min and random_max.

Also rebuild else it might not work.

Sorry for my bad English. Have fun :)
 
Also in Item the constructor or if you dont know where it is just add after this lines of code:
if(it.isFluidContainer() || it.isSplash())
setFluidType(amount);
else if(it.stackable && amount)
count = amount;
else if(it.charges && amount)
setCharges(amount);

I can't find this bit in 0.3.6 pl1 source, can you give me a line number of where to add the code you posted for this part?

Nevermind, found it in .4 :p guess I'm upgrading
 
Last edited:
I can't find this bit in 0.3.6 pl1 source, can you give me a line number of where to add the code you posted for this part?

At line 195 in the Item.cpp not Items.cpp.

If you still can't find it just look for the constructor for Item it looks something like this:
Item::Item(const uint16_t type, uint16_t amount/* = 0*/):ItemAttributes(), id(type)
{
...
}
Just add it in the end of the constructor and should work fine.

Tell me if you get it to work :).
 
Found it on 0.3.6 (duh)

Compiled with no errors, but the server isn't starting up now. After loading the map it says "the forgotten server has encountered an error and needs to close"
 
ahh, I made something wrong probably
serv starts, but when I try to log in I appear in temple being invisible, every item around is somehow wrong and serv crashes

gonna try again later:D
 
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)
 
Back
Top