Feature Critical Chance Hit

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Best answers
0
Reaction score
59
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]
 

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Best answers
0
Reaction score
61
Location
with Taiga
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
 
OP
VirrageS

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Best answers
0
Reaction score
59
Location
Poland
Yeah, but you can say the same to other releases not in C++ but also in lua.
Now anyone will sell his scrpit and work which add to make scrpit?? <_<

I think that can be very helpful to someone. :p
 

Strack

Excellent OT User
Joined
May 15, 2009
Messages
198
Best answers
0
Reaction score
14
nice release ^^, i dont know so much of c, how it would be for something like 'setCriticalHitChance'?
 
OP
VirrageS

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Best answers
0
Reaction score
59
Location
Poland
Nope beacause it's attrubite which you can change in items.xml (or in lua scrpit).

It isn't lua function!!
 

Exedion

Excellent OT User
Joined
Jun 11, 2007
Messages
628
Best answers
0
Reaction score
28
you make fun of me right?

the people are envious
 

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Best answers
0
Reaction score
61
Location
with Taiga
doItemSetAttribute or doPlayerSetExtraCriticalRate?
already exists or easy ;d
 
OP
VirrageS

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Best answers
0
Reaction score
59
Location
Poland
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:

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Best answers
0
Reaction score
61
Location
with Taiga
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:

Exedion

Excellent OT User
Joined
Jun 11, 2007
Messages
628
Best answers
0
Reaction score
28
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
 
Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
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.
 

Guiminha

Commoner Hero
Joined
Sep 15, 2007
Messages
16
Best answers
0
Reaction score
0
Location
Brazil
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?
 
Top