Jump to content

Increase the value of a specific attribute


Recommended Posts

  • Active+ Member

Today I will share with you something simple.

 

char_item.cpp

// Add in the USE_CHANGE_ATTRIBUTE case
				else if (item->GetVnum() == 75891)
				{
					if ((item2->GetType() == ITEM_WEAPON) && item2->HasAttr(72))
					{
						int16_t idx = item2->FindAttribute(72);
						int32_t value = item2->GetAttributeValue(idx)+1;
						if ((150 > item2->GetAttributeValue(idx)) && (item2->GetAttributeValue(idx) >= 50))
						{
							item2->SetForceAttribute(idx, 72, value);
						}
						else
						{
							ChatPacket(CHAT_TYPE_INFO, "You can only use this item which is between 80-200 avg.");
							return false;
						}
					}
					else
					{
						ChatPacket(CHAT_TYPE_INFO, "You can only use this item on weapons with average damage.");
						return false;
					}
				}

item_names.txt

75891	Efsun Arttırma

item_proto.txt

75891	a_c	ITEM_USE	USE_CHANGE_ATTRIBUTE	1	ANTI_DROP | ANTI_SELL	ITEM_STACKABLE | LOG	NONE	NONE	1000	0	0	0	0	LIMIT_NONE	0	LIMIT_NONE	0	APPLY_NONE	0	APPLY_NONE	0	APPLY_NONE	0	0	0	0	0	0	0	0	0	0

 

https://metin2.download/picture/sZNM9Bsys7hT70MZWwro3N9Y7t95aQfR/.gif

Edited by Metin2 Dev
Core X - External 2 Internal
  • Good 1
Link to comment
Share on other sites

  • Premium

if you want just to increase a value from a bonus you dont have to change anything in item_proto 
the bonus value is signed 16 bit that means you can have max. 32767  without change anything
 

item2->SetForceAttribute(idx, 72, 32767);

this function will do it

also if you want to increase a value by 1 use the ++ increment operator instead of using +1  
 

int32_t value = item2->GetAttributeValue(idx);
++value;


 

Edited by xTryhard
Link to comment
Share on other sites

  • Active+ Member
9 hours ago, Xovarto said:

It somehow is not adding the avg value.

Even tho i have 55avg on weapon it says i need 50-150avg.

Do i need to add further code beside the on u posted?

Can you try like this

				else if (item->GetVnum() == 75891)
				{
					if ((item2->GetType() == ITEM_WEAPON) && item2->HasAttr(72))
					{
						int16_t idx = item2->FindAttribute(72);
						int32_t value = item2->GetAttributeValue(idx)+1;
						if ((150 > item2->GetAttributeValue(idx)) && (item2->GetAttributeValue(idx) >= 50))
						{
							item2->SetForceAttribute(idx, 72, value);
						}
						else
						{
							ChatPacket(CHAT_TYPE_INFO, "You can only use this item which is between 80-200 avg.");
							return false;
						}
					}
					else
					{
						ChatPacket(CHAT_TYPE_INFO, "You can only use this item on weapons with average damage.");
						return false;
					}
				}

 

4 hours ago, xTryhard said:

if you want just to increase a value from a bonus you dont have to change anything in item_proto 
the bonus value is signed 16 bit that means you can have max. 32767  without change anything
 

item2->SetForceAttribute(idx, 72, 32767);

this function will do it

also if you want to increase a value by 1 use the ++ increment operator instead of using +1  
 

int32_t value = item2->GetAttributeValue(idx);
++value;


 

Uhm no, I don't want to get the value 32767. I just want to increase an attribute type 150 by increasing value and this code does that. if you gonna do ++value, you'll increase by 1, and equals value to value+1. But you don't set it trough the weapon. You just declare a value by variable and you'll just increase value by 1.

Edited by Reached
Link to comment
Share on other sites

  • Premium
16 minutes ago, Reached said:

Can you try like this

				else if (item->GetVnum() == 71351)
				{
					if ((item2->GetType() == ITEM_WEAPON) && item2->HasAttr(72))
					{
						int16_t idx = item2->FindAttribute(72);
						int32_t value = item2->GetAttributeValue(idx)+1;
						if ((150 > item2->GetAttributeValue(idx)) && (item2->GetAttributeValue(idx) >= 50))
						{
							item2->SetForceAttribute(idx, 72, value);
						}
						else
						{
							ChatPacket(CHAT_TYPE_INFO, "You can only use this item which is between 80-200 avg.");
							return false;
						}
					}
					else
					{
						ChatPacket(CHAT_TYPE_INFO, "You can only use this item on weapons with average damage.");
						return false;
					}
				}

 

Uhm no, I don't want to get the value 32767. I just want to increase an attribute type 150 by increasing value and this code does that. if you gonna do ++value, you'll increase by 1, and equals value to value+1. But you don't set it trough the weapon. You just declare a value by variable and you'll just increase value by 1.

ofc you set the weapon. in your code you use this

 

item2->SetForceAttribute(idx, 72, value);

as third parameter you use value.

anyway this is the correct if statement :

 

if (item2->GetAttributeValue(idx) >= 80 && item2->GetAttributeValue(idx) <= 200)
	{
		item2->SetForceAttribute(idx, 72, value);
	}

 

Edited by xTryhard
Link to comment
Share on other sites

  • Active+ Member
2 minutes ago, xTryhard said:

ofc you set the weapon. in your code you use this

 

item2->SetForceAttribute(idx, 72, value);

as third parameter you use value.

anyway this is the correct if statement :

 

if (item2->GetAttributeValue(idx) >= 50 && item2->GetAttributeValue(idx) <= 200)
	{
		item2->SetForceAttribute(idx, 72, value);
	}

 

yes, i shared

Edited by Reached
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.