• 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 Critical Chance Hit

So find one of this:
[cpp]
setField(L, "transformToFree", item->transformToFree);
setField(L, "transformEquipTo", item->transformEquipTo);
setField(L, "transformDeEquipTo", item->transformDeEquipTo);
setField(L, "clientId", item->clientId);
setField(L, "maxItems", item->maxItems);
setField(L, "slotPosition", item->slotPosition);
setField(L, "wieldPosition", item->wieldPosition);
setField(L, "speed", item->speed);
setField(L, "maxTextLength", item->maxTextLength);
setField(L, "writeOnceItemId", item->writeOnceItemId);
setField(L, "date", item->date);
setField(L, "writer", item->writer);
setField(L, "text", item->text);
setField(L, "attack", item->attack);
setField(L, "extraAttack", item->extraAttack);
setField(L, "defense", item->defense);
setField(L, "extraDefense", item->extraDefense);
setField(L, "armor", item->armor);
setField(L, "breakChance", item->breakChance);
setField(L, "hitChance", item->hitChance);
setField(L, "maxHitChance", item->maxHitChance);
setField(L, "runeLevel", item->runeLevel);
setField(L, "runeMagicLevel", item->runeMagLevel);
setField(L, "lightLevel", item->lightLevel);
setField(L, "lightColor", item->lightColor);
setField(L, "decayTo", item->decayTo);
setField(L, "rotateTo", item->rotateTo);
setField(L, "alwaysOnTopOrder", item->alwaysOnTopOrder);
setField(L, "shootRange", item->shootRange);
setField(L, "charges", item->charges);
setField(L, "decayTime", item->decayTime);
setField(L, "attackSpeed", item->attackSpeed);
setField(L, "wieldInfo", item->wieldInfo);
setField(L, "minRequiredLevel", item->minReqLevel);
setField(L, "minRequiredMagicLevel", item->minReqMagicLevel);
setField(L, "worth", item->worth);
setField(L, "levelDoor", item->levelDoor);
setField(L, "name", item->name.c_str());
setField(L, "plural", item->pluralName.c_str());
setField(L, "article", item->article.c_str());
setField(L, "description", item->description.c_str());
setField(L, "runeSpellName", item->runeSpellName.c_str());
setField(L, "vocationString", item->vocationString.c_str());
[/cpp]

And then paste under or above one of them this:
[cpp]
setField(L, "criticalHitChance", item->criticalHitChance);
[/cpp]
 
I've created diff patch for TFS 9.1+
Save to your sources as otserv.patch
And use like this: patch -Np1 < otserv.patch
Code:
diff -crB ../old/item.cpp ./item.cpp
*** ../old/item.cpp	2012-08-30 18:44:12.000000000 +0200
--- ./item.cpp	2012-08-31 10:33:40.000000000 +0200
***************
*** 389,394 ****
--- 389,403 ----
  			setAttribute("article", article);
  			break;
  		}
+ 		case ATTR_CRITICALHITCHANCE:
+ 		{
+ 			int32_t criticalHitChance;
+ 			if(!propStream.getLong((uint32_t&)criticalHitChance))
+ 				return ATTR_READ_ERROR;
+  
+ 			setAttribute("criticalhitchance", criticalHitChance);
+ 			break;
+ 		}
  
  		case ATTR_ATTACK:
  		{
***************
*** 887,892 ****
--- 896,914 ----
  				if(it.extraDefense || (item && item->getExtraDefense()))
  					s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos;
  			}
+ 
+ 			if(it.criticalHitChance || (item && item->getCriticalHitChance()))
+ 			{
+ 				if(begin)
+ 				{
+ 					begin = false;
+ 					s << " (";
+ 				}
+ 				else
+ 					s << ", ";
+  
+ 				s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
+ 			}
  		}
  
  		if(it.attackSpeed || (item && item->getAttackSpeed()))
***************
*** 1184,1189 ****
--- 1206,1224 ----
  			begin = false;
  		}
  
+ 		if(it.criticalHitChance || (item && item->getCriticalHitChance()))
+ 		{
+ 			if(begin)
+ 			{
+ 				begin = false;
+ 				s << " (";
+ 			}
+ 			else
+ 				s << ", ";
+  
+ 			s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
+ 		}
+ 
  		if(it.hasAbilities())
  		{
  			for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
diff -crB ../old/item.h ./item.h
*** ../old/item.h	2012-06-20 18:25:00.000000000 +0200
--- ./item.h	2012-08-31 10:41:59.000000000 +0200
***************
*** 113,118 ****
--- 113,119 ----
  	ATTR_ARTICLE = 41,
  	ATTR_SCRIPTPROTECTED = 42,
  	ATTR_DUALWIELD = 43,
+ 	ATTR_CRITICALHITCHANCE = 44,
  	ATTR_ATTRIBUTE_MAP = 128
  };
  
***************
*** 254,259 ****
--- 255,261 ----
  		bool isDualWield() const;
  
  		int32_t getAttack() const;
+ 		int32_t getCriticalHitChance() const;
  		int32_t getExtraAttack() const;
  		int32_t getDefense() const;
  		int32_t getExtraDefense() const;
***************
*** 392,397 ****
--- 394,409 ----
  	return false;
  }
  
