• 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 Increase player damage

Erikas Kontenis

Board Moderator
Staff member
Board Moderator
Joined
Jul 3, 2009
Messages
1,859
Reaction score
556
Location
Lithuania
This code have been used to sell as request but it was needed some scripting part and I feeling very tired of my scripting/programming services. Also I just started up my real map server my free time overloaded. I have nothing bad against buyer who told me to do this.

So result of this code is a lua function that increases player any health damage to target. And sendAnimatedMessage how much boosted his hit is with increasement.

this works with simple formula: (Real damage + Real Damage*param); sendAnimatedMessage formula: (Real Damage*param - real damage)

Tested and works like angel on tfs 0.3.6 (8.54 protocol) -- I just love outdated this version :) However it won't be a problem too much to update it for 0.4 or something.

player.cpp


Code:
lastAttack = idleTime = marriage = blessings = balance = premiumDays = mana = manaMax = manaSpent = extraAttackSpeed = 0;

after this line make new line with code:

Code:
extraMagicDamage = 1; // Erikas

in the end of player.cpp add this code:

Code:
void Player::setPlayerExtraMagicDamage(uint32_t damage)
{
	extraMagicDamage = damage;
}

player.h

Code:
uint32_t getMagicLevel() const {return getPlayerInfo(PLAYERINFO_MAGICLEVEL);}
		uint64_t getSpentMana() const {return manaSpent;}

after this line make new line with code:

Code:
uint32_t getExtraMagicDamage() const {return extraMagicDamage;}
		void setPlayerExtraMagicDamage(uint32_t damage);


Code:
uint32_t idleTime;

after this line make new line with code:

Code:
uint32_t extraAttackSpeed;

creature.cpp

found this function:

Code:
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)

and replace it all to this:

Code:
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
	lastDamageSource = combatType;
	onAttacked();
	
	if(attacker->getPlayer())
	{
		if(attacker->getPlayer()->getExtraMagicDamage() > 1)
		{
			int16_t color = g_config.getNumber(ConfigManager::EXTRA_DAMAGE_COLOR);
			if(color < 0)
				color = random_range(0, 255);
			
			int realDamage = damage;
			damage = damage * attacker->getPlayer()->getExtraMagicDamage();
			std::stringstream ss;
			ss << "+" << damage - realDamage;
			g_game.addAnimatedText(attacker->getPosition(), (uint8_t)color, ss.str());
		}
	}
	
	
	changeHealth(-damage);
	
	if(attacker)
		attacker->onAttackedCreatureDrainHealth(this, damage);
}

configmanager.cpp

Code:
m_confNumber[EXPERIENCE_COLOR] = getGlobalNumber("gainExperienceColor", COLOR_WHITE);

after this line make new line with code:

Code:
//Erikas
	m_confNumber[EXTRA_DAMAGE_COLOR] = getGlobalNumber("extraDamageColor", COLOR_WHITE);
//Erikas

configmanager.h

Code:
EXPERIENCE_COLOR,

after this line make new line with code:

Code:
EXTRA_DAMAGE_COLOR,

luascript.cpp

Code:
//doPlayerAddSoul(cid, soul)
lua_register(m_luaState, "doPlayerAddSoul", LuaScriptInterface::luaDoPlayerAddSoul);

after this line make new line with code:

Code:
//doPlayerSetExtraMagicDamage(cid, damage)
lua_register(m_luaState, "doPlayerSetExtraMagicDamage", LuaScriptInterface::luaDoPlayerSetExtraMagicDamage);

Code:
int32_t LuaScriptInterface::luaDoPlayerAddSoul(lua_State* L)
{
	//doPlayerAddSoul(cid, soul)
	int32_t soul = popNumber(L);

	ScriptEnviroment* env = getEnv();
	if(Player* player = env->getPlayerByUID(popNumber(L)))
	{
		player->changeSoul(soul);
		lua_pushboolean(L, true);
	}
	else
	{
		errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushboolean(L, false);
	}
	return 1;
}

after this function make new line with code:

Code:
int32_t LuaScriptInterface::luaDoPlayerSetExtraMagicDamage(lua_State *L)
{    
    uint32_t damage = popNumber(L);           	
    ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L))){    
			player->setPlayerExtraMagicDamage(damage);
            lua_pushnumber(L, true);
       }    
       else{       
           errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
           lua_pushnumber(L, false);
       }       
    return 1;
}

luascript.h

Code:
static int32_t luaDoPlayerAddSoul(lua_State* L);

after this line make new line with code:

Code:
static int32_t luaDoPlayerSetExtraMagicDamage(lua_State* L);

config.lua

extraDamageColor = 50 -- anywhere place it in config.lua

