• 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!

help in counting players [8.50]

mostafaz4

New Member
Joined
Jun 24, 2009
Messages
25
Reaction score
0
Location
Egypt
im making a event which count players in a room every 1 min and send them message how much player in that room

i think i have that code but i cant make it work

Code:
function onThink(interval, lastExecution, thinkInterval)
function pc()
for roomx = 995,998 do
for roomy = 1006,1009 do
roomsize = {x=roomx, y=roomy, z=7, stackpos=253}
local playercount = getThingfromPos(roomsize)
	if playercount.itemid > 0 then
	for _, pid in ipairs(playercount) do
	playerc = playercount.type
		doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "There is "..playerc.." players in the event room.")
		addEvent(pc,2000)
else
		stopEvent(pc)
		end end end
end
		addEvent(pc,2000)
end

any help ??
 
this should work
XML:
<globalevent name="event" interval="2000" script="event.lua"/>
LUA:
function getEventPlayers(pos, radiusx, radiusy, stack)
        local players = {}
        local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z}  
        local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z}
        for x = starting.x, ending.x do
                for y = starting.y, ending.y do
                        for z = starting.z, ending.z do
                                local pos = {x=x, y=y, z=z,stackpos = stack}
                                local thing = getThingfromPos(pos)
                                if thing.itemid > 0 then
                                        if isPlayer(thing.uid) == TRUE then
                                                table.insert (players, thing.uid)
                                        end
                                end                      
                        end
                end
        end
    return players
end

function onThink(interval, lastExecution, thinkInterval)
    
    local position = {x=996, y=1007, z=7} --center of event area
    local pid = getEventPlayers(position, 4, 4, 253)                              
    
    if #pid < 1 then
        return true
    end
    
    for _, cid in ipairs(pid) do
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'There are ' .. #pid .. ' players in the event room.')
    end
    return true
end
 
Back
Top