• 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 Script] teams online (solved)

StormRusher

New Member
Joined
Dec 23, 2009
Messages
138
Reaction score
0
Hi
I need a modification for this script:

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

function onSay(cid, words, param, channel)
	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

	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " 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)
	end

	return true
end

I want to show how many players with getPlayerStorageValue(1) == 1 and how many with storage(1) == 2

Thanks
 
Last edited:
Lua:
function onSay(cid, words, param, channel)
	local players = getPlayersOnline()
	local first_ = 0
	local second_ = 0
	
	for _, pid in ipairs(players) do
		if getPlayerStorageValue(pid, STORAGE_NUMBER) == 1 then
			first_ = first_ +1
		end
		
		if getPlayerStorageValue(pid, STORAGE_NUMBER) == 2 then
			second_ = second_ +1
		end
	end
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Storage value 1 have "..first_.." player's, Storage value 2 have "..second_.." player's.")
	return true
end

#EDIT#
I don't tested this xS, replace STORAGE_NUMBER to number of storage value
 
ok it worked, but i want to show the players name, for example, if have 4 players online, 2 in team1 (Joan and Michael), and 2 in team2 (Rubens and George). The talkaction return like that:

Team1 = 2 (team count like in your script)
Joan, Michael

Team2 = 2
Rubens, George

hope its possible xD,

thanks
 
1. I don't tested it
2. I'm never before used "table.concat"
3. Write information in this thread if it work xS
4. Sorry for noobish english ^^

Lua:
function onSay(cid, words, param, channel)
	local players = getPlayersOnline()
	local first_ = 0
	local second_ = 0
	local team1 = {}
	local team2 = {}
       
	for _, pid in ipairs(players) do
		if getPlayerStorageValue(pid, STORAGE_NUMBER) == 1 then
			first_ = first_ +1
			table.insert(team1, getCreatureName(pid))
		end
               
		if getPlayerStorageValue(pid, STORAGE_NUMBER) == 2 then
			second_ = second_ +1
			table.insert(team2, getCreatureName(pid))
		end
	end
	
	if table.maxn(team1) == 0 then
		table.insert(team1, "NOBODY")
	end
	
	if table.maxn(team2) == 0 then
		table.insert(team2, "NOBODY")
	end
	
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Team1 = "..first_.." ("..table.concat(team1 , ", ").."),\n Team2 = "..second_.." ("..table.concat(team2 , ", ")..").")
	return true
end
 
Man thanks very much, the script is PERFECT

now i need a last thing hehe,

i want show in team1 and team2, only players with getPlayerGroupId < 3, then in another line show the other players with group >= 3, like GODs, GMs, CMs.

thanks again, already rep++
 
Just removed players with group >= 3 from the table.
Lua:
  function onSay(cid, words, param, channel)
        local players = getPlayersOnline()
        local first_ = 0
        local second_ = 0
        local team1 = {}
        local team2 = {}
       
        for _, pid in ipairs(players) do
                if getPlayerStorageValue(pid, STORAGE_NUMBER) == 1 and getPlayerGroupId(pid) < 3 then
                        first_ = first_ +1
                        table.insert(team1, getCreatureName(pid))
                end
               
                if getPlayerStorageValue(pid, STORAGE_NUMBER) == 2 and getPlayerGroupId(pid) < 3 then
                        second_ = second_ +1
                        table.insert(team2, getCreatureName(pid))
                end
        end
       
        if table.maxn(team1) == 0 then
                table.insert(team1, "NOBODY")
        end
       
        if table.maxn(team2) == 0 then
                table.insert(team2, "NOBODY")
        end
       
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Team1 = "..first_.." ("..table.concat(team1 , ", ").."),\n Team2 = "..second_.." ("..table.concat(team2 , ", ")..").")
        return true
end
 
Back
Top