• 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++ Classic Spell Casting

LeOnArd0

Member
Joined
Jan 24, 2010
Messages
76
Reaction score
14
Hi guys,

I would like some help to place the spells as they used to.

Ex: eXuRa / Ex ura / eXura "Hello World

I use TFS 1.5 - Downgrade from Nekiro.

spells.cpp

Could someone give me a light?

Tks,
Leo
 
Now the spells will detect lowercase, uppercase and spaces in the spell usage

C++:
TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
{
std::string str_words = words;
//strip trailing spaces
trimString(str_words);

//transform the string in lowercase
std::transform(str_words.begin(), str_words.end(), str_words.begin(), ::tolower);

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 {
            trimString(paramText);
            loc1 = paramText.find(' ', 0);
            if (loc1 == std::string::npos) {
                param = paramText;
            } else {
                return TALKACTION_CONTINUE;
            }
        }
    }
}

if (instantSpell->playerCastInstant(player, param)) {
    words = instantSpell->getWords();

    if (instantSpell->getHasParam() && !param.empty()) {
        words += " \"" + param + "\"";
    }

    return TALKACTION_BREAK;
}

return TALKACTION_FAILED;
}
Post automatically merged:

@LeOnArd0 @Drucken
 
Now the spells will detect lowercase, uppercase and spaces in the spell usage

C++:
TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
{
std::string str_words = words;
//strip trailing spaces
trimString(str_words);

//transform the string in lowercase
std::transform(str_words.begin(), str_words.end(), str_words.begin(), ::tolower);

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 {
            trimString(paramText);
            loc1 = paramText.find(' ', 0);
            if (loc1 == std::string::npos) {
                param = paramText;
            } else {
                return TALKACTION_CONTINUE;
            }
        }
    }
}

if (instantSpell->playerCastInstant(player, param)) {
    words = instantSpell->getWords();

    if (instantSpell->getHasParam() && !param.empty()) {
        words += " \"" + param + "\"";
    }

    return TALKACTION_BREAK;
}

return TALKACTION_FAILED;
}
Post automatically merged:

@LeOnArd0 @Drucken


Thanks for the answer.

I tested it here, but it didn't work. It doesn't return errors on compilation, it just didn't make any changes to the game.

giphy.gif
 
I forgot that in TFS 1.5 you can't use it (it was awesome that in the old days you could do that 😪):
exura "LIFE IS GOOD

According to the upper and lower case letters, I managed to solve it, it is by changing this line:
In the function:
TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
Search this:
words = instantSpell->getWords();
Change to:
words = words;

The quotation marks are still missing...
exura "LIFE IS GOOD
 
because ur supposed to make spells work via talkaction. that is the whole trick. they allow for " and spaces then if u add separator.
try to make exura talkaction with separator=" "
 
@Idletibia you have given me an idea because of your comment...

I remembered that in TFS 1.X+ you can use the " " in utevo res and utevo res ina, so there was some parameter to identify the quotes.
Yes, there is a parameter to add in spells.xml that enables quotes and the parameter is:
params="1"

So the complete "exura" line would be:
<instant exhaustedGroup="healing" name="Light Healing" words="exura" level="8" mana="20" aggressive="0" params="1" selftarget="1" cooldown="1000" needlearn="0" script="healing/light_healing.lua">

But the parameter is being repeated twice o_O
If I set:
exura "LIFE

It is displayed as:
exura "LIFE""LIFE"
 
@Idletibia you have given me an idea because of your comment...

I remembered that in TFS 1.X+ you can use the " " in utevo res and utevo res ina, so there was some parameter to identify the quotes.
Yes, there is a parameter to add in spells.xml that enables quotes and the parameter is:
params="1"

So the complete "exura" line would be:
<instant exhaustedGroup="healing" name="Light Healing" words="exura" level="8" mana="20" aggressive="0" params="1" selftarget="1" cooldown="1000" needlearn="0" script="healing/light_healing.lua">

But the parameter is being repeated twice o_O
If I set:
exura "LIFE

It is displayed as:
exura "LIFE""LIFE"

I was able to resolve this by commenting out the line
LUA:
//words += " \"" + param + "\"";

The only thing now not being done is magic with space in between.

Ex: Ex Ura
 
Last edited:
go spells.cpp

search for:
C:
words = instantSpell->getWords();
replace with:
C:
words = words /*instantSpell->getWords()*/;


search for:
C:
if (instantSpell->getHasParam() && !param.empty()) {

commit looking like
C:
        /*if (instantSpell->getHasParam() && !param.empty()) {
            words += " \"" + param + "\"";
        }*/


go in tools.cpp
search for:
C:
void trimString(std::string& str)

after:
C:
str.erase(0, str.find_first_not_of(' '));
paste:
C:
str.erase(remove(str.begin(), str.begin() + 5, ' ') , str.begin() + 5); //mano368


ExUrA will work(and all others)
Ex Ura will work(and all others)
Utevo lux "mano368 will not work(we need this)
 
wooow i was looking for this too love u guys!

upup!
we need the last "fix"
Utevo lux "mano368 will not work(we need this)
 
Last edited:
Just make check that if words end with " re-read whats before it and cast spell associated with matching case apso check if exank hur up works with his newest change because instant spell commit with spell param makes me wonder if exiva wont work etc
 
Just make check that if words end with " re-read whats before it and cast spell associated with matching case apso check if exank hur up works with his newest change because instant spell commit with spell param makes me wonder if exiva wont work etc
nice idea, the problem is that I don't know about c program, what I can do is a try and repeat xd
 
Does exani hur up work with this if so jist add param to all spslls xml?
Yes, all spells that have parameters work.
No, you don't need to add parameter in all spells.

I didn't get to test, but I don't think adding parameter in all spells will make it work this way, it has to be in the code itself.
 
Yes, all spells that have parameters work.
No, you don't need to add parameter in all spells.

I didn't get to test, but I don't think adding parameter in all spells will make it work this way, it has to be in the code itself.
I didnt get to test blablablabla xD so don't talk other work with parameters meaning that all should if u add that just check someone because if spell has no parameter but its there im sure there is failsafe in the code to ignore it but might just make what u need work in the present code ;d
 
I didnt get to test blablablabla xD so don't talk other work with parameters meaning that all should if u add that just check someone because if spell has no parameter but its there im sure there is failsafe in the code to ignore it but might just make what u need work in the present code ;d
blablabla xd test done

so only need to add hasparams in all spells to get the last one trick

edit: seems we have problem using that in some spells, like exori vis and others
 
Last edited:
still closer to the whole thing im sure its just a part of code as i said so need to fix the param stuff

try your whole code without commenting that.

/*if (instantSpell->getHasParam() && !param.empty()) {
words += " \"" + param + "\"";
}*/

the && !param.empty()) is very important here :p (but i guess for exori vis etc it should work god knows about exiva though. the problem with the exori vis etc might be because needtarget once u put param it works like exiva so thats where the problem is but if it works for most spells and not like exori vis etc i think its already liveable feature. :) mostly people use it for exura and utanihur

worth mentioning yurots engines had it working like that im nearly 100% sure if not then ask the guy who made akademicki ots maybe he has solution he used to have that feature im sure
 
Last edited:
Back
Top