• 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++ how to deal with chatted strings on server-side?

nettoMain

New Member
Joined
Jan 15, 2018
Messages
8
Reaction score
4
Hello, I want to do some operations with the strings that are submitted to the chat.
Basically, I need to know which is the function that is called when a player chat.
I've made some tests and I think that's Creature:: onCreatureSay(,,), is it correct? If so, should I just override the method in my Player class?

Greetings,

P.S.: I rlly need to do it with source edits.
 
Last edited:
theforgottenserver, master branch. Btw I think it's not important, since the method should be the same, regardless of version.
As a portuguese native speaker, it will be hard to explain, but I'll try:
when a player text, the server need to see if the submitted string contains the substring "foo", if so, the server will call a function passing a substring
—with the foo value— as parameter.
I've had a quick look at the chat methods, and coded this:
C++:
void Player::onCreatureSay(Creature* creature, SpeakClasses, const std::string& text)
{
    const Player* speaker = creature->getPlayer();
    if (speaker && text.find("foo") != std::string::npos)
    {
        speaker->doStuff("foo");
     }
}
I've compiled that code and it's working, but is it the most efficient way to do what I want?
If not, what method should I modify? I've noticed some relationated methods, like the bool method ChatChannel::talk(,,).
 
thank you all for the attempts to help, but my question is:
which method is called when a creature say something.
It isn't: oh god can someone please teach me how to use talkactions
 
Well there are several functions involved. It would be easier if you used google translate and explained what you are trying to acheive.
 
I've compiled that code and it's working, but is it the most efficient way to do what I want?
If not, what method should I modify? I've noticed some relationated methods, like the bool method ChatChannel::talk(,,).
If we knew what exactly you wanted to do it would be easier to tell you if it was the best way to do it.
 
So you are saying like these chat windows?
Mmmh no, i dont think its the same as that.

For example: I write in chat: "hello my name is vysius" so in sources i hook that string, modify it and returns: "Suisyv si eman ym ollah". Its a dumb example, but what he wants is to be aable to process the text written.
 
Mmmh no, i dont think its the same as that.

For example: I write in chat: "hello my name is vysius" so in sources i hook that string, modify it and returns: "Suisyv si eman ym ollah". Its a dumb example, but what he wants is to be aable to process the text written.
To process the written text you need to access the chat channels method's, whether they are in lua or c++.

The easy way is to do it in the sources, the hard way would be to do it in strictly a script, but you could combine the two.
 
Mmmh no, i dont think its the same as that.

For example: I write in chat: "hello my name is vysius" so in sources i hook that string, modify it and returns: "Suisyv si eman ym ollah". Its a dumb example, but what he wants is to be aable to process the text written.
To process the written text you need to access the chat channels method's, whether they are in lua or c++.

The easy way is to do it in the sources, the hard way would be to do it in strictly a script, but you could combine the two.
I'm unsure if tfs 1.2 has a "default" talkaction but it's very easy to do with nothing but lua in 0.4
780c6b9a0868e948a8aa9f4efd5ed50a.gif

works in all channels btw
So yeah, @nettoMain if we have more information on what you're trying to do, it could save time & effort.
 
Back
Top