天堂私服123首頁 | GM發布私服 | 在線人員: 1608943
當前位置:天堂私服123>私服架設>天堂私服排行榜的編寫方式~

天堂私服排行榜的編寫方式~

發表時間:2016-10-15

本排名系統最初由99nets.spofpak首發

經過我的整理,然后經過missu0524的改良(還有一個missu0524的版本,目前還沒有辦法適當地套用在我自己的版本上)

再經由9001183ex的共同努力,目前達成如下效果,在收集排名的同時避免太多人點擊而造成伺服器LAG.

理論上而言,可以套用到從三年前到現在的任何版本......

本段代碼由missu0524所提供

[Copy to clipboard]

CODE:
private String[] getPlayersExp() throws SQLException { //等级排名
String[] name = new String[10];
PreparedStatement pstm1 = null;
ResultSet rs = null;
Connection con = null;
con = L1DatabaseFactory.getInstance().getConnection();
int cc = 0;
while (cc < 10) {
pstm1 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit "+cc+",1;");
rs = pstm1.executeQuery();
while (rs.next()) {
name[cc] = rs.getString("char_name");
}
SQLUtil.close(rs);
cc++;
}
return name;
}

通過讀取DB內所保存的數據而非玩家的當前數據,所以每次讀取的應該是在線玩家上線時的數據,每次有玩家下線,DB資料庫更新此排名也隨之更新.

[Copy to clipboard]

CODE:
if (((L1NpcInstance)obj).getNpcTemplate().get_npcId()==123456) { //排行榜NPC的编号
L1NpcInstance npc = (L1NpcInstance) obj;
int time = npc.getSkillEffectTimeSec(123456);
if (s.equalsIgnoreCase("playersexp")) { //显示等级前10
if (!npc.hasSkillEffect(123456) || pc.isGm()) {
htmldata = getPlayersExp();
htmlid = "getexp";
npc.setSkillEffect(123456, 1800*1000);
} else {
npc.broadcastPacket(new S_NpcChatPacket(npc, "最新排名的信息还需要"+ time +"秒的时间,请稍后再来!", 0));
Thread.sleep(10000);
}
}
}

每半小時可以查詢一人次......這便是此寫法的不是很人性化的一個地方了,為了避免LAG,暫時也只好這樣了.


----------------------------------------------------------------------------


softpak曾經寫過的排行榜,只是拿過來稍稍改了一下.因為softpak以前是發在99的,所以請勿隨意轉載.

希望套用等級排名而又不希望太過於佔用資源導致伺服器LAG的朋友請將此貼所有跟貼看完

看完後相信可以有一個比較適當的解決方法給你!


對話檔命令添加:
if (s.equalsIgnoreCase("playersexp")) { //顯示等級前10
htmldata = getPlayersExp();
htmlid = "playersexp";
}

寫一個<var src="#xx">的對話檔,命令為 playersexp 備用

隨意找個能添加的java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