+ inline int32_t Item::getCriticalHitChance() const
+ {
+ 	bool ok;
+ 	int32_t v = getIntegerAttribute("criticalhitchance", ok);
+ 	if(ok)
+ 		return v;
+  
+ 	return items[id].criticalHitChance;
+ }
+ 
  inline int32_t Item::getAttack() const
  {
  	bool ok;
diff -crB ../old/items.cpp ./items.cpp
*** ../old/items.cpp	2012-08-23 16:15:26.000000000 +0200
--- ./items.cpp	2012-08-31 10:35:26.000000000 +0200
***************
*** 67,72 ****
--- 67,73 ----
  	attack = extraAttack = 0;
  	defense = extraDefense = 0;
  	attackSpeed = 0;
+ 	criticalHitChance = 0;
  	armor = 0;
  	decayTo = -1;
  	decayTime = 0;
***************
*** 711,716 ****
--- 712,722 ----
  			if(readXMLInteger(itemAttributesNode, "value", intValue))
  				it.extraDefense = intValue;
  		}
+ 		else if(tmpStrValue == "criticalhitchance")
+ 		{
+ 			if(readXMLInteger(itemAttributesNode, "value", intValue))
+ 				it.criticalHitChance = intValue;
+ 		}
  		else if(tmpStrValue == "attack")
  		{
  			if(readXMLInteger(itemAttributesNode, "value", intValue))
diff -crB ../old/items.h ./items.h
*** ../old/items.h	2012-06-18 18:28:10.000000000 +0200
--- ./items.h	2012-08-31 10:35:54.000000000 +0200
***************
*** 157,163 ****
  		uint16_t transformBed[PLAYERSEX_MALE + 1], transformUseTo, transformEquipTo, transformDeEquipTo,
  			id, clientId, maxItems, slotPosition, wieldPosition, speed, maxTextLength, writeOnceItemId, wareId;
  
! 		int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
  			runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;
  		uint32_t shootRange, charges, decayTime, attackSpeed, wieldInfo, minReqLevel, minReqMagicLevel,
  			worth, levelDoor, date;
--- 157,163 ----
  		uint16_t transformBed[PLAYERSEX_MALE + 1], transformUseTo, transformEquipTo, transformDeEquipTo,
  			id, clientId, maxItems, slotPosition, wieldPosition, speed, maxTextLength, writeOnceItemId, wareId;
  
! 		int32_t attack, criticalHitChance, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
  			runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;
  		uint32_t shootRange, charges, decayTime, attackSpeed, wieldInfo, minReqLevel, minReqMagicLevel,
  			worth, levelDoor, date;
diff -crB ../old/luascript.cpp ./luascript.cpp
*** ../old/luascript.cpp	2012-08-30 18:44:12.000000000 +0200
--- ./luascript.cpp	2012-08-31 10:36:14.000000000 +0200
***************
*** 10425,10430 ****
--- 10425,10431 ----
  	setField(L, "date", item->date);
  	setField(L, "writer", item->writer);
  	setField(L, "text", item->text);
+ 	setField(L, "criticalHitChance", item->criticalHitChance);
  	setField(L, "attack", item->attack);
  	setField(L, "extraAttack", item->extraAttack);
  	setField(L, "defense", item->defense);
Only in .: otserv.patch
diff -crB ../old/player.cpp ./player.cpp
*** ../old/player.cpp	2012-08-30 18:44:12.000000000 +0200
--- ./player.cpp	2012-08-31 10:36:40.000000000 +0200
***************
*** 428,433 ****
--- 428,445 ----
  	return armor;
  }
  
+ int32_t Player::getCriticalHitChance() const
+ {
+ 	int32_t i = SLOT_FIRST, crit = 0;
+ 	for(; i < SLOT_LAST; ++i)
+ 	{
+ 		if(Item* item = getInventoryItem((slots_t)i))
+ 			crit += item->getCriticalHitChance();
+ 	}
+  
+ 	return crit;
+ }
+ 
  void Player::getShieldAndWeapon(const Item* &_shield, const Item* &_weapon) const
  {
  	_shield = NULL;
diff -crB ../old/player.h ./player.h
*** ../old/player.h	2012-08-30 18:44:12.000000000 +0200
--- ./player.h	2012-08-31 10:37:04.000000000 +0200
***************
*** 483,488 ****
--- 483,489 ----
  		bool addUnjustifiedKill(const Player* attacked, bool countNow);
  
  		virtual int32_t getArmor() const;
+ 		virtual int32_t getCriticalHitChance() const;
  		virtual int32_t getDefense() const;
  		virtual float getAttackFactor() const;
  		virtual float getDefenseFactor() const;
 
Last edited:
No such thing as TFS 9.1, there's only 0.2 and 0.3 (0.4 is 0.3).
 
I meak TFS 0.4 that supports 9.1+ protocol.
 
04...
all compiled....
and added to xml:
<item id="2407" article="a" name="bright sword">
<attribute key="description" value="The blade shimmers in light blue."/>
<attribute key="weight" value="2900"/>
<attribute key="defense" value="30"/>
<attribute key="attack" value="36"/>
<attribute key="weaponType" value="sword"/>
<attribute key="extradef" value="1"/>
<attribute key="criticalhitchance" value="100" />
</item>
but if I attack train monk, I dont see any Critical Hits...
 
Sorry to revive the topic, it is because I have an error in this code, when I put the item in the arrow slot also the% of critical, what could be wrong?

2i87nza.jpg
 
I did this tutorial just right, after I compiled my server it was like this could you help me?image.thumb.png.15267c1b45829b0ef13c4d266b66ba67.png
 
Back
Top