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

Compiling damage owner?

Swiff

Member
Joined
Apr 6, 2009
Messages
366
Reaction score
12
Location
Sweden
I'm not sure how to describe it. after I've implemented a number of source changes, namely:
http://otland.net/threads/increase-player-damage.177331/#post-1991331 <- fault
http://otland.net/threads/level-and-vocation-instead-of-world-name-on-character-login.158447/
http://otland.net/threads/autostacking-stackable-items-in-tfs-0-3-6pl1.162795/ <-fine

and commenting out the "checking software version" due to "malformed file" like so ;
Code:
    /*
    std::cout << ">> Checking software version... ";
    #if defined(WINDOWS) && !defined(__CONSOLE__)
    SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> Checking software version");
    #endif
    if(xmlDocPtr doc = xmlParseFile(VERSION_CHECK))
    {
        xmlNodePtr p, root = xmlDocGetRootElement(doc);
        if(!xmlStrcmp(root->name, (const xmlChar*)"versions"))
        {
            p = root->children->next;
            if(!xmlStrcmp(p->name, (const xmlChar*)"entry"))
            {
                std::string version;
                int32_t patch, build, timestamp;

                bool tmp = false;
                if(readXMLString(p, "version", version) && version != STATUS_SERVER_VERSION)
                    tmp = true;

                if(readXMLInteger(p, "patch", patch) && patch > VERSION_PATCH)
                    tmp = true;

                if(readXMLInteger(p, "build", build) && build > VERSION_BUILD)
                    tmp = true;

                if(readXMLInteger(p, "timestamp", timestamp) && timestamp > VERSION_TIMESTAMP)
                    tmp = true;

                if(tmp)
                {
                    std::cout << "outdated, please consider updating!" << std::endl;
                    std::cout << "> Current version information - version: " << STATUS_SERVER_VERSION << ", patch: " << VERSION_PATCH;
                    std::cout << ", build: " << VERSION_BUILD << ", timestamp: " << VERSION_TIMESTAMP << "." << std::endl;
                    std::cout << "> Latest version information - version: " << version << ", patch: " << patch;
                    std::cout << ", build: " << build << ", timestamp: " << timestamp << "." << std::endl;
                    if(g_config.getBool(ConfigManager::CONFIM_OUTDATED_VERSION) && version.find("_SVN") == std::string::npos)
                    {
                        #if defined(WINDOWS) && !defined(__CONSOLE__)
                        if(MessageBox(GUI::getInstance()->m_mainWindow, "Continue?", "Outdated software", MB_YESNO) == IDNO)
                        #else
                        std::cout << "Continue? (y/N)" << std::endl;
 
                        char buffer = getchar();
                        if(buffer == 10 || (buffer != 121 && buffer != 89))
                        #endif
                            startupErrorMessage("Aborted.");
                    }
                }
                else
                    std::cout << "up to date!" << std::endl;
            }
            else
                std::cout << "failed checking - malformed entry." << std::endl;
        }
        else
            std::cout << "failed checking - malformed file." << std::endl;

        xmlFreeDoc(doc);
    }
    else
        std::cout << "failed - could not parse remote file (are you connected to the internet?)" << std::endl;
    /**/

My server started to crash, alot.
I managed to find the source in-game of the crash by testing. It lead me to firefield, and then to the conclusion that when there's no creature or player online/alive and I(player) take damage from it(like posion or firefield) Server crashes. Illustration below, when scorpion is alive and i take posion damage, it's all good. but when I kill it, and the posion is about to damage me, server crashes that very moment.

9z2y.png


I will make a fresh .dev and do the changes step by step and test which one is causing the issue tomorrow. But even if i knew I doubt I'd find the cause in those codes. So if anyone got a hunch or maybe experienced the same problem, do you know where the cause is?

I'm using TFS 0.3.6pl1
from: svn://svn.otland.net/public/forgottenserver/tags/0.3.6pl1

Thanks in advance, will edit this post tomorrow when I've located which feature are wrong

Edit:
After adding them one by one I got to Erikas feature Increase player damage, and this one was the burglar;http://otland.net/threads/increase-player-damage.177331/#post-1991331

I don't know the coding language, but i have a feeling this:
Code:
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);
}

Is bad code. The compiler don't give me any syntax errors or warnings, just 100% successfull compile. I can't verify is this code is bad because if i take some away it will error upon compile.
 
Last edited:
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)

And this Coding Language is C++
 
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
lastDamageSource = combatType;
onAttacked();

if(attacker->getPlayer())
{

changeHealth(-damage);
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;
Player* player = NULL;
player->getName()
std::stringstream ss;
ss << "+" << damage - realDamage;
g_game.addAnimatedText(attacker->getPosition(), (uint8_t)color, ss.str());
}
}

Dont is possible compile

Watch Photo >>>>>>>>>>
http://scr.hu/0km1/iq6t4
 
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
lastDamageSource = combatType;
onAttacked();

if(attacker->getPlayer())
{

changeHealth(-damage);
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;
Player* player = NULL;
player->getName()
std::stringstream ss;
ss << "+" << damage - realDamage;
g_game.addAnimatedText(attacker->getPosition(), (uint8_t)color, ss.str());
}
}

