O codigo funciona só que não respeita os parametros do spells.xml como uso de mana, range, cooldown e etc.
Preciso que determinados itens sejam atalhos para o uso das magias e que sejam como se fosse o proprio player falar a magia.
Lua Script
-
-
function onUse(player, words, param)
-
player:doCastSpell("Light Healing")
-
end
-
C++ Code
-
-
int LuaScriptInterface::luaDoCastSpell(lua_State* L)
-
{
-
//creature: doCastSpell("spellName")
-
Creature* creature = getUserdata<Creature>(L, 1);
-
if(!creature) {
-
lua_pushboolean(L, false);
-
return 1;
-
}
-
-
const std::string& spellName = getString(L, 2);
-
InstantSpell* spell = g_spells->getInstantSpellByName(spellName);
-
if(!spell) {
-
lua_pushboolean(L, false);
-
return 1;
-
}
-
-
Creature* target = creature->getAttackedCreature();
-
if(target)
-
spell->castSpell(creature, target);
-
else
-
spell->castSpell(creature, creature);
-
-
lua_pushboolean(L, true);
-
-
return 1;
-
}
-