• 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!

Lua Function doAbsorbCombatPercentage && getCombatPercentageAbsorbed

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
Here i finished two functions useful for scripts like firewalker boots.

These functions works with the following combats:
Code:
COMBAT_PHYSICALDAMAGE = 1
COMBAT_ENERGYDAMAGE = 2
COMBAT_EARTHDAMAGE = 4
COMBAT_POISONDAMAGE = 4
COMBAT_FIREDAMAGE = 8
COMBAT_LIFEDRAIN = 32
COMBAT_MANADRAIN = 64
COMBAT_DROWNDAMAGE = 256
COMBAT_ICEDAMAGE = 512
COMBAT_HOLYDAMAGE = 1024
COMBAT_DEATHDAMAGE = 2048

Go to player.cpp and below:
[cpp] editListId = maxWriteLen = windowTextId = rankId = 0;[/cpp]

Paste:
[cpp]firePercent = energyPercent = earthPercent = icePercent = holyPercent = deathPercent = physicalPercent = lifeDrainPercent = manaDrainPercent = drownPercent = 0;[/cpp]

At the end of player.cpp, paste:
[cpp]void Player::setAbsorbedPercent(const CombatType_t combatType, int32_t percent)
{
if(percent < 0)
percent = 0;

if(percent > 100)
percent = 100;

switch((CombatType_t)combatType)
{
case COMBAT_FIREDAMAGE:
firePercent = percent;
break;
case COMBAT_ENERGYDAMAGE:
energyPercent = percent;
break;
case COMBAT_EARTHDAMAGE:
earthPercent = percent;
break;
case COMBAT_ICEDAMAGE:
icePercent = percent;
break;
case COMBAT_HOLYDAMAGE:
holyPercent = percent;
break;
case COMBAT_DEATHDAMAGE:
deathPercent = percent;
break;
case COMBAT_PHYSICALDAMAGE:
physicalPercent = percent;
break;
case COMBAT_LIFEDRAIN:
lifeDrainPercent = percent;
break;
case COMBAT_MANADRAIN:
manaDrainPercent = percent;
break;
case COMBAT_DROWNDAMAGE:
drownPercent = percent;
break;
default:
break;
}
}[/cpp]

Go to player.h and below:
[cpp] void setSex(uint16_t);[/cpp]

Paste:
[cpp]int32_t getAbsorbedPercent(CombatType_t combatType) const
{
switch(combatType)
{
case COMBAT_FIREDAMAGE:
return firePercent;

case COMBAT_ENERGYDAMAGE:
return energyPercent;

case COMBAT_EARTHDAMAGE:
return earthPercent;

case COMBAT_ICEDAMAGE:
return icePercent;

case COMBAT_HOLYDAMAGE:
return holyPercent;

case COMBAT_DEATHDAMAGE:
return deathPercent;

case COMBAT_PHYSICALDAMAGE:
return physicalPercent;

case COMBAT_LIFEDRAIN:
return lifeDrainPercent;

case COMBAT_MANADRAIN:
return manaDrainPercent;

case COMBAT_DROWNDAMAGE:
return drownPercent;

default:
break;
}
return 0;
}
void setAbsorbedPercent(const CombatType_t combatType, int32_t percent);[/cpp]

Below:
[cpp] int32_t shootRange;[/cpp]

Paste:
[cpp]
int32_t firePercent;
int32_t energyPercent;
int32_t earthPercent;
int32_t icePercent;
int32_t holyPercent;
int32_t deathPercent;
int32_t physicalPercent;
int32_t lifeDrainPercent;
int32_t manaDrainPercent;
int32_t drownPercent;
[/cpp]

Now got to game.cpp and find:
[cpp]bool Game::combatChangeHealth(CombatType_t combatType, Creature* attacker, Creature* target, int32_t healthChange,
MagicEffect_t hitEffect/* = MAGIC_EFFECT_UNKNOWN*/, TextColor_t hitColor/* = TEXTCOLOR_UNKNOWN*/, bool force/* = false*/)[/cpp]

Find the line:
[cpp]damage = std::min(target->getHealth(), damage);[/cpp]

Below it, paste this:
[cpp] Player* player = target->getPlayer();
int32_t percent, total;
if(player)
{
percent = player->getAbsorbedPercent(combatType);
total = damage * percent / (int32_t)100;
}

if(total > 0)
damage -= total;[/cpp]

Later, go to luascript.cpp and below:
[cpp] //doPlayerRemoveMoney(cid, money)
lua_register(m_luaState, "doPlayerRemoveMoney", LuaScriptInterface::luaDoPlayerRemoveMoney);[/cpp]

Paste:
[cpp] //doAbsorbCombatPercentage(cid, combat, percent)
lua_register(m_luaState, "doAbsorbCombatPercentage", LuaScriptInterface::luaDoAbsorbCombatPercentage);

//getCombatPercentageAbsorbed(cid, combat)
lua_register(m_luaState, "getCombatPercentageAbsorbed", LuaScriptInterface::luaGetCombatPercentageAbsorbed);[/cpp]

Find the function:
[cpp]int32_t LuaScriptInterface::luaDoPlayerRemoveMoney(lua_State* L)[/cpp]

