Grehy
Killroy
A simple script, when you log on and if access > 2, open these channels; x, x, x, etc
Last edited:
data\XML\channels.xml
logged="yes" access="2"
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;
}
onlogin
if access > 2 then
doPlayerOpenChannel(cid, channelId)
end
yes, as long as channelId is a valid channel.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 ?
function onLogin(cid)
if getPlayerGroupId(cid) > 2 then
doPlayerOpenChannel(cid, CHANNEL_HELP)
end
return true
end
../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
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;
}
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;
}
Execution terminated
Compilation successful