What's new

[Konkurs] Funkcja getPlayersOnlineCount()

Status
Not open for further replies.

Dantez

Moim sekretem jest ciasto
Joined
May 22, 2008
Messages
1,206
Reaction score
202
Odp: [Konkurs] Funkcja getPlayersOnlineCount()

A dla normalnych:

getWorldCreatures(type)
//type = 0 players, 1 monsters, 2 npcs, 3 all
 

Placek

Blue Waffle
Joined
Sep 30, 2008
Messages
6,793
Reaction score
672
Age
9
data\lib\050-function.lua na poczatku:

PHP:
function getPlayersOnlineCount()
local config = {
	showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}
	local players = getPlayersOnline()
	local strings = {""}
	local i, position = 1, 1
	local added = false
	for _, pid in ipairs(players) do
		if(added) then
			if(i > (position * 7)) then
				strings[position] = strings[position] .. ","
				position = position + 1
				strings[position] = ""
			else
				strings[position] = i == 1 and "" or strings[position] .. ", "
			end
		end

		if((config.showGamemasters or getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES) or not getPlayerCustomFlagValue(pid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) and (not isPlayerGhost(pid) or getPlayerGhostAccess(cid) >= getPlayerGhostAccess(pid))) then
			strings[position] = strings[position] .. getCreatureName(pid) .. " [" .. getPlayerLevel(pid) .. "]"
			i = i + 1
			added = true
		else
			added = false
		end
	end
return (i - 1)
end
(Nie jest moze za specjalnie profesjonalna i mozna by stad wywalic niepotrzebne rzeczy, ale dziala i to jest najwazniejsze.)
Przykladowe wykorzystanie funkcji jest bardzo proste. Jesli na serwerze masz event np loterie i chcesz aby losowanie odbywalo sie tylko kiedy liczba graczy online jest powyzej 50, dajesz taki warunek:
PHP:
if getPlayersOnlineCount() >= 50 then
W ten sposob loteria bedzie sie odbywac tylko jesli na serwerze beda aktywni gracze :)



Zabraniam kopiowania zawarto?ci na inne fora/serwisy.

Notka moderatorska:
+10 pkt do konkursu!
 
Status
Not open for further replies.
Top