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

Say spells with spaces

Terotrificy

Veteran OT User
Joined
Oct 18, 2020
Messages
401
Solutions
13
Reaction score
254
Location
Santiago, Chile.
Hi, i'm trying to modify the sources in an attempt to make it work like it works in tibia rl:

If i try to add extra spaces between a word and another when casting a spell, it won't work.

Example:


I guess i should modify this part, but i'm not certain about what to do at all:


C++:
TalkActionResult_t Spells::playerSaySpell(Player* player, SpeakClasses type, std::string& words)
{
    std::string str_words = words;

    //strip trailing spaces
    trim_left(str_words, " ");
    trim_right(str_words, " ");

    InstantSpell* instantSpell = getInstantSpell(str_words);
    if (!instantSpell){
        return TALKACTION_CONTINUE;
    }
    std::string param = "";

    if (instantSpell->getHasParam()){
        size_t spellLen = instantSpell->getWords().length();
        size_t paramLen = str_words.length() - spellLen;
        std::string paramText = str_words.substr(spellLen, paramLen);

        if (!paramText.empty() && paramText[0] == ' '){
            size_t quote = paramText.find('"', 1);
            if(quote != std::string::npos) {
                size_t tmp = paramText.find('"', quote + 1);
                if(tmp == std::string::npos)
                    tmp = paramText.length();
    
                param = paramText.substr(quote + 1, tmp - quote - 1);
            }
            else if(paramText.find(' ', 1) == std::string::npos) {
                param = paramText.substr(1, paramText.length());
            }

            trim_left(param, " ");
            trim_right(param, " ");
        }
    }

    if (instantSpell->playerCastInstant(player, param)){
        return TALKACTION_BREAK;
    }
    else{
        return TALKACTION_FAILED;
    }
}

Anyone?
 
Solution
This code doesn't seem to be responsible for recognizing whether certain text is an incantation. You should probably look in getInstantSpell() or somewhere else. Here it only reads parameters.
By the way, in real Tibia you could also separate syllabes in first word, e.g. ex evo, ut ani, ad ori etc.
I managed to make the quotes work as it should, passing the parametters and strimming, using the Nostalrius formula:


C++:
TalkActionResult_t Spells::playerSaySpell(Player* player, SpeakClasses type, std::string& words)
{
    std::string str_words = words;

    //Disabled to make the quotes work as expected
    //trimString(str_words);

    std::ostringstream str_instantSpell;
    for (size_t i = 0; i < str_words.length(); i++) {...
I guess i should modify this part, but i'm not certain about what to do at all:
This code doesn't seem to be responsible for recognizing whether certain text is an incantation. You should probably look in getInstantSpell() or somewhere else. Here it only reads parameters.
By the way, in real Tibia you could also separate syllabes in first word, e.g. ex evo, ut ani, ad ori etc.
 
This code doesn't seem to be responsible for recognizing whether certain text is an incantation. You should probably look in getInstantSpell() or somewhere else. Here it only reads parameters.
By the way, in real Tibia you could also separate syllabes in first word, e.g. ex evo, ut ani, ad ori etc.
I managed to make the quotes work as it should, passing the parametters and strimming, using the Nostalrius formula:


C++:
TalkActionResult_t Spells::playerSaySpell(Player* player, SpeakClasses type, std::string& words)
{
    std::string str_words = words;

    //Disabled to make the quotes work as expected
    //trimString(str_words);

    std::ostringstream str_instantSpell;
    for (size_t i = 0; i < str_words.length(); i++) {
        if (!isspace(str_words[i]) || (i < str_words.length() - 1 && !isspace(str_words[i + 1]))) {
            str_instantSpell << str_words[i];
        }
    }
    
    str_words = str_instantSpell.str();

    InstantSpell* instantSpell = getInstantSpell(str_words);
    if (!instantSpell) {
        return TALKACTION_CONTINUE;
    }

    std::string param;

    if (instantSpell->getHasParam()) {
        size_t spellLen = instantSpell->getWords().length();
        size_t paramLen = str_words.length() - spellLen;
        std::string paramText = str_words.substr(spellLen, paramLen);
        if (!paramText.empty() && paramText.front() == ' ') {
            size_t loc1 = paramText.find('"', 1);
            if (loc1 != std::string::npos) {
                size_t loc2 = paramText.find('"', loc1 + 1);
                if (loc2 == std::string::npos) {
                    loc2 = paramText.length();
                } else if (paramText.find_last_not_of(' ') != loc2) {
                    return TALKACTION_CONTINUE;
                }

                param = paramText.substr(loc1 + 1, loc2 - loc1 - 1);
            } else {
                //Disabled to make the quotes work as expected
                //trimString(paramText);
                loc1 = paramText.find(' ', 0);
                if (loc1 == std::string::npos) {
                    param = paramText;
                } else {
                    return TALKACTION_CONTINUE;
                }
            }
        }
    }

    if (instantSpell->playerCastInstant(player, param)) {
        return TALKACTION_BREAK;
    }

    return TALKACTION_FAILED;
}

But yeah, i haven't managed to separate syllabes in first word yet.
Post automatically merged:

Btw, @kay did it worked only for single word spells or also for Exura Gran and so?
 
Last edited:
Solution
But yeah, i haven't managed to separate syllabes in first word yet.
Post automatically merged:

Btw, @kay did it worked only for single word spells or also for Exura Gran and so?

All spells. The first word of any incantation consists of two syllabes (ex, ad, al, ut ... + evo, ani, ana, ori, ura, iva, eta ... etc.) and you could type it with a space between them or without. E.g. both "ut evo lux" and "utevo lux" worked.
 
Back
Top