• 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++ TFS 1.3 docastspell help to fix my code

epaminombas

New Member
Joined
Apr 23, 2009
Messages
17
Reaction score
0
TFS 1.3

This code works but ignore parameters of spells.xml spent mana, cooldown, range and all another parameters.
I need this code follow spells.xml parameters.

I try make items with shorcut for cast spells

Lua Script
Lua:
function onUse(player, words, param)
        player:doCastSpell("Light Healing")
end

C++ Code
C++:
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;
}
 
Back
Top