• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Implementation on the !online command

KylerXX

Active Member
Joined
Jun 24, 2010
Messages
439
Reaction score
30
Well, when I was bored, I was thinking a one script that is an implementation of !online command.

Here is an image:
rookieb.jpg



Change the normal !online script to this one:
Lua:
local config = {
	showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}
 
function onSay(cid, words, param, channel)
	local players = getPlayersOnline()
	local strings = {""}
local sorc,druid,paladin,knight,rook = 0,0,0,0,0
 
	local i, position = 1, 1
	local added = false
	for _, pid in ipairs(players) do
	-- Implementacion por Xafterin.
		if isSorcerer(pid) then
			sorc = sorc + 1
		elseif isDruid(pid) then
			druid = druid + 1
		elseif isPaladin(pid) then
			paladin = paladin + 1
		elseif isKnight(pid) then
			knight = knight + 1
		elseif isRookie(pid) then
			rook = rook + 1
	end
	---
		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 .. ". ".. sorc .." sorcerers, ".. druid .." druids, ".. paladin .." paladins, ".. knight .." knights and ".. rook .." rookies."
		end
 
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
	end
 
	return true
end


That's all!
 
Ehmm... example:
If you are rookie you can't see this extra information, right :O?
 
no, if true then when you use !online it does not show "0 rookies", would be usefull since not too many servers use rook system xD
 
Okay, then change the script for this:
Lua:
local config = {
	showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}
local showToRook = true

function getVocShortString(cid) -- function by Xafterin
local string = ""
local tabla = {
		[0] = {"N"},
		[1] = {"S"},
		[2] = {"D"},
		[3] = {"P"},
		[4] = {"K"},
		[5] = {"MS"},
		[6] = {"ED"},
		[7] = {"RP"},
		[8] = {"EK"}
}
local p = tabla[getPlayerVocation(cid)]
	if p then
		string = p[1]
	end
return string
end
function onSay(cid, words, param, channel)
	local players = getPlayersOnline()
	local strings = {""}
local sorc,druid,paladin,knight,rook = 0,0,0,0,0

	local i, position = 1, 1
	local added = false
	for _, pid in ipairs(players) do
		if isSorcerer(pid) then
			sorc = sorc + 1
		elseif isDruid(pid) then
			druid = druid + 1
		elseif isPaladin(pid) then
			paladin = paladin + 1
		elseif isKnight(pid) then
			knight = knight + 1
		elseif isRookie(pid) then
			rook = rook + 1
	end

		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) .. "][".. getVocShortString(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 .. ". ".. sorc .." sorcerers, ".. druid .." druids, ".. paladin .." paladins, ".. knight .." knights"..(showToRook == true and " and ".. rook .." rookies." or ".")..""
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
	end

	return true
end


Now you can declare true or false show the rookies players count on this line:
Lua:
local showToRook = true

If you put true, the rook players count will be showed, if is false dont will be showed.
 
Thats cool, but if you get too many players you have to take out that.. or else it will lag whenever you say it haha
 
But I added options to remove or add those extra-codes, with this if you do not think that you need then you put false, and this I think it is useful.
 
Code:
	doPlayerSendTextMessage(cid, [COLOR="red"][B]MESSAGE_STATUS_CONSOLE_BLUE[/B][/COLOR], (i - 1) .. " player(s) online:")
	for i, str in ipairs(strings) do
		if(str:sub(str:len()) ~= ",") then
			str = str .. ". ".. sorc .." sorcerers, ".. druid .." druids, ".. paladin .." paladins, ".. knight .." knights and ".. rook .." rookies."
		end
 
		doPlayerSendTextMessage(cid, [B][COLOR="red"]MESSAGE_STATUS_CONSOLE_BLUE[/COLOR][/B], str)
here
 
Hey, can someone modify one for me?

I need one with this..

3 players online now - player name 1, player name 2 and player name 3.
2 players wirth a storage xx, and 01 player with storage yy and 0 palyers without a storages.
 
Back
Top