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

[REQUEST] Open GM channels onLogin

Grehy

Killroy
Joined
Nov 21, 2008
Messages
2,631
Reaction score
33
Location
United States
A simple script, when you log on and if access > 2, open these channels; x, x, x, etc
 
Last edited:
Have you added this into your luascript.cpp?
Code:
int32_t LuaScriptInterface::luaDoPlayerOpenChannel(lua_State* L)
{
	//doPlayerOpenChannel(cid, channelId)
	uint32_t channelId = popNumber(L);
	uint32_t cid = popNumber(L);
	
	ScriptEnviroment* env = getScriptEnv();
	Player* player = env->getPlayerByUID(cid);
	if(player)
		lua_pushnumber(L, g_game.playerOpenChannel(cid, channelId) ? true : false);
	else
	{
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushnumber(L, false);
	}
	return 1;
}
 
I will, I was asking how to use the function in my lua script

Lua:
 onlogin 
if access > 2 then
      doPlayerOpenChannel(cid, channelId) 
end

Would that be right ?
 
I will, I was asking how to use the function in my lua script

Lua:
 onlogin 
if access > 2 then
      doPlayerOpenChannel(cid, channelId) 
end

Would that be right ?
yes, as long as channelId is a valid channel.
Code:
function onLogin(cid)
	if getPlayerGroupId(cid) > 2 then
		doPlayerOpenChannel(cid, CHANNEL_HELP)
	end
	return true
end
 
Sorry for double post, I'm home and tried to compile, this is the error I get;

../luascript.cpp:8481: error: expected initializer before "int32_t"

../luascript.cpp:8499: error: expected unqualified-id before '{' token

make.exe: *** [../luascript.o] Error 1

Execution terminated

This the section that the error is in, did I add everything correctly?

Code:
int32_t LuaScriptInterface::luaGetChannelUsers(lua_State* L)
int32_t LuaScriptInterface::luaDoPlayerOpenChannel(lua_State* L)
{
	//doPlayerOpenChannel(cid, channelId)
	uint32_t channelId = popNumber(L);
	uint32_t cid = popNumber(L);
	
	ScriptEnviroment* env = getScriptEnv();
	Player* player = env->getPlayerByUID(cid);
	if(player)
		lua_pushnumber(L, g_game.playerOpenChannel(cid, channelId) ? true : false);
	else
	{
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushnumber(L, false);
	}
	return 1;
}

Note: I just added that function, not anything else from that thread
 
you dont add it right below that line, you skip down and insert it right after that function ends.
Code:
int32_t LuaInterface::luaGetChannelUsers(lua_State* L)
{
	//getChannelUsers(channelId)
	ScriptEnviroment* env = getEnv();
	uint16_t channelId = popNumber(L);

	if(ChatChannel* channel = g_chat.getChannelById(channelId))
	{
		UsersMap usersMap = channel->getUsers();
		UsersMap::iterator it = usersMap.begin();

		lua_newtable(L);
		for(int32_t i = 1; it != usersMap.end(); ++it, ++i)
		{
			lua_pushnumber(L, i);
			lua_pushnumber(L, env->addThing(it->second));
			pushTable(L);
		}
	}
	else
		lua_pushboolean(L, false);

	return 1;
}

int32_t LuaInterface::luaDoPlayerOpenChannel(lua_State* L)
{
	//doPlayerOpenChannel(cid, channelId)
	uint32_t channelId = popNumber(L);
	uint32_t cid = popNumber(L);
	
	ScriptEnviroment* env = getEnv();
	Player* player = env->getPlayerByUID(cid);
	if(player)
		lua_pushnumber(L, g_game.playerOpenChannel(cid, channelId) ? true : false);
	else
	{
		errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
		lua_pushnumber(L, false);
	}
	return 1;
}

are both the getchannelusers and openchannel functions for example...please note that this is modified for 0.4dev. note that int32_t LuaScriptInterface the bolded part is taken out, along with other minor details. Just compile to see the errors, they are very easy to fix if you look
 
Back
Top