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

C++ TFS 1.2 8.6 Random Color Experience

ssiwyy158

Member
Joined
Jan 24, 2011
Messages
128
Solutions
2
Reaction score
13
I tried to change the code from this topic:

I get error:
1.png
2.png

My creature.cpp:
 
If you read the errors outputed by visual studio, you will see, firstly that you removed the opening of the function "{".

The curly brackets that should be on line 1142 is now on line 1161 because you simply copied the code from the thread without even noticing you were placing it in the wrong spot.
 
If you read the errors outputed by visual studio, you will see, firstly that you removed the opening of the function "{".

The curly brackets that should be on line 1142 is now on line 1161 because you simply copied the code from the thread without even noticing you were placing it in the wrong spot.

I'm trying to fix it but im noob
3.png

creature.cpp:
C++:
void Creature::onGainExperience(uint64_t gainExp, Creature* target)
{
    TextMessage message(MESSAGE_EXPERIENCE_OTHERS, ucfirst(getNameDescription()) + " gained " + std::to_string(gainExp) + (gainExp != 1 ? " experience points." : " experience point."));
    static constexpr std::array<TextColor_t, 12> colors = {
        TEXTCOLOR_BLUE,
        TEXTCOLOR_LIGHTGREEN,
        TEXTCOLOR_LIGHTBLUE,
        TEXTCOLOR_MAYABLUE,
        TEXTCOLOR_DARKRED,
        TEXTCOLOR_LIGHTGREY,
        TEXTCOLOR_SKYBLUE,
        TEXTCOLOR_PURPLE,
        TEXTCOLOR_RED,
        TEXTCOLOR_ORANGE,
        TEXTCOLOR_YELLOW,
        TEXTCOLOR_WHITE_EXP,
    };
    message.position = position;
    message.primary.color = colors[uniform_random(0, colors.size() - 1)];
    message.primary.value = gainExp;
    
}

{
    if (gainExp == 0 || !master) {
        return;
    }

    gainExp /= 2;
    master->onGainExperience(gainExp, target);

    std::ostringstream strExp;
    strExp << gainExp;
    g_game.addAnimatedText(strExp.str(), _position, TEXTCOLOR_WHITE_EXP);
}
 
You have added the curly bracket at the start of the method but haven't removed the one on line 1161.
8.png

C++:
void Creature::onGainExperience(uint64_t gainExp, Creature* target)

{
    if (gainExp == 0 || !master) {
        return;
    }
    
    TextMessage message(MESSAGE_EXPERIENCE_OTHERS, ucfirst(getNameDescription()) + " gained " + std::to_string(gainExp) + (gainExp != 1 ? " experience points." : " experience point."));
    static constexpr std::array<TextColor_t, 12> colors = {
        TEXTCOLOR_BLUE,
        TEXTCOLOR_LIGHTGREEN,
        TEXTCOLOR_LIGHTBLUE,
        TEXTCOLOR_MAYABLUE,
        TEXTCOLOR_DARKRED,
        TEXTCOLOR_LIGHTGREY,
        TEXTCOLOR_SKYBLUE,
        TEXTCOLOR_PURPLE,
        TEXTCOLOR_RED,
        TEXTCOLOR_ORANGE,
        TEXTCOLOR_YELLOW,
        TEXTCOLOR_WHITE_EXP,
    };
    message.position = position;
    message.primary.color = colors[uniform_random(0, colors.size() - 1)];
    message.primary.value = gainExp;

    gainExp /= 2;
    master->onGainExperience(gainExp, target);

    std::ostringstream strExp;
    strExp << gainExp;
    g_game.addAnimatedText(strExp.str(), _position, TEXTCOLOR_WHITE_EXP);
}
 
Try this.

C++:
void Creature::onGainExperience(uint64_t gainExp, Creature* target)

{
    if (gainExp == 0 || !master) {
        return;
    }
    
    static constexpr std::array<TextColor_t, 12> colors = {
        TEXTCOLOR_BLUE,
        TEXTCOLOR_LIGHTGREEN,
        TEXTCOLOR_LIGHTBLUE,
        TEXTCOLOR_MAYABLUE,
        TEXTCOLOR_DARKRED,
        TEXTCOLOR_LIGHTGREY,
        TEXTCOLOR_SKYBLUE,
        TEXTCOLOR_PURPLE,
        TEXTCOLOR_RED,
        TEXTCOLOR_ORANGE,
        TEXTCOLOR_YELLOW,
        TEXTCOLOR_WHITE_EXP,
    };

    gainExp /= 2;
    master->onGainExperience(gainExp, target);

    std::ostringstream strExp;
    strExp << gainExp;
    g_game.addAnimatedText(strExp.str(), _position, colors[uniform_random(0, colors.size() - 1)]);
}
 
Try this.

C++:
void Creature::onGainExperience(uint64_t gainExp, Creature* target)

{
    if (gainExp == 0 || !master) {
        return;
    }
   
    static constexpr std::array<TextColor_t, 12> colors = {
        TEXTCOLOR_BLUE,
        TEXTCOLOR_LIGHTGREEN,
        TEXTCOLOR_LIGHTBLUE,
        TEXTCOLOR_MAYABLUE,
        TEXTCOLOR_DARKRED,
        TEXTCOLOR_LIGHTGREY,
        TEXTCOLOR_SKYBLUE,
        TEXTCOLOR_PURPLE,
        TEXTCOLOR_RED,
        TEXTCOLOR_ORANGE,
        TEXTCOLOR_YELLOW,
        TEXTCOLOR_WHITE_EXP,
    };

    gainExp /= 2;
    master->onGainExperience(gainExp, target);

    std::ostringstream strExp;
    strExp << gainExp;
    g_game.addAnimatedText(strExp.str(), _position, colors[uniform_random(0, colors.size() - 1)]);
}

There is no error, but only displays white color exp :(
 
Can you change this line:
g_game.addAnimatedText(strExp.str(), _position, colors[uniform_random(0, colors.size() - 1)]);

to
g_game.addAnimatedText(strExp.str(), _position, TEXTCOLOR_RED);

Just so we know we are changing it in the right place. Also, are you moving the new compiled distro to your server dir?
 
Can you change this line:
g_game.addAnimatedText(strExp.str(), _position, colors[uniform_random(0, colors.size() - 1)]);

to
g_game.addAnimatedText(strExp.str(), _position, TEXTCOLOR_RED);

Just so we know we are changing it in the right place. Also, are you moving the new compiled distro to your server dir?
Yes i moving the new compiled. I change this:
Code:
g_game.addAnimatedText(strExp.str(), _position, colors[uniform_random(0, colors.size() - 1)]);
to
Code:
g_game.addAnimatedText(strExp.str(), _position, TEXTCOLOR_RED);

But displays white color
 
Back
Top