• 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 [C++] doCreatureCastSpell

Cezinha

New Member
Joined
May 15, 2010
Messages
14
Reaction score
0
Hello guys, I did a function in my source called "doCreatureCastSpell (uid, spell)" so that ta give an error:
Code:
In static member function `static int32_t LuaScriptInterface::luaDoCreatureCastSpell(lua_State*)': 

 expected primary-expression before ',' token

And giving this error in this part:
Code:
 ret = g_spells->getInstantSpellByName(spell)->castSpell(Creature, spell);

This is the function code:
Code:
int32_t LuaScriptInterface::luaDoCreatureCastSpell(lua_State* L)
{
        //doCreatureCastSpell(uid, spell)
        std::string spell = popString(L);

        ScriptEnviroment* env = getEnv();
        Creature* creature = env->getCreatureByUID(popNumber(L));
        if(!creature)
        {
                errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
                lua_pushboolean(L, false);
                return 1;
        }
        
        ReturnValue ret = RET_NOERROR;
        ret = g_spells->getInstantSpellByName(spell)->castSpell(Creature, spell);
        if(ret == RET_NOERROR || (ret == RET_NEEDEXCHANGE && !g_config.getBool(ConfigManager::BUFFER_SPELL_FAILURE)))
            return true;

        lua_pushboolean(L, true);
        return 1;
}

Someone here could tell me how to fix this error?

Awaiting response
 
If I for lowercase the word "creature" of this error:

Code:
In static member function `static int32_t LuaScriptInterface: luaDoCreatureCastSpell (lua_State *) ':
 
 candidates are: virtual bool InstantSpell::castSpell(Creature*)

virtual bool InstantSpell::castSpell(Creature*, Creature*)
 
Now I put like this:
Code:
ret = g_spells-> getInstantSpellByName (spell) -> CastSpell (creature);

And this showing this error:
Code:
Can not convert `bool 'to' ReturnValue 'in assignment
 
The error happens at line 2852, which is this one:
Code:
ret = g_spells-> getInstantSpellByName (spell) -> CastSpell (creature);

This is the part where she put it:
Code:
ReturnValue ret = RET_NOERROR;
ret = g_spells-> getInstantSpellByName (spell) -> CastSpell (creature);
if (ret == RET_NOERROR | | (ret == RET_NEEDEXCHANGE & &! g_config.getBool (ConfigManager: BUFFER_SPELL_FAILURE)))
return true;
 
Last edited:
Sorry I missed the line there, most already edited the post to the correct line.

The error happens at line 2852, which is this one:
Code:
ret = g_spells-> getInstantSpellByName (spell) -> CastSpell (creature);

This is the part where she put it:
Code:
ReturnValue ret = RET_NOERROR;
ret = g_spells-> getInstantSpellByName (spell) -> CastSpell (creature);
if (ret == RET_NOERROR | | (ret == RET_NEEDEXCHANGE & &! g_config.getBool (ConfigManager: BUFFER_SPELL_FAILURE)))
return true;
 
Last edited:
Try something like this:

Code:
if(g_spells->getInstantSpellByName(spell)->CastSpell(creature))
	return true;
else
	return false;


kind regards, Evil Hero.
 
I thought I achieved, I did so far:
Code:
int32_t LuaScriptInterface::luaDoCreatureCastSpell(lua_State* L)
{
        //doCreatureCastSpell(uid, spell)
        std::string spell = popString(L);

        ScriptEnviroment* env = getEnv();
        Creature* creature = env->getCreatureByUID(popNumber(L));
        if(!creature)
        {
                errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
                lua_pushboolean(L, false);
                return 1;
        }
        
        if(g_spells->getInstantSpellByName(spell)->castSpell(creature))
        {
            lua_pushboolean(L, true);
            return 1;
        }

        lua_pushboolean(L, false);
        return 1;
}

More then when I use the function of the server crash and it is closed.
 
Last edited:
In your code is:
PHP:
if (g_spells-> getInstantSpellByName (spell) -> CastSpell (creature))
and in spells.cpp is no function CastSpell, there is castSpell, but it should not let you compile luascript.cpp, not crash server :mad:

EDIT:
and everywhere in TFS is something like:
PHP:
std::string spell = popString (L);
not:
PHP:
std:: string = spell popString (L);
but I'm not C++ programmer and maybe your version work too.

EDIT 2:
I know why it crash. It's because you try to use spell that doesn't exist or not loaded.
I think it should be:
PHP:
int32_t LuaScriptInterface: luaDoCreatureCastSpell (lua_State * L)
{
	//DoCreatureCastSpell (uid, spell)
	std::string spell_name = popString(L);

	* Env = getenv ScriptEnviroment ();
	Creature * creature = env-> getCreatureByUID (popNumber (L));
	if (! creature)
	{
		errorEx (getError (LUA_ERROR_CREATURE_NOT_FOUND));
		lua_pushboolean (L, false);
		return 1;
	}

	Spell* spell = NULL;
	if (spell = g_spells-> getInstantSpellByName (spell_name))
	{
		if (spell-> castSpell(creature))
		{
			lua_pushboolean (L, true);
			return 1;
		}
	}
	lua_pushboolean (L, false);
	return 1;
}
 
Last edited:
PhoOwned, your version compiled smoothly, and has not crash the server, no more nothing happens when I use the function.

Error does not appear, nor cast a spell
 
Back
Top