onCastSpell
.const std::string& words
argument.getWords()
so bool result = internalCastSpell(player, var, getWords());
bool InstantSpell::internalCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
return...
You ever coded before?Like commands with talk actions !addskill etc, if parameter 1 == xyz
Do you mean..?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]
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 likeDo you mean..?
Lua:function onCastSpell(creature, variant) print(variant.string) return true end
function onCastSpell(creature, variant)
if words == "exori" then -- words = spellname
-- do stuff
return true
end
This is pretty much what I said, and guy was rude.Do you mean..?
Lua:function onCastSpell(creature, variant) print(variant.string) return true end
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.You ever coded before?
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).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.
if
but then this if
would be true all the time because how do you execute it without these exact words lol.But these are spell parameters, not spell words (exura, exori, utani hur, utevo lux etc.) which you use to cast a spell.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.
This is pretty much what I mean. If variant.string includes both the spell words and param/target/pos, ect.Do you mean..?
Lua:function onCastSpell(creature, variant) print(variant.string) return true end
nailed itIt'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 intoif
but then thisif
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 .
onCastSpell
.const std::string& words
argument.getWords()
so bool result = internalCastSpell(player, var, getWords());
bool InstantSpell::internalCastSpell(Creature* creature, const LuaVariant& var, const std::string& words)
{
return executeCastSpell(creature, var, words);
}
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.I'll just throw 5 more cents here then.
You can easily add new argument toonCastSpell
.
Add hereconst std::string& words
argument.
Also hereforgottenserver/src/spells.h at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
forgottenserver/src/spells.h at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
Here usegetWords()
sobool result = internalCastSpell(player, var, getWords());
forgottenserver/src/spells.cpp at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
Replace this
withforgottenserver/src/spells.cpp at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
C++:bool InstantSpell::internalCastSpell(Creature* creature, const LuaVariant& var, const std::string& words) { return executeCastSpell(creature, var, words); }
Replace this
withforgottenserver/src/spells.cpp at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
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); }