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

Solved Change !online command

Galaxy

New Member
Joined
Feb 24, 2011
Messages
108
Reaction score
1
Location
Ireland/Carlow
Hello Otlanders :)

I would like to change my script that is responsible for showing players online in-game.

First of all, I would like to add exhaustion to it for 30 seconds.

Secondly, Well, I must give you an example ;P

Now, when I use a command !online, this appears in Defaul channel:
Code:
19:48 1 player(s) online:
19:48 Tomek [100000].

But, I would just like the script to tell me the amout of players online ONLY - NOT ALL THE NAMES THAT ARE ONLINE BECAUSE WHEN THERE WILL BE 100 PLAYERS ONLINE, IT WILL BE NOT NEEDED SPAM (sorry for caps lock xD)

So, something like that:
Code:
19:48 Actually there are X players online.
and thats all i want the script to tell me... :)

Here is the script :)
Code:
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

Thanks for your support! :)
 
Last edited:
REP ++ please


Code:
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, "Actually there are: " .. (i - 1) .. " player(s) online.")    
    return true 
end
 
Lua:
local config = { 
    showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand')) 
} 

local str = 1234
local exhaustTime = 30
function onSay(cid, words, param, channel) 
	if exhaustion.check(cid, str) then
		return doPlayerSendCancel(cid, 'you are exhausted')
	end
    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, "Actually there are: " .. (i - 1) .. " player(s) online.")
	exhaustion.set(cid, str,exhaustTime)
    return true 
end
 
Lua:
local config = { 
    showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand')) 
} 
 
local useExhaust = true
local storageValue = 1234
local exhaustTime = 30

function onSay(cid, words, param, channel) 
	if useExhaust and getCreatureStorage(cid, storageValue) > os.time() then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Sorry, you need to wait ' .. exhaustTime .. ' seconds before using this command again.')
	end
    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, "Actually there are: " .. (i - 1) .. " player(s) online.")
	setPlayerStorageValue(cid, storageValue, os.time() + exhaustTime)
    return true 
end
 
Lua:
local key = 1234
local time = 30

function onSay(cid, words, param, channel)
	if getCreatureStorage(cid, key) > os.time() then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Currently there are ' .. getWorldCreatures(0) .. ' players online.')
		doCreatureSetStorage(cid, key, os.time() + time)
	end
	return true
end
 
Last edited:
Back
Top