private String[] getPlayersExp() throws SQLException { //等級排名 by softpak .jhony修正
String msg1 = null; String msg2 = null; String msg3 = null; String msg4 = null; 
String msg5 = null; String msg6 = null; String msg7 = null; String msg8 = null; 
String msg9 = null; String msg10 = null;
PreparedStatement pstm1 = null; PreparedStatement pstm2 = null;
PreparedStatement pstm3 = null; PreparedStatement pstm4 = null;
PreparedStatement pstm5 = null; PreparedStatement pstm6 = null;
PreparedStatement pstm7 = null; PreparedStatement pstm8 = null;
PreparedStatement pstm9 = null; PreparedStatement pstm10 = null;
ResultSet rs1 = null; ResultSet rs2 = null;
ResultSet rs3 = null; ResultSet rs4 = null;
ResultSet rs5 = null; ResultSet rs6 = null;
ResultSet rs7 = null; ResultSet rs8 = null;
ResultSet rs9 = null; ResultSet rs10 = null;
Connection con = null;
String[] expresult = null;
con = L1DatabaseFactory.getInstance().getConnection();
pstm1 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 0,1;");
pstm2 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 1,1;");
pstm3 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 2,1;");
pstm4 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 3,1;");
pstm5 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 4,1;");
pstm6 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 5,1;");
pstm7 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 6,1;");
pstm8 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 7,1;");
pstm9 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 8,1;");
pstm10 = con.prepareStatement("select char_name from characters where accesslevel=0 order by exp DESC limit 9,1;");
rs1 = pstm1.executeQuery();
while (rs1.next()) {
msg1 = rs1.getString("char_name");
}
rs2 = pstm2.executeQuery();
while (rs2.next()) {
msg2 = rs2.getString("char_name");
}
rs3 = pstm3.executeQuery();
while (rs3.next()) {
msg3 = rs3.getString("char_name");
}
rs4 = pstm4.executeQuery();
while (rs4.next()) {
msg4 = rs4.getString("char_name");
}
rs5 = pstm5.executeQuery();
while (rs5.next()) {
msg5 = rs5.getString("char_name");
}
rs6 = pstm6.executeQuery();
while (rs6.next()) {
msg6 = rs6.getString("char_name");
}
rs7 = pstm7.executeQuery();
while (rs7.next()) {
msg7 = rs7.getString("char_name");
}
rs8 = pstm8.executeQuery();
while (rs8.next()) {
msg8 = rs8.getString("char_name");
}
rs9 = pstm9.executeQuery();
while (rs9.next()) {
msg9 = rs9.getString("char_name");
}
rs10 = pstm10.executeQuery();
while (rs10.next()) {
msg10 = rs10.getString("char_name");
}
expresult = new String[] {String.valueOf(msg1),String.valueOf(msg2),String.valueOf(msg3),String.valueOf(msg4),String.valueOf(msg5),String.valueOf(msg6),String.valueOf(msg7),String.valueOf(msg8),String.valueOf(msg9),String.valueOf(msg10)};
SQLUtil.close(rs1);
SQLUtil.close(rs2);
SQLUtil.close(rs3);
SQLUtil.close(rs4);
SQLUtil.close(rs5);
SQLUtil.close(rs6);
SQLUtil.close(rs7);
SQLUtil.close(rs8);
SQLUtil.close(rs9);
SQLUtil.close(rs10);
SQLUtil.close(pstm1);
SQLUtil.close(pstm2);
SQLUtil.close(pstm3);
SQLUtil.close(pstm4);
SQLUtil.close(pstm5);
SQLUtil.close(pstm6);
SQLUtil.close(pstm7);
SQLUtil.close(pstm8);
SQLUtil.close(pstm9);
SQLUtil.close(pstm10);
SQLUtil.close(con);
return expresult;
}

 
其他分類
私服技巧
玩家分享
私服架設
私服新手區
 
相關推薦
優化MYSQL數據庫減少天堂私服當機的機會!
天堂私服玩家不知道的秘密!!
天堂私服GM指令簡易列表!
一個為兒子買天幣的媽媽~淚流滿面!
一段被騙天堂帳號的回憶
揭密天堂私服電腦容易中毒的原因,以及某些私服業者惡意的行為!!
天堂私服玩家無法進入論壇與遊戲的解決方法之一!
天堂私服內LH2喝水設定詳細教學
天堂私服內建自動喝水LHZ使用教學
防止外掛特殊況狀使用喝水功能!
如何在天堂私服盟戰中發揮技巧~
教你Lineage3.0天堂不能玩私服的解決方法!
自我檢測無法玩天堂私服的原因!!
小妙招幾步驟可以幫助你更快速的玩天堂遊戲喔!!
玩天堂不關機延長電腦硬碟壽命的方法
總是打不贏別人嗎?看看天堂打架技巧教戰守則吧!!
天堂打稱號★顏色代碼★符號★教您如何使用!
超骨灰級!這些天堂技巧你知道多少?又用過多少?
怎麼上傳天堂盟徽?不會上傳天堂盟徽嗎?教您如何上傳!!
天堂各職業出生/洗血配點.洗血後配點(王族篇)
   

網站地圖關於天堂私服123天堂私服123列表免責聲明刊登廣告私服合作私服百科天堂私服123粉絲團天堂私服123 GOOGLE+
天堂私服123 © https://playsf.net/ Corporation All Rights Reserved.