• 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 Function getMonstersOnline()

KylerXX

Active Member
Joined
Jun 24, 2010
Messages
439
Reaction score
30
getMonstersOnline()
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
 
PHP:
function onSay(cid, words, param)
local mo = getMonstersOnline()
for _,mid in ipairs(mo) do
 doRemoveCreature(mid, true)
end
doBroadcastMessage("F**K YOU PLAYERS! NO MONSTERS FOR YOU!\n"..#mo.." monsters has been kicked!")
return TRUE
end
some example of use it ^^
 
PHP:
function onSay(cid, words, param)
local mo = getMonstersOnline()
for _,mid in ipairs(mo) do
 doRemoveCreature(mid, true)
end
doBroadcastMessage("F**K YOU PLAYERS! NO MONSTERS FOR YOU!\n"..#mo.." monsters has been kicked!")
return TRUE
end
some example of use it ^^

hahaha nice ^_^
 
Back
Top