• 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 Talkaction online.lua (Show players online in certain area)

Extrodus

|| Blazera.net ||
Joined
Dec 22, 2008
Messages
2,692
Solutions
7
Reaction score
550
Location
Canada
How would I use online.lua to show players online in a certain area.

For example:
Players Online in Thais: 35, Venore: 15, Edron:20.
List: (List of players names online as usual)

It would be lovely if someone could edit/make this script for me. I searched all over the forums and couldn't seem to find someone who has requested this sort of thing.

My talkactions/online.lua

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

function onSay(cid, words, param, channel)
	local strings, i, position, added = {""}, 1, 1, false
	for _, pid in ipairs(getPlayersOnline()) 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

		added = false
		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
		end
	end

	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player" .. (i > 1 and "s" or "") .. " 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

Would be greatly appreciated! Thanks in advance.
 
The question is, you want check the area around the player or only a specific area?
 
For example: ( 500, 500, 1 to 1000, 1000, 15 ), (250, 250, 1 to 499, 499, 15)

First area = Thais, Second Area = Venore

Talkaction !online:
Player Online in Thais: 35, Venore: 15 (Overall Player Online: 50)
List: (Display all names of the people online from each city here)

Edit: Fail on my part, you wanted to know something specific.

The answer would be a certain area, I want to check from area to area (an entire city).
 
Hmm, I saw it effectively done without lag on Mega-Wars; thought it would be a good idea to bring to the community to script and share. Hopefully it can be done without lag!
 
You sure it checked how many players is online in the city or how many belong to that city xD?
 
It checks how many players are in each area, it allows people to check where the most people are to go fight. (Ment for War servers)
 
LUA:
local towns = {1, 2}
 
function onSay(cid, words, param, channel)
	local strings, i, position, added, showGamemasters, _towns = {""}, 1, 1, false, getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand')), {}
	for _, pid in ipairs(getPlayersOnline()) 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
 
		added = false
		if((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
 
            local closest = {nil, math.huge}
            for j = 1, #towns do
                local distance = getDistanceBetween(getThingPos(pid), getTownTemplePosition(towns[j]))
                if distance < closest[2] then
                    closest[1] = towns[j]
                    closest[2] = distance
                end
                
                if not _towns[towns[j]] then
                    _towns[towns[j]] = {towns[j], 0}
                end
            end
  
            _towns[closest[1]][2] = _towns[closest[1]][2] + 1 
		end
	end
 
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player" .. (i > 1 and "s" or "") .. " 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

    table.sort(_towns, function(a, b) return a[2] > b[2] end)
    local townsStr, first = "", true   
    for i = 1, #_towns do
        townsStr = townsStr .. (first and "" or ", ") .. getTownName(_towns[i][1]) .. ": " .. _towns[i][2]
        first = false
    end
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, townsStr)
 
	return true
end
 
Could you explain how this works a little bit? I dont understand how it gets the areas of the spots I want it to count the players from. You couldn't possibly make it so I can set the areas I want it to read from?

Example:
Area 1 [x, y, z to x, y, z],
Area 2 [x, y, z to x, y, z]

It would be awesome if you could do that ;*

P.S. - Thank you for trying to code this!
 
Could you explain how this works a little bit? I dont understand how it gets the areas of the spots I want it to count the players from. You couldn't possibly make it so I can set the areas I want it to read from?

Example:
Area 1 [x, y, z to x, y, z],
Area 2 [x, y, z to x, y, z]

It would be awesome if you could do that ;*

P.S. - Thank you for trying to code this!

It adds the players to the list depending on which temple is the closest one, you don't need positions, just put the numbers of the towns in the array.
 
Wonderful, I see how it works now. Just wondering, is it possible to make it so the list of towns and how many players are in each town lists at the top.

So instead of:
09:42 3 players online:
09:42 Admin [125], Risky [129], Knight T [125].
09:42 Warforia: 3

It would be:
09:42 3 players online:
09:42 Warforia: 1, Thais: 1, Venore: 1
09:42 Admin [125], Risky [129], Knight T [125].

<3 Much love to you Summ for this even if you can't get it the way I would like to have it; I am just being picky :)
 
Back
Top