• 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

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Reaction score
63
Location
Poland
[ATTRIBUTE] Critical Chance Hit



Idea:
weapons-critical-hit-system

Description:
This attribute change that player get critical hit +X%.

Example:
XML:
	<attribute key="criticalhitchance" value="15" />

Warning:
Code was written 100% by me!!

If you don't know what you are doing, don't change anything and leave from this theard.


Test:
I tested it on TFS 0.4 trunk 3884 (it should work on better versions)




Edit:


item.cpp

Below:
[cpp]
case ATTR_ARTICLE:
{
std::string article;
if(!propStream.getString(article))
return ATTR_READ_ERROR;

setAttribute("article", article);
break;
}
[/cpp]

Paste:
[cpp]
case ATTR_CRITICALHITCHANCE:
{
int32_t criticalHitChance;
if(!propStream.getLong((uint32_t&)criticalHitChance))
return ATTR_READ_ERROR;

setAttribute("criticalhitchance", criticalHitChance);
break;
}
[/cpp]



Below:
[cpp]
bool begin = true;
if(tmp)
{
s << " (Arm:" << tmp;
begin = false;
}
[/cpp]

Paste:
[cpp]
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;
}
[/cpp]



Below:
[cpp]
if(it.defense || it.extraDefense || (item && (item->getDefense() || item->getExtraDefense())))
{
if(begin)
{
begin = false;
s << " (";
}
else
s << ", ";

s << "Def:" << int32_t(item ? item->getDefense() : it.defense);
if(it.extraDefense || (item && item->getExtraDefense()))
s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos;
}
[/cpp]

Paste:
[cpp]
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;
}
[/cpp]


item.h

Below:
[cpp]
ATTR_DUALWIELD = 43,
[/cpp]

Paste:
[cpp]
ATTR_CRITICALHITCHANCE = 44,
[/cpp]



Below:
[cpp]
int32_t getAttack() const;
[/cpp]

Paste:
[cpp]
int32_t getCriticalHitChance() const;
[/cpp]



Below:
[cpp]
inline bool Item::isScriptProtected() const
{
const bool* v = getBooleanAttribute("scriptprotected");
if(v)
return *v;

return false;
}
[/cpp]

Paste:
[cpp]
inline int32_t Item::getCriticalHitChance() const
{
const int32_t* v = getIntegerAttribute("criticalhitchance");
if(v)
return *v;

return items[id].criticalHitChance;
}
[/cpp]


items.cpp

Below:
[cpp]
attackSpeed = 0;
[/cpp]

Paste:
[cpp]
criticalHitChance = 0;
[/cpp]



Below:
[cpp]
else if(tmpStrValue == "extradefense" || tmpStrValue == "extradef")
{
if(readXMLInteger(itemAttributesNode, "value", intValue))
it.extraDefense = intValue;
}
[/cpp]

Paste:
[cpp]
else if(tmpStrValue == "criticalhitchance")
{
if(readXMLInteger(itemAttributesNode, "value", intValue))
it.criticalHitChance = intValue;
}
[/cpp]


items.h

Change:
[cpp]
int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
[/cpp]

To:
[cpp]
int32_t attack, criticalHitChance, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
[/cpp]


luascript.cpp

Below:
[cpp]
setField(L, "text", item->text);
[/cpp]

Paste:
[cpp]
setField(L, "criticalHitChance", item->criticalHitChance);
[/cpp]


player.cpp

Below:
[cpp]
int32_t Player::getArmor() const
{
int32_t i = SLOT_FIRST, armor = 0;
for(; i < SLOT_LAST; ++i)
{
if(Item* item = getInventoryItem((slots_t)i))
armor += item->getArmor();
}

if(vocation->getMultiplier(MULTIPLIER_ARMOR) != 1.0)
return int32_t(armor * vocation->getMultiplier(MULTIPLIER_ARMOR));

return armor;
}
[/cpp]

Paste:
[cpp]
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;
}
[/cpp]


player.h

Under:
[cpp]
virtual int32_t getArmor() const;
[/cpp]

Paste:
[cpp]
virtual int32_t getCriticalHitChance() const;
[/cpp]


weapons.cpp

FIND ALL:
[cpp]
if(random_range(1, 100) < g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
[/cpp]

Change to:
[cpp]
if(random_range(1, 100) < player->getCriticalHitChance() + g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
[/cpp]
 
well, it was easy but you could leave for urself
people with thinking skill can code it and others dont deserve to get it for free imo
also it should work also on 0.3.6, caus ei cannot see any differences
 
nice release ^^, i dont know so much of c, how it would be for something like 'setCriticalHitChance'?
 
Nope beacause it's attrubite which you can change in items.xml (or in lua scrpit).

It isn't lua function!!
 
doPlayerSetExtraCriticalRate
I think that is good idea to do it (beacuse I thought about "doPlayerSetExtraCriticalHitChance" the same like attrubite but also in lua function)
I tried to make but always when try to login TFS closing.
<_<
 
Last edited:
try storing it in reserved storage, this way it gonna work for sure

ah, and condition increasing and/or decreasing that value would be nice(better than coding all shit to make spell work as it should)
 
Last edited:
I think that is good idea to do it (beacuse I thought about "doPlayerSetExtraCriticalHitChance" the same like attrubite but also in lua function)
I tried to make but always when try to login TFS closing.
<_<

usefull for spells and another actions or creature events
 
I think that is good idea to do it (beacuse I thought about "doPlayerSetExtraCriticalHitChance" the same like attrubite but also in lua function)
I tried to make but always when try to login TFS closing.
<_<

If you are sure that you did the code well, then rebuild the project and don't compile it, any time you edit player.h file, you need to rebuild the project or the server will crash when a player logs in.
 
luascript.cpp

Below:
C Code:
setField(L, "text", item->text);
Paste:
C Code:
setField(L, "criticalHitChance", item->criticalHitChance);

I didn't find "setField(L, "text", item->text);" in my sources, Crying Damson 0.3.7a. And now?
 
Back
Top