• 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
 
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
old strike spell doesnt use needtarget, only needdirection

if its only for spells that use in yourself, using hasParams do the job.

I dont remember if they use in all spells but, for light, haste and others spells that buff or heal yourself this work well

with spell:isSelfTarget(true) and spell:hasParams(true) this work

but, doing that in c# is better

thanks for the help
 
Last edited:
no problem :) as i said u can use talkactions they do not care but then u have to rewrite every spell into talkaction module without any c++ changes. im pretty sure. and adding manadrain and stuff can be exhausting (stupid but works )
 
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)
If i write ex: eX u r A is not working
UTANI GRAN HUR not working either

Can somebody give a fix pls?
 
If i write ex: eX u r A is not working
UTANI GRAN HUR not working either

Can somebody give a fix pls?
that exura is even possible in past days? I only changed to the first five letters because the first word always have 5 letter(dam).

exura (5 letters) = ex ura, ex u ra, e xura, ex u ra << all work

UTANI GRAN HUR, ut ani gran hur, u tani gran hur.. and so

after made these changes, have u compiled again?
 
that exura is even possible in past days? I only changed to the first five letters because the first word always have 5 letter(dam).

exura (5 letters) = ex ura, ex u ra, e xura, ex u ra << all work

UTANI GRAN HUR, ut ani gran hur, u tani gran hur.. and so

after made these changes, have u compiled again?
Yes all these works, ex ura, ex u ra, e xura, ex u ra << all work
eX u r A <<< no work
Exu Ra << works
in some cases is not working. I don't get the reason because of it.
should it work right? eX u r A <<< no work
I don't have a cipsoft server 7.7 to test this, sadly
Yes i have compiled after the changes
I have used these code changes:
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)
 
dont we reall just need to compare what player says everytime? could we not use onSay instead and bring tolower + remove spaces and search for string "spell words" ? and then just make player say the text he says anyways + castspell? why even c++

just tought about it.
Lua:
local spellTable = {
  ["exura"] = "Light Healing",
  ["exura gran"] = "Intense Healing",
  ["exura vita"] = "Ultimate Healing",
  -- add more spell keywords and corresponding spell names here
}

function onSay(player, words, param)
  local message = string.lower(words)

  for spellKeyword, spellName in pairs(spellTable) do
    if string.find(message, spellKeyword) then
      player:getCastSpell():execute(spellName)
      return true
    end
  end

  return false
end
 
Last edited:
UP I've solved the problem @mano368
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)
OK I've solved the issue related with using quotes, change the code to this

Lua:
InstantSpell* Spells::getInstantSpell(const std::string& words)
{
    InstantSpell* result = nullptr;

    for (auto& it : instants) {
        const std::string& instantSpellWords = it.second.getWords();
        size_t spellLen = instantSpellWords.length();
        if (caseInsensitiveStartsWith(words, instantSpellWords)) {
            if (!result || spellLen > result->getWords().size()) {
                result = &it.second;
                if (words.length() == spellLen) {
                    break;
                }
            }
        }
    }

    //if (result) {
        //const std::string& resultWords = result->getWords();
        //if (words.length() > resultWords.length()) {
    //if (!result->getHasParam()) {
                //return nullptr;
            //}
    if (result && words.length() > result->getWords().length())
    {
        std::string param = words.substr(result->getWords().length(), words.length());
        if (param[0] != ' ' || (param.length() > 1 && (!result->getHasParam() || param.find(' ', 1) != std::string::npos) && param[1] != '"'))
            return NULL;
    }

   
   
        return result;
    }

the only problem is that if i use exani hur up (without quotes)this crashing the server. This does not happens if i use exani hur down ( weird this huh?)
also exani hur " up/down with quotes works properly
spells like utevo res ina rat crashes the server too
is there a way to add param monstername and up? jaaj :/
@mano368
 

Attachments

Last edited:
up! a solution for fix the crash?. everything is working except for exani hur up and utevo res ina, without quotes
these spells are crashing the server is they are used without quotes

BUMP
 
dont we reall just need to compare what player says everytime? could we not use onSay instead and bring tolower + remove spaces and search for string "spell words" ? and then just make player say the text he says anyways + castspell? why even c++

just tought about it.
Lua:
local spellTable = {
  ["exura"] = "Light Healing",
  ["exura gran"] = "Intense Healing",
  ["exura vita"] = "Ultimate Healing",
  -- add more spell keywords and corresponding spell names here
}

function onSay(player, words, param)
  local message = string.lower(words)

  for spellKeyword, spellName in pairs(spellTable) do
    if string.find(message, spellKeyword) then
      player:getCastSpell():execute(spellName)
      return true
    end
  end

  return false
end
how to use this? could you elaborate a bit please' since i know that for use a talkaction we need to execute a command like !spells or similar
 
oK I HAVE CHANGED THE CODE A LOT
Lua:
TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
{
    std::string str_words = words;

    //strip trailing spaces
    trimString(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());
            }

            trimString(str_words);
        }
    }

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

ExUrA will work(and all others)
Ex Ura will work(and all others)
Utevo lux "ola work
Utevo Lux "ola work

SOLVED exani hur up and other not crashing server anymore

 
Last edited:
Back
Top