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

Lua Function doPlayerCastSpell(cid, spell)

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,254
Solutions
27
Reaction score
721
Location
Germany
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:
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.
 
thats really cool, but does it check for exhaustion between other spells? (i.e, if a char says a spell then does the action to make a script go off.. will it cancel from exhaustion?) I looked at the code and it doesn't seem like it does.
 
Yes, it's basicly the same as if you cast the spell via it's name.
 
Try replacing getPlayerByUID with getCreatureByUID.

Wont work.
onPlayerSay(Player* player, const std::string& words);

inside that method are also few functions with Player* in args.

Ive made onCreatureSay for spells but need lot of source edit, but you can also cast spell by
Code:
g_spells->getInstantSpellByName(spellName)->castSpell(creature, creature->getAttackedCreature)
 
Wont work.
onPlayerSay(Player* player, const std::string& words);

inside that method are also few functions with Player* in args.

Ive made onCreatureSay for spells but need lot of source edit, but you can also cast spell by
Code:
g_spells->getInstantSpellByName(spellName)->castSpell(creature, creature->getAttackedCreature)

It was just fast thought :p
 
also additional param checkExhaust would be awesome(you sometimes need to use it even when char is exhausted I think), but it would need other way of casting spell, not emulating onSay

and its based on 0.4 if I'm not wrong right?(LuaInterface ^^)
 
zomg GREAT, tfs developers maybe transform it into doCreatureCastSpell, with some useful params! :D Repped Evil Hero :)
And Mock! If you really wanna make isSpell function xD make it not only checks spell words('Exura') but also spell name ('Light Healing').
 
is as per this system to summon the magic drop?

From my understanding, it's basically just making the player say something. If it happens to be a spell, all normal rules apply just as if the player had said it manually.
 
@up
no, it's basically make player cast an spell, if the words arent the name of an spell it will do nothing, and if they are, it will cast the spell
 
@up
no, it's basically make player cast an spell

Broken English... Anyways, yes, it's 'basically' unfiltered so it will return true immediately if the text doesn't correspond to a registered spell string. So then the play won't say or emote the spell when it's cast through this function, right?
 
could someone edit this function for it to be sent by the creature??
maybe a doCreatureCastSpell (cid, spell)

I am a long time ago that, tenhu almost certain that there are enough people who are also

Thanks already
 
Back
Top