• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Talkactions] Check players online in certain areas

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
595
Solutions
2
Reaction score
66
Location
México
Hello, im using tfs 0.3.6 and i need this script

when a player uses !online appears next message:
Players Online:
Arena 1 : 4 players
Arena 2 : 6 players
Arena 3 : 15 players
etc...
 
Try
Code:
function countPlayers(fromPosition, toPosition)
    local count = 0
    for _, pid in ipairs(getPlayersOnline()) do
        if isInRange(getCreaturePosition(pid), fromPosition, toPosition) then
            count = (count + 1)
        end
    end
    return count
end

function onSay(cid, words, param, channel)
    local area1 = countPlayers({x = 1, y = 1, z = 7}, {x = 3, y = 3, z = 7})
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Players in area 1: "..area1..".")
    return true
end

Updated, now use getPlayersOnline() and isInRange().

Thanks @cbrm
 
Last edited:
Try
Code:
function countPlayers(fromPos, toPos)
    local count = 0
    for x=fromPos.x,toPos.x do
        for y=fromPos.y,toPos.y do
            for z=fromPos.z,toPos.z do
                local v = getTopCreature({x=x, y=y, z=z}).uid
                if isPlayer(v) then
                    count = (count + 1)
                end
            end
        end
    end
    return count
end

function onSay(cid, words, param, channel)
    local area1 = countPlayers({x = 1, y = 1, z = 7}, {x = 3, y = 3, z = 7})
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Players in area 1: "..area1..".")
    return true
end
what if players are stacked?? iterate thru getPlayersOnline() and check with isInRange(position, fromPosition, toPosition)
 
Back
Top