• 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

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
85
Location
Portugal
Hey, can any1 tell me how can I add numbers infront of displaying monster name?
I'm not sure this is the code that displays the monster name to the players, if it's not please tell me where it is.

Default code:
Code:
    if (new_mType) {
        mType = &monsters[asLowerCaseString(monsterName)];
    }

        mType->name = attr.as_string();//aqui str

My code:
Code:
    if (new_mType) {
        mType = &monsters[asLowerCaseString(monsterName + number)];
    }

        mType->name = attr.as_string();//aqui str

Thank you in advance :p
 
Depends on what you want to achieve. You can either change the name being sent in the ProtocolGame (which in my opinion would be better) or keep with your idea.
Code:
mType->name = std::to_string(number) + " " + monsterName;
 
I'm trying to create levels for monsters, I already made the code to load it from XML I just have no idea how to make it show on monster name :p

my variable name is: monsterLevel

18:51 Loot of a Abyssador [Lvl: 500]: Guthans Mace, Ahrim's Legs, 50 gold coins, 100 gold coins

[Lvl: 500] is sourced, but I was only able to put it after description and not name

Protocolgame.cpp:
http://pastebin.com/jtFcvWXk
 
I'm trying to create levels for monsters, I already made the code to load it from XML I just have no idea how to make it show on monster name :p

my variable name is: monsterLevel



[Lvl: 500] is sourced, but I was only able to put it after description and not name

Protocolgame.cpp:
http://pastebin.com/jtFcvWXk
Here:
https://github.com/otland/forgottenserver/blob/master/src/protocolgame.cpp#L2765

Change to:
http://pastebin.com/0qA4WFfU

That should work, you must replace "getLevel" with your own function or whatever you use to get monster level.
 
Code:
std::string monsterLevel = std::to_string(creature->getMonsterLevel());
msg.addString(creature->getName() + " [" + monsterLevel + "]");

Thanks @Nu77 it worked perfectly, I fixed the function and it's working 100% now!

Does any1 know how to make math.random() in c++?

for example:

Code:
math.random(monsterLevel, (monsterLevel+100))

but in C++
 
You can use one of TFS utility functions like:
Code:
int32_t uniform_random(int32_t minNumber, int32_t maxNumber)
int32_t normal_random(int32_t minNumber, int32_t maxNumber)
bool boolean_random(double probability/* = 0.5*/)
 
Thanks :p

Last question :oops:

Code:
msg.addString(creature->getName() + " [" + monsterLevel + "]" + "\n" + "[" + monsterHealth + "]");

monster can't show health numbers under name and level because thats client sided right?

ex:

tE7d0eP.png


P.S: Sorry for my kickass paint skills XD
 
Thanks :p

Last question :oops:

Code:
msg.addString(creature->getName() + " [" + monsterLevel + "]" + "\n" + "[" + monsterHealth + "]");

monster can't show health numbers under name and level because thats client sided right?

ex:

tE7d0eP.png


P.S: Sorry for my kickass paint skills XD
Creature names is cached and only changes when you remove or add a creature.
Maybe you should make a new function for change creature name and by Lua update it every time monster HP changes ( Client side is better than server side ).
 
btw I just found out that

Code:
if (known) {
        msg.add<uint16_t>(0x62);
        msg.add<uint32_t>(creature->getID());
    }
    else {
        msg.add<uint16_t>(0x61);
        msg.add<uint32_t>(remove);
        msg.add<uint32_t>(creature->getID());
        msg.addByte(creatureType);
        if (creatureType != CREATURETYPE_MONSTER) {
            msg.addString(creature->getName());
        }
        else {
            // Get monster level here
            std::string monsterLevel = std::to_string(rand() % creature->getMonsterLevel());
            msg.addString(creature->getName() + " [" + monsterLevel + "]");
        }
    }

is causing same monster to show different levels, like it shows lvl 501 to me and 489 to my rl friend
using normal random c++ function
 
Last edited:
Why are you getting a random number on creature name packet instead of spawn time? Makes no sense, clearly different Players will see different number's.
Just do to every time a new monster is created generate a random level.
 
thanks, will do it

btw can you check this one?
I get no errors in compiling but when I login I get insta debug :(

Code:
if (known) {
        msg.add<uint16_t>(0x62);
        msg.add<uint32_t>(creature->getID());
    }
    else {
        msg.add<uint16_t>(0x61);
        msg.add<uint32_t>(remove);
        msg.add<uint32_t>(creature->getID());
        msg.addByte(creatureType);
        if (creatureType == CREATURETYPE_PLAYER && player->getGuild() == nullptr) {
            msg.addString(player->getName() + " [NO GUILD]");
        }
        else if (creatureType == CREATURETYPE_PLAYER && player->getGuild() != nullptr) {
            msg.addString(player->getName() + " [" + player->getGuildNick() + "]");
        }
    }

P.S: complete file: http://pastebin.com/WyPTJPpJ
 
Back
Top