how to use function:
Lua:
doPlayerSetExtraMagicDamage(cid, 1) -- Default no boost damage
doPlayerSetExtraMagicDamage(cid, 2) -- formula boost

Script example: http://otland.net/f81/ring-increase-attack-damage-179504/ & http://otland.net/f82/increase-player-damage-rebirth-181840/
 
Last edited:
Any idea how to make ring with that (ring what increasing the damage) ?
 
Updated, fixed crash bug o.o :D If creature attack player or something was crash because I forgot to add isPlayer condition ^^
 
can you update it to OTX 8.6? I try to updated it myself to OTX 8.6 and this appeared:
[14/12/2013 23:45:53] [Error - MoveEvents Interface]
[14/12/2013 23:45:53] data/movements/scripts/damageRing.lua:eek:nEquip
[14/12/2013 23:45:53] Description:
[14/12/2013 23:45:53] data/movements/scripts/damageRing.lua:2: attempt to call global 'doPlayerSetExtraMagicDamage' (a nil value)
[14/12/2013 23:45:53] stack traceback:
[14/12/2013 23:45:53] data/movements/scripts/damageRing.lua:2: in function <data/movements/scripts/damageRing.lua:1>
 
Search string: "
lastAttack = idleTime = marriage = blessings = balance = premiumDays = mana = manaMax = manaSpent = extraAttackSpeed = 0;" not found

Using: TFS0.3.6pl1
From: svn://svn.otland.net/public/forgottenserver/tags/0.3.6pl1

Edit:
It looks like this:
Code:
lastAttack = idleTime = marriage = blessings = balance = premiumDays = mana = manaMax = manaSpent = 0;

I am a bit confused now, as I don't ahve extraAttackspeed, I don't think I should change this?

""""
Code:
uint32_t idleTime;
after this line make new line with code:

Code:
uint32_t extraAttackSpeed;
""""
Right? Wrong? :/



Failed:
23 C:\Users\Dan\Documents\The Wild\NYTFS0.3.6\actions.cpp In file included from ../actions.cpp
23 C:\Users\Dan\Documents\The Wild\NYTFS0.3.6\actions.cpp In member function 'uint32_t Player::getExtraMagicDamage() const':
276 C:\Users\Dan\Documents\The Wild\NYTFS0.3.6\player.h 'extraMagicDamage' was not declared in this scope
276 C:\Users\Dan\Documents\The Wild\NYTFS0.3.6\player.h *** [obj//actions.o] Error 1
The dev marks the #include "player.h"

"player.h 'extraMagicDamage' was not declared in this scope" <- What do they mean declared?
Is this not a declaration?;
Code:
uint32_t getExtraMagicDamage() const {return extraMagicDamage;}
This is line 276 in player.h

and in action I found this on line 23:
#include "player.h"
I think everything is in order... EXCEPT this attackspeed that you have that I don't?

The only source edit on extraattackspeed i found on otland was darkhaos:
http://otland.net/threads/doplayersetextraattackspeed-cid-speed.58945/#post-603459

I need to use this one?
____
Edit:
I looked through your whole post again and found nothing that I did wrong. So I changed
Code:
lastAttack = idleTime = marriage = blessings = balance = premiumDays = mana = manaMax = manaSpent = 0;
to
Code:
lastAttack = idleTime = marriage = blessings = balance = premiumDays = mana = manaMax = manaSpent = extraAttackSpeed = 0;
and also added
Code:
uint32_t extraAttackSpeed;
below
Code:
uint32_t idleTime;

But i get same error:
Code:
Compiler: Default compiler
Building Makefile: "C:\Users\Dan\Documents\The Wild\NYTFS0.3.6\dev-cpp\Makefile.win"
Executing  make...
mingw32-make -f "C:\Users\Dan\Documents\The Wild\NYTFS0.3.6\dev-cpp\Makefile.win" all
g++.exe -c ../actions.cpp -o obj//actions.o -I"C:/Dev-Cpp/Dev-Cpp/include"  -D__USE_MYSQL__ -D__USE_SQLITE__ -D__ENABLE_SERVER_DIAGNOSTIC__ -D__CONSOLE__   -fexpensive-optimizations -O1

In file included from ../actions.cpp:23:
../player.h: In member function 'uint32_t Player::getExtraMagicDamage() const':
../player.h:276: error: 'extraMagicDamage' was not declared in this scope

mingw32-make: *** [obj//actions.o] Error 1

Execution terminated
 
Last edited:
So I finally got it to work. I'll post same guide as Erikas but a little edited which worked for me (tfs 03.6pl1 )
from: svn://svn.otland.net/public/forgottenserver/tags/0.3.6pl1

player.cpp

Code:
lastAttack = idleTime = marriage = blessings = balance = premiumDays = mana = manaMax = manaSpent = 0;

after this line make new line with code:

Code:
extraMagicDamage = 1; // Erikas

in the end of player.cpp add this code:

Code:
void Player::setPlayerExtraMagicDamage(uint32_t damage)
{
    extraMagicDamage = damage;
}

player.h

Code:
uint32_t getMagicLevel() const {return getPlayerInfo(PLAYERINFO_MAGICLEVEL);}
        uint64_t getSpentMana() const {return manaSpent;}

after this line make new line with code:

Code:
uint32_t getExtraMagicDamage() const {return extraMagicDamage;}
        void setPlayerExtraMagicDamage(uint32_t damage);


Code:
uint32_t idleTime;

after this line make new line with code:

Code:
uint32_t extraMagicDamage;

creature.cpp

found this function:

Code:
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)

and replace it all to this:

Code:
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
    lastDamageSource = combatType;
    onAttacked();
  
    if(attacker->getPlayer())
    {
        if(attacker->getPlayer()->getExtraMagicDamage() > 1)
        {
            int16_t color = g_config.getNumber(ConfigManager::EXTRA_DAMAGE_COLOR);
            if(color < 0)
                color = random_range(0, 255);
          
            int realDamage = damage;
            damage = damage * attacker->getPlayer()->getExtraMagicDamage();
            std::stringstream ss;
            ss << "+" << damage - realDamage;
            g_game.addAnimatedText(attacker->getPosition(), (uint8_t)color, ss.str());
        }
    }
  
  
    changeHealth(-damage);
  
    if(attacker)
        attacker->onAttackedCreatureDrainHealth(this, damage);
}

