Hello Peoples,
Since I've seen this function requested a few times now, I thought to give it a shoot, after some testing it is fully working now.
If you encounter any kind of bugs with it, then feel free to post them here.
This function is limited same as in spells.xml
If the Player does not have the required vocation or anything, it'll not cast the spell.
quick example of usage:
Let's start...
Luascript.cpp:
after:
add this:
after:
add this:
Luascript.h
after:
add this:
kind regards, Evil Hero.
Since I've seen this function requested a few times now, I thought to give it a shoot, after some testing it is fully working now.
If you encounter any kind of bugs with it, then feel free to post them here.
This function is limited same as in spells.xml
If the Player does not have the required vocation or anything, it'll not cast the spell.
quick example of usage:
Lua:
doPlayerCastSpell(cid, "exevo gran mas vis")
Let's start...
Luascript.cpp:
after:
Code:
//getCreatureHealth(cid)
lua_register(m_luaState, "getCreatureHealth", LuaInterface::luaGetCreatureHealth);
add this:
Code:
//doPlayerCastSpell(cid, spell)
lua_register(m_luaState, "doPlayerCastSpell", LuaInterface::luaDoPlayerCastSpell);
after:
Code:
int32_t LuaInterface::luaGetPlayerSex(lua_State* L)
{
//getPlayerSex(cid[, full = false])
bool full = false;
if(lua_gettop(L) > 1)
full = popNumber(L);
ScriptEnviroment* env = getEnv();
Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
if(!player)
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
else
lua_pushnumber(L, player->getSex(full));
return 1;
}
add this:
Code:
int32_t LuaInterface::luaDoPlayerCastSpell(lua_State* L)
{
//doPlayerCastSpell(cid, spell)
std::string spell = popString(L);
ScriptEnviroment* env = getEnv();
Player* player = env->getPlayerByUID(popNumber(L));
if(!player)
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
ReturnValue ret = RET_NOERROR;
ret = g_spells->onPlayerSay(player, spell);
if(ret == RET_NOERROR || (ret == RET_NEEDEXCHANGE && !g_config.getBool(ConfigManager::BUFFER_SPELL_FAILURE)))
return true;
lua_pushboolean(L, true);
return 1;
}
Luascript.h
after:
Code:
static int32_t luaDoRemoveItem(lua_State* L);
add this:
Code:
static int32_t luaDoPlayerCastSpell(lua_State* L);
kind regards, Evil Hero.