热门搜索: LOL雷霆之怒蓝月传奇传奇霸业
--执行数据库操作function rows (connection, sql_statement) local cursor = assert (connection:execute (sql_statement)) return function () return cursor:fetch() endend
function ontalk2037_997(npc,event,player) local mysql = require "luasql.mysql" --创建环境对象 local env = assert(mysql.mysql()) local conn_db = assert(env:connect("game","root","123456","127.0.0.1",3306)) --操作数据数据库 conn_db:execute "SET NAMES utf8"
player:echo(0,npc:GetLowGUID(),[[ 战士 战力排行榜]]); for name,restTime in rows(conn_db, "SELECT name,restTime FROM `characters` WHERE class=1 ORDER BY restTime DESC Limit 10") do player:echo(0,npc:GetLowGUID(),[[]]..string.upper(string.format("%s %s",name,restTime))..[[
]]); end player:echo(0,npc:GetLowGUID(),[[ <u><a href='event:M2402,998'>法师排行榜</a></u> <u><a href='event:M2402,999'>道士排行榜</a></u>]]); conn_db:close() --关闭数据库连接 env:close() --关闭数据库环境end
function ontalk2037_998(npc,event,player) local mysql = require "luasql.mysql" --创建环境对象 local env = assert(mysql.mysql()) local conn_db = assert(env:connect("game","root","123456","127.0.0.1",3306)) --操作数据数据库 conn_db:execute "SET NAMES utf8"
player:echo(0,npc:GetLowGUID(),[[ 法师 战力排行榜]]); for name,restTime in rows(conn_db, "SELECT name,restTime FROM `characters` WHERE class=2 ORDER BY restTime DESC Limit 10") do player:echo(0,npc:GetLowGUID(),[[]]..string.upper(string.format("%s %s",name,restTime))..[[
]]); end player:echo(0,npc:GetLowGUID(),[[ <u><a href='event:M2402,997'>战士排行榜</a></u> <u><a href='event:M2402,999'>道士排行榜</a></u>]]); conn_db:close() --关闭数据库连接 env:close() --关闭数据库环境end
function ontalk2037_999(npc,event,player) local mysql = require "luasql.mysql" --创建环境对象 local env = assert(mysql.mysql()) local conn_db = assert(env:connect("game","root","123456","127.0.0.1",3306)) --操作数据数据库 conn_db:execute "SET NAMES utf8"
player:echo(0,npc:GetLowGUID(),[[ 道士 战力排行榜]]); for name,restTime in rows(conn_db, "SELECT name,restTime FROM `characters` WHERE class=3 ORDER BY restTime DESC Limit 10") do player:echo(0,npc:GetLowGUID(),[[]]..string.upper(string.format("%s %s",name,restTime))..[[
]]); end player:echo(0,npc:GetLowGUID(),[[ <u><a href='event:M2402,997'>战士排行榜</a></u> <u><a href='event:M2402,998'>法师排行榜</a></u>]]); conn_db:close() --关闭数据库连接 env:close() --关闭数据库环境end
对照目录放置文件(如QQ图片显示)
NPC脚本用的是城主雕像,懂得就自己提取美化吧
(直接读数据库,没做什么限制,最好是读取后生成缓存文件,再读取缓存,10分钟一次,负责被人点死服务器不负责)
PS:万一砸人饭碗,请见谅,By Xuell下载相关组件请到百度网盘下载链接:http://pan.baidu.com/s/1i36fIYx 密码:s8tn