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

Code:
int32_t LuaScriptInterface::luaDoCreatureSetLookDir(lua_State* L)
{
	//doCreatureSetLookDir(cid, dir)
	Direction dir = (Direction)popNumber(L);

	ScriptEnviroment* env = getScriptEnv();
	if(Creature* creature = env->getCreatureByUID(popNumber(L)))
	{
		if(dir < NORTH || dir > WEST)
		{
			std::stringstream ss;
			ss << dir;
			reportErrorFunc("Invalid direction " + ss.str());
			lua_pushboolean(L, LUA_ERROR);
			return 1;
		}

		g_game.internalCreatureTurn(creature, dir);
		if(Player* player = creature->getPlayer())
			player->resetIdleTime();

		lua_pushboolean(L, LUA_NO_ERROR);
	}
	else
	{
		reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
		lua_pushboolean(L, LUA_ERROR);
	}
	return 1;
}
 
Lua:
NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
SOUTHWEST = 4
SOUTHEAST = 5
NORTHWEST = 6
NORTHEAST = 7

So if a players stays front of a door with the lookDir on the door, you can simply do
Lua:
doCreatureSetLookDir(cid, SOUTH)
He will now look south, lookDir south.
 
Code:
int32_t LuaScriptInterface::luaDoCreatureSetLookDir(lua_State* L)
{
	//doCreatureSetLookDir(cid, dir)
	Direction dir = (Direction)popNumber(L);

	ScriptEnviroment* env = getScriptEnv();
	if(Creature* creature = env->getCreatureByUID(popNumber(L)))
	{
		if(dir < NORTH || dir > WEST)
		{
			std::stringstream ss;
			ss << dir;
			reportErrorFunc("Invalid direction " + ss.str());
			lua_pushboolean(L, LUA_ERROR);
			return 1;
		}

		g_game.internalCreatureTurn(creature, dir);
		if(Player* player = creature->getPlayer())
			player->resetIdleTime();

		lua_pushboolean(L, LUA_NO_ERROR);
	}
	else
	{
		reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
		lua_pushboolean(L, LUA_ERROR);
	}
	return 1;
}


Thanks. This is Luascript.cpp? Do I add anything in Luascript.h?
 
Thanks. This is Luascript.cpp? Do I add anything in Luascript.h?

You always add something to luascript.h when adding new function.
This goes to luascript.cpp also:
Code:
        //doCreatureSetLookDir(cid, dir)
	lua_register(m_luaState, "doCreatureSetLookDirection", LuaScriptInterface::luaDoCreatureSetLookDir);

luascript.h
Code:
static int32_t luaDoCreatureSetLookDir(lua_State* L);
 
Back
Top