• 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 An Online command remake

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,855
Solutions
18
Reaction score
671
Hello.
I want a little remake to my !online command script:
LUA:
local STORE_VALUE = 3567 -- Value where exhaust is saved.
local EXHAUST_TIME = 60 -- Exhaust time in seconds.

-----------------------------------------------
---- Skrypt Online, edytowany przez Vojtaz ----
-----------------------------------------------

local config = {
	showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}

function onSay(cid, words, param, channel)
if exhaust(cid, STORE_VALUE, EXHAUST_TIME) > 0 then
	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) .. ""
			i = i + 1
			added = true
		else
			added = false
		end
	end

	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player(s) online:")
	for i, str in ipairs(strings) do
		if(str:sub(str:len()) ~= "-") then
			str = str .. ""
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, (i) .. " player(s) totally is playing at the moment.")
	end
else
     doPlayerSendCancel(cid, "You can check online players only one time per minute.")
end
	return true
end

-- Exhaustion system (Made by Alreth, bugfix by me)
-- DO NOT EDIT!
function exhaust(cid, STORE_VALUE, EXHAUST_TIME)
    
    newExhaust = os.time()
    oldExhaust = getPlayerStorageValue(cid, STORE_VALUE)
    if (oldExhaust == nil or oldExhaust < 0) then
        oldExhaust = 0
    end
    if (EXHAUST_TIME == nil or EXHAUST_TIME < 0) then
        EXHAUST_TIME = 1
    end
    diffTime = os.difftime(newExhaust, oldExhaust)
    if (diffTime >= EXHAUST_TIME) then
        setPlayerStorageValue(cid, STORE_VALUE, newExhaust) 
        return 1
    else
        return 0
    end
end

Now its like:
Player(s) online:
Name, name
Totally X players online

I want something like this:
Player(s) online:
Name, name
Support online:
- here showing: players who have group higher than 2 :)
Totally X players online
 
I want to add line in this command, who will be displaying a support people ex. Gamemasters/god's/tutors if they are online the line is displaying his nicks with "," param.
 
Try this:
Code:
local exhaustStorage = 1283

local config = {
	showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}

function onSay(cid, words, param, channel)
	if getPlayerStorageValue(cid, exhaustStorage) < os.time() then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to wait " .. getPlayerStorageValue(cid, exhaustStorage) - os.time() .. ".")
		return true
	end

	setPlayerStorageValue(cid, exhaustStorage, os.time() + 10)
	local players = getPlayersOnline()
	local normal = {}
	local unormal = {}
	local i = 0
	local c = 0

	for _, p in ipairs (players) do
		if getPlayerGroupId(p) >= 2 and config.showGamemsters then
			c = c + 1
			unormal[c] = getCreatureName(p)
		else
			i = i + 1
			normal[i] = getCreatureName(p)
		end
	end

	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player(s) online:\
	\n" .. table.concat(normal, ", ") .. ".")
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Support online:\
	\n" .. table.concat(unormal, ", ") .. ".")
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.format("Total %d players online", #normal + #unormal))
	return true
end
 
Back
Top