Dont is possible compile

Watch Photo >>>>>>>>>>
http://scr.hu/0km1/iq6t4
What I Posted isn't a solution it is just a conclusion of why it crash
 
Thanks tetra. I will check my current cpp file and compare those lines.

Well the original looks like this;
Code:
void Creature::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
    lastDamageSource = combatType;
    onAttacked();

    changeHealth(-damage);
    if(attacker)
        attacker->onAttackedCreatureDrainHealth(this, damage);
}
And all that code is in the new code..
So, in other words. I won't be able to fix this. I have too little knowledge.
Thanks for pointing the fault out anyways
 
Last edited:
my only solution for you isn't a source edit it is like this
Code:
function onStatsChange(cid,attacker,type,value)
local damage = extra damage
if isPlayer(cid) and isMonster(target)
doCreatureAddhealth(target, damage)
doSendAnimatedText(getThingPos(cid), "-"..damage.."",COLOR_RED)
end
return true
end
 
I'm guessing this is an addon for the faulty source edit. Not a replacer for that specific code? I'm not sure if it'd be possible to compile without having the complete edits. I might try this, thanks for your help.
 
if i were you i wouldn't compile with that Extra Damage and make a lua script and you have an example above i posted
 
I don't really have the knowledge to make a script like that. Most scripts I've been doing is just editing, copying some lines from another script that I think I need, sometimes it works...
onStatsChange would be a creaturescript I suppose. But that's about all I could figure. With that script that you gave me, it looks like.. er, unfinished. there's nothing that defines extra damage xd Also, doCreatureAddHealth? doesen't that add health to target from the variable "extra damage"?

Er wait. Maybe I got it wrong, maybe this script should go into a onequip script? movement~
edit:
I have no clue what to do with this code to be honest ;P
 
Ok Here You Are a Full Code -- Self-Explantory
Create a new extra.lua in CreatureScripts/scripts
Code:
function onStatsChange(cid, attacker, type, combat, value)
-- This Is a Script for the normal damage (Constant for Every Player) just remove the --[[ at the first and the --]] at the end if you want it
   --[[   local damage = 5
       if isPlayer(cid) and isMonster(target) and type == STATSCHANGE_HEALTHLOSS then
       doCreatureAddhealth(target, -damage)
       doSendAnimatedText(getThingPos(target),"-"..damage.."")
       end
     return true
   end--]]
local damage = (value / 10) * 5 -- this will get be like this if attack hit the monster with 30 (30/10)*5 = 15 extra damage so it is 15+30 == 45
   if isPlayer(cid) and isMonster(target) and type == STATSCHANGE_HEALTHLOSS then
   doCreatureAddhealth(target, -damage)
   doSendAnimatedText(getThingPos(target),"-"..damage.."")
   end
   return true
end
-- if you want to cancel this just add --[[ at local damage and --]] at the last end

add this in creaturescripts.xml
Code:
<event type="statschange" name="extra" event="script" value="extra.lua"/>

add This in Login.lua
Code:
registerCreatureEvent(cid, "extra")
 
I appreciate all your help tetra!

However, I might've missunderstood this script, but the feature I am trying to implement is to be able to give the player bonus damage depending on what storage he has, or what item he has equipped.
for example:

Code:
function onLogin(cid)
if getPlayerStorageValue(cid,6601) == true then
doPlayerSetExtraDamage(cid, extradamage)
end
return true
end


or item:
Code:
function onEquip(cid, item, slot)
doPlayerSetExtraDamage(cid, 100)
return true
end

function onDeEquip(cid, item, slot)
doPlayerSetExtraDamage(cid, 1)
return true
end

As I said maybe I misunderstood this onStatsChange script, but to me it seems it will excecute everytime someone make an attack. I could achieve this by simply editing the players base attack damage and spell damage in vocations.xml
So before I start to research how to add this onStatsChange into a storage value or an item, can you clarify if that is what we're trying to do here? Thanks!

Edit:
I'm too tired today I will be trying to add this to onEquip tomorrow
 
Last edited:
Code:
function onStatsChange(cid, attacker,type,value)
if getPlayerSlotItem(cid, slotid).itemid == item then
doCreatureAddHealth(attacker, -100)
end
return true
end
 
Thanks again!
Not sure if I did it correctly, because it doesen't do any added damage:
in mveoemnts.xml:
Code:
    <movevent type="DeEquip" itemid="7708" slot="ring" event="function" value="onDeEquipItem"/>
    <movevent type="Equip" itemid="7708" slot="ring" event="function" value="onEquipItem"/>
in creaturescripts:
Code:
<event type="statschange" name="extra" event="script" value="extra.lua"/>
in extra.lua:
Code:
function onStatsChange(cid, attacker,type,value)
if getPlayerSlotItem(cid, CONST_SLOT_RING).itemid == 7708 then
doCreatureAddHealth(attacker, -10000)
end
return true
end
in login:
Code:
registerCreatureEvent(cid, "extra")
no extra
 
Back
Top