TalkAction [TFS 0.2.5] Ingame Highscores

4220niller

XHTML / CSS Coder
Joined
Jul 4, 2007
Messages
127
Best answers
0
Reaction score
1
Location
Denmark, Korsør
ATTENTION! this script only works on servers with LuaSQL and doPlayerPopupFYI()

Example:
!ranks "level


Updated table format + fix, and fixed Sqlite support. Image is outdated

talkactions/scripts/highscores.lua
Code:
function onSay(cid, words, param)
    dofile("./config.lua")
	local players = 20 -- The amount of players that is shown in the list
	local maxgroupid = 1 -- Players in groups above this is not shown in the list
	
	if sqlType == "mysql" then
		env = assert(luasql.mysql())
		con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	else -- sqlite
		env = assert(luasql.sqlite3())
		con = assert(env:connect(sqliteDatabase))
	end
	
	local str = ""
	if param == "level" or param == "exp" or param == "lvl" or param == "" then
		cur = assert(con:execute("SELECT `name`, `level`, `experience` FROM `players` WHERE `group_id` <= "..maxgroupid.." ORDER BY `experience` DESC LIMIT 0,"..players..";"))
		row = cur:fetch({}, "a")
		str = "# [Level] - Name - (Experience)\n"
		local i = 0
		while row do
			str = str.."\n#"..(i+1).." ["..row.level.."] - "..row.name.." - ("..row.experience..")"
			row = cur:fetch (row, "a")
			i = i+1
		end
	elseif param == "maglevel" or param == "magic" or param == "ml" then
		cur = assert(con:execute("SELECT `name`, `maglevel` FROM `players` WHERE `group_id` <= "..maxgroupid.." ORDER BY `maglevel` DESC LIMIT 0,"..players..";"))
		row = cur:fetch({}, "a")
		str = "# [Magic Level] - Name\n"
		local i = 0
		while row do
			str = str.."\n#"..(i+1).." ["..row.maglevel.."] - "..row.name..""
			row = cur:fetch (row, "a")
			i = i+1
		end
	elseif param == "fist" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 0 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Fist Fighting] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	elseif param == "club" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 1 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Club Fighting] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	elseif param == "sword" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 2 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Sword Fighting] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	elseif param == "axe" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 3 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Axe Fighting] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	elseif param == "dist" or param == "distance" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 4 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Distance Fighting] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	elseif param == "shield" or param == "shielding" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 5 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Shielding] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	elseif param == "fish" or param == "fishing" then
		cur = assert(con:execute("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = 6 ORDER BY `value` DESC;"))
		row = cur:fetch({}, "a")
		str = "# [Fishing] - Name\n"
		local i = 0
		while row do
			if i == players then
				break
			end
			query = assert(con:execute("SELECT `name` FROM `players` WHERE `group_id` <= "..maxgroupid.." AND `id` = "..row.player_id..""))
			sql = query:fetch({}, "a")
			if sql ~= nil then
				str = str.."\n#"..(i+1).." ["..row.value.."] - "..sql.name..""
				i = i+1
			end
			row = cur:fetch (row, "a")
		end
	end
	if str ~= "" then
		doPlayerPopupFYI(cid, str)
	end
	con:close()
	env:close()
end
talkactions/talkactions.xml
Code:
<talkaction words="!ranks" script="highscores.lua"/>
 
Last edited:

mamon_2

Banned User
Joined
Jul 2, 2007
Messages
424
Best answers
0
Reaction score
0
It owns! I will implement it on my ot xD
 

Jonern

Retired
Joined
May 31, 2007
Messages
1,054
Best answers
0
Reaction score
8
Location
Norway
Great script!

Gave you some rep for it :) (hint hint)
 

kofel

Quietly
Joined
Aug 19, 2007
Messages
74
Best answers
0
Reaction score
1
Thanks, i searched this!
 

Pedro B.

OpenTibia Official Dev
Joined
Aug 8, 2007
Messages
127
Best answers
0
Reaction score
2
Location
Brazil
This wouldnt work for SQLite would it?
It wouldn't, but you can easily make it support SQLite is you change the "luasql.mysql" to "luasql.sqlite3" and change the env:connect() to open the SQLite database(check examples on the deathlist script of the TFS svn).
 

jankk

New Member
Joined
Aug 15, 2007
Messages
60
Best answers
0
Reaction score
1
Oo nice idea! but becouse of that my server crashed :(
 

Mark

Administrator
Staff member
Administrator
Joined
May 27, 2007
Messages
6,389
Best answers
21
Reaction score
1,388
Location
Sweden
Creating this for XML would mean to parse every player XML file on your server, and you should know what that means. Switch to SQL instead.
 

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
Location
The Netherlands
I think I found a bug , not sure.

it seems that it isnt like magic: 20 19 18 insteed it goes from magic 0 35 3 12 1 or something? you know what I mean?
 
Top