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

TFS 1.X+ TFS 1.4 spells question

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,307
Solutions
68
Reaction score
982
Is it possible to get the spell words in the xml file from the lua file of the spell?

.xml
XML:
words = "exori"

.lua
Lua:
function onCastSpell(c, v)
if spellWords = "exori" then
....
end
end
[code]
 
Solution
I'll just throw 5 more cents here then.
You can easily add new argument to onCastSpell.

Add here const std::string& words argument.
Also here

Here use getWords() so bool result = internalCastSpell(player, var, getWords());

Replace this
with
C++:
bool InstantSpell::internalCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
    return...
Is it possible to get the spell words in the xml file from the lua file of the spell?

.xml
XML:
words = "exori"

.lua
Lua:
function onCastSpell(c, v)
if spellWords = "exori" then
....
end
end
[code]
Do you mean..?
Lua:
function onCastSpell(creature, variant)
    print(variant.string)
    return true
end
 
Do you mean..?
Lua:
function onCastSpell(creature, variant)
    print(variant.string)
    return true
end
Im kinda confused too but I think he want to avoid using xml and using it like

Lua:
function onCastSpell(creature, variant)
if words == "exori" then -- words = spellname
-- do stuff
    return true
end

but why does he not use revscripts in that case then
( correct me if im wrong tutorial )
 
This is the only other viable alternative I can think of.

Parse through the spell list and generate a table using this

and then put that into a lib file to be referenced as a global table
 
Do you mean..?
Lua:
function onCastSpell(creature, variant)
    print(variant.string)
    return true
end
This is pretty much what I said, and guy was rude.
Post automatically merged:

You ever coded before?
I already coded what you’re trying to, using the method I described. It was very late after a 12 hour work shift, obviously I didn’t mean position with xyz, just meant whatever spell you want.
 
Last edited:
This is pretty much what I said, and guy was rude.
Post automatically merged:


I already coded what you’re trying to, using the method I described. It was very late after a 12 hour work shift, obviously I didn’t mean position with xyz, just meant whatever spell you want.
It's not even close to what OP needs tho. Variant String is used only if spell has arguments, like exura sio "Oen" (variant:getString() would return Oen).

I don't really know why would you need to get that data from .xml, each spell has its own script so just by opening that script you should know what words are associated with that spell. Just hardcode it into if but then this if would be true all the time because how do you execute it without these exact words lol.
If however you are using one script file for multiple spells (for whatever reason), then you have to rethink why you did that 🤪.
 
Exura sio parameter1
Print parameter1
Would return whatever you say after exura sio, same as I said above with talk actions. !addskill involves 4 parameters including string name, which I referenced so he could have some copy/paste code.
 
Exura sio parameter1
Print parameter1
Would return whatever you say after exura sio, same as I said above with talk actions. !addskill involves 4 parameters including string name, which I referenced so he could have some copy/paste code.
But these are spell parameters, not spell words (exura, exori, utani hur, utevo lux etc.) which you use to cast a spell.
 
Do you mean..?
Lua:
function onCastSpell(creature, variant)
    print(variant.string)
    return true
end
This is pretty much what I mean. If variant.string includes both the spell words and param/target/pos, ect.

Spells are set up so they have more than 1 ranking (WoW style). I ended up not needing to do what I was looking for here.

What I was wanting was to be able to get the spell words (from the xml file) in the lua file. I created a new spell system based in lua and I needed to get the spells words from the xml file so I could see if the player has access to the spell.

As I said I no longer need this. Thanks for anyone that tried to understand what I needed and help.

More than 1 spell was linked to the same file to minimize how many files needed to be made. They all did the same thing so it was best to try and get spell words from the xml. Hard to explain but it doesn't matter anymore.
Post automatically merged:

It's not even close to what OP needs tho. Variant String is used only if spell has arguments, like exura sio "Oen" (variant:getString() would return Oen).

I don't really know why would you need to get that data from .xml, each spell has its own script so just by opening that script you should know what words are associated with that spell. Just hardcode it into if but then this if would be true all the time because how do you execute it without these exact words lol.
If however you are using one script file for multiple spells (for whatever reason), then you have to rethink why you did that 🤪.
nailed it
 
Last edited:
I'll just throw 5 more cents here then.
You can easily add new argument to onCastSpell.

Add here const std::string& words argument.
Also here

Here use getWords() so bool result = internalCastSpell(player, var, getWords());

Replace this
with
C++:
bool InstantSpell::internalCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
    return executeCastSpell(creature, var, words);
}

Replace this
with
C++:
bool InstantSpell::executeCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
    //onCastSpell(creature, var, words)
    if (!scriptInterface->reserveScriptEnv()) {
        std::cout << "[Error - InstantSpell::executeCastSpell] Call stack overflow" << std::endl;
        return false;
    }

    ScriptEnvironment* env = scriptInterface->getScriptEnv();
    env->setScriptId(scriptId, scriptInterface);

    lua_State* L = scriptInterface->getLuaState();

    scriptInterface->pushFunction(scriptId);

    LuaScriptInterface::pushUserdata<Creature>(L, creature);
    LuaScriptInterface::setCreatureMetatable(L, -1, creature);

    LuaScriptInterface::pushVariant(L, var);
   
    LuaScriptInterface::pushString(L, words);

    return scriptInterface->callFunction(3);
}
 
Solution
I'll just throw 5 more cents here then.
You can easily add new argument to onCastSpell.

Add here const std::string& words argument.
Also here

Here use getWords() so bool result = internalCastSpell(player, var, getWords());

Replace this
with
C++:
bool InstantSpell::internalCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
    return executeCastSpell(creature, var, words);
}

Replace this
with
C++:
bool InstantSpell::executeCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
    //onCastSpell(creature, var, words)
    if (!scriptInterface->reserveScriptEnv()) {
        std::cout << "[Error - InstantSpell::executeCastSpell] Call stack overflow" << std::endl;
        return false;
    }

    ScriptEnvironment* env = scriptInterface->getScriptEnv();
    env->setScriptId(scriptId, scriptInterface);

    lua_State* L = scriptInterface->getLuaState();

    scriptInterface->pushFunction(scriptId);

    LuaScriptInterface::pushUserdata<Creature>(L, creature);
    LuaScriptInterface::setCreatureMetatable(L, -1, creature);

    LuaScriptInterface::pushVariant(L, var);
  
    LuaScriptInterface::pushString(L, words);

    return scriptInterface->callFunction(3);
}
Appreciate it but its really not needed anymore. Thank you.
 
Back
Top