KylerXX
Active Member
- Joined
- Jun 24, 2010
- Messages
- 439
- Reaction score
- 30
getMonstersOnline()
luascript.cpp
Search:
And under you add:
Now search:
And under you add:
luascript.h
Search:
Under write:
Test script that I was used:
luascript.cpp
Search:
Lua:
int32_t LuaScriptInterface::luaGetPlayersOnline(lua_State* L)
{
//getPlayersOnline()
ScriptEnviroment* env = getEnv();
AutoList<Player>::iterator it = Player::autoList.begin();
lua_newtable(L);
for(int32_t i = 1; it != Player::autoList.end(); ++it, ++i)
{
lua_pushnumber(L, i);
lua_pushnumber(L, env->addThing(it->second));
pushTable(L);
}
return 1;
}
And under you add:
Lua:
int32_t LuaScriptInterface::luaGetMonstersOnline(lua_State* L)
{
//getMonstersOnline()
ScriptEnviroment* env = getEnv();
AutoList<Monster>::iterator it = Monster::autoList.begin();
lua_newtable(L);
for(int32_t i = 1; it != Monster::autoList.end(); ++it, ++i)
{
lua_pushnumber(L, i);
lua_pushnumber(L, env->addThing(it->second));
pushTable(L);
}
return 1;
}
Now search:
Lua:
//getPlayersOnline()
lua_register(m_luaState, "getPlayersOnline", LuaScriptInterface::luaGetPlayersOnline);
And under you add:
Lua:
//getMonstersOnline()
lua_register(m_luaState, "getMonstersOnline", LuaScriptInterface::luaGetMonstersOnline);
luascript.h
Search:
Lua:
static int32_t luaGetPlayersOnline(lua_State* L);
Under write:
Lua:
static int32_t luaGetMonstersOnline(lua_State* L);
Test script that I was used:
Lua:
function onSay(cid, words, param, channel)
local m = getMonstersOnline()
if(not m) then
return doPlayerSendCancel(cid, "No are monsters")
end
for _, mid in ipairs(m) do
local mpos = getThingPos(mid)
doSendAnimatedText(mpos, 'WORK', 255)
end
return 0
end