Below that function, paste this:
[cpp]int32_t LuaScriptInterface::luaDoAbsorbCombatPercentage(lua_State *L)
{
ScriptEnviroment* env = getEnv();
int32_t percent = popNumber(L);
CombatType_t combat = (CombatType_t)popNumber(L);
if(!combat)
{
errorEx(getError(LUA_ERROR_COMBAT_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}

Player* player = env->getPlayerByUID(popNumber(L));
if(player)
{
player->setAbsorbedPercent(combat, percent);
lua_pushnumber(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushnumber(L, false);
}
return 1;
}

int32_t LuaScriptInterface::luaGetCombatPercentageAbsorbed(lua_State *L)
{
ScriptEnviroment* env = getEnv();
CombatType_t combat = (CombatType_t)popNumber(L);
if(!combat)
{
errorEx(getError(LUA_ERROR_COMBAT_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
lua_pushnumber(L, player->getAbsorbedPercent(combat));
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushnumber(L, false);
}
return 1;
}[/cpp]

Finally, go to luascript.h and find:
[cpp] static int32_t luaDoPlayerRemoveMoney(lua_State* L);[/cpp]

Below it, paste:
[cpp] static int32_t luaDoCombatAbsorbPercentage(lua_State* L);
static int32_t luaGetCombatPercentageAbsorbed(lua_State* L);[/cpp]

These functions will absorb the damage percentage of the combat declared, ex:

You setted 50% to the physical damage, so if a Demon will do a damage of 100 hit points, you'll lose only 500 hitpoints.

How to use?
Lua:
doAbsorbCombatPercentage(cid, COMBAT_FIREDAMAGE, 50)
getCombatPercentageAbsorbed(cid, COMBAT_FIREDAMAGE)

Note: If the player logouts, the protection will disappear, to make it not removable, it needs to use queries.

Rep++ will be appreciated.
 
Last edited:
and can't work with values like "-150"?
 
Last edited by a moderator:
Thanks!
Darkhaos can you make now - increasePhysicalDamage ? :)
 
If this only work with player... they can be do more easy and more advanced with "onStatsChange" and without source editing...
 
Man..this function dont work in the newst mystic spirit and in the cryng 0.3.5..when you enter a chacter the serve down, however its good
 
Man..this function dont work in the newst mystic spirit and in the cryng 0.3.5..when you enter a chacter the serve down, however its good

Really don't know because i tested it on TFS 0.3.6, try to rebuild the project again (Don't press the Compile button, press the Rebuild Button)
 
Ahh, I was forgetting this detail ... but still no good for this version, players can not attack, but this is really good 0.3.6

And you have to modify the post has an error in relation with luascript.cpp and luascript.h
 
Ahh, I was forgetting this detail ... but still no good for this version, players can not attack, but this is really good 0.3.6

And you have to modify the post has an error in relation with luascript.cpp and luascript.h

What error? it works good for me :)
 
.cpp
//doAbsorbCombatPercentage(cid, combat, percent)
lua_register(m_luaState, "doAbsorbCombatPercentage", LuaScriptInterface::luaDoAbsorbCombatPercentage);

.h
static int32_t luaDoCombatAbsorbPercentage(lua_State* L);


And the players can't atack with this script, i dont know why ^^, maybe:
percent = player->getAbsorbedPercent(combatType);
total = damage * percent / (int32_t)100;
when percent is 0 total is 0 too, i dont know
 
Go to game.cpp and replace
[cpp]damage -= total;[/cpp]

With:
[cpp]if(total > 0)
damage -= total;[/cpp]
 
int32_t../luascript.cpp: In member function `virtual void LuaScriptInterface::registerFunctions()':
../luascript.cpp:1682: error: `luaDoAbsorbCombatPercentage' is not a member of `LuaScriptInterface'

../luascript.cpp: At global scope:
../luascript.cpp:4782: error: no `int32_t LuaScriptInterface::luaDoAbsorbCombatPercentage(lua_State*)' member function declared in class `LuaScriptInterface'

make.exe: *** [obj//luascript.o] Error 1
 
../luascript.cpp: In member function `virtual void LuaScriptInterface::registerFunctions()':
../luascript.cpp:1678: error: `luaDoAbsorbCombatPercentage' is not a member of `LuaScriptInterface'

../luascript.cpp: At global scope:
../luascript.cpp:4757: error: no `int32_t LuaScriptInterface::luaDoAbsorbCombatPercentage(lua_State*)' member function declared in class `LuaScriptInterface'

make.exe: *** [obj//luascript.o] Error 1

Execução terminada
 
I have Error...

Code:
 C:\Documents and Settings\DOMA\Pulpit\DBP_Client\Serwery\Silniki\Dragon Ball\SOURCE\luascript.cpp In member function `virtual void LuaScriptInterface::registerFunctions()': 
 1678 C:\Documents and Settings\DOMA\Pulpit\DBP_Client\Serwery\Silniki\Dragon Ball\SOURCE\luascript.cpp `luaDoAbsorbCombatPercentage' is not a member of `LuaScriptInterface' 
 1678 C:\Documents and Settings\DOMA\Pulpit\DBP_Client\Serwery\Silniki\Dragon Ball\SOURCE\luascript.cpp At global scope: 
 4757 C:\Documents and Settings\DOMA\Pulpit\DBP_Client\Serwery\Silniki\Dragon Ball\SOURCE\luascript.cpp no `int32_t LuaScriptInterface::luaDoAbsorbCombatPercentage(lua_State*)' member function declared in class `LuaScriptInterface' 
  C:\Documents and Settings\DOMA\Pulpit\DBP_Client\Serwery\Silniki\Dragon Ball\SOURCE\dev-cpp\Makefile.win [Build Error]  [obj//luascript.o] Error 1

Pls help me, i need this code
 
bump

got same problem as up

any ideas how to fix it?
 
Back
Top