configmanager.cpp

Code:
m_confNumber[EXPERIENCE_COLOR] = getGlobalNumber("gainExperienceColor", TEXTCOLOR_WHITE);

after this line make new line with code:

Code:
//Erikas
    m_confNumber[EXTRA_DAMAGE_COLOR] = getGlobalNumber("extraDamageColor", TEXTCOLOR_WHITE);
//Erikas

configmanager.h

Code:
EXPERIENCE_COLOR,

after this line make new line with code:

Code:
EXTRA_DAMAGE_COLOR,

luascript.cpp

Code:
//doPlayerAddSoul(cid, soul)
lua_register(m_luaState, "doPlayerAddSoul", LuaScriptInterface::luaDoPlayerAddSoul);

after this line make new line with code:

Code:
//doPlayerSetExtraMagicDamage(cid, damage)
lua_register(m_luaState, "doPlayerSetExtraMagicDamage", LuaScriptInterface::luaDoPlayerSetExtraMagicDamage);

Code:
int32_t LuaScriptInterface::luaDoPlayerAddSoul(lua_State* L)
{
    //doPlayerAddSoul(cid, soul)
    int32_t soul = popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
    {
        player->changeSoul(soul);
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}

after this function make new line with code:

Code:
int32_t LuaScriptInterface::luaDoPlayerSetExtraMagicDamage(lua_State *L)
{  
    uint32_t damage = popNumber(L);             
    ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L))){  
            player->setPlayerExtraMagicDamage(damage);
            lua_pushnumber(L, true);
       }  
       else{     
           errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
           lua_pushnumber(L, false);
       }     
    return 1;
}

luascript.h

Code:
static int32_t luaDoPlayerAddSoul(lua_State* L);

after this line make new line with code:

Code:
static int32_t luaDoPlayerSetExtraMagicDamage(lua_State* L);

config.lua

extraDamageColor = 50 -- anywhere place it in config.lua

Hope I helped some!
 
This is The Line of Crash
Code:
damage = damage * attacker->getPlayer()->getExtraMagicDamage();
because when the Scorpion is Dead there is no Attacker so it is like this
Code:
Player* player = NULL;
player->getName()
Getting Information From Null Crash.i hope what i said is right(correct me if i said something wrong)
 
for TFS 0.4 only use this on luascript.cpp:
//doPlayerSetExtraMagicDamage(cid, damage)
lua_register(m_luaState, "doPlayerSetExtraMagicDamage", LuaInterface::luaDoPlayerSetExtraMagicDamage);

and:
int32_t LuaInterface::luaDoPlayerSetExtraMagicDamage(lua_State* L)
{

int32_t damage = popNumber(L);

ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->setPlayerExtraMagicDamage(damage);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
 
how change Valor Int to Float? for put damage 1.3 1.5 etc
 
There is a mistake in player.h should be:
Code:
uint32_t extraMagicDamage;
Instead of:
Code:
uint32_t extraAttackSpeed;
 
Really cool,
Ive been trying to figure out something like this for some time. I know its an old thread but seems like the only one on OTLand.

Did anyone manage to get it to work on 0.4? Cheers
 
Back
Top