UnixCode Posted July 1, 2011 Posted July 1, 2011 Ok hello all, i have made an npc instance showing top online players for example[top 10]. So for example i want those 10 or the frist 4 of them for example to make them setHero(true); //example. But how will i store these 4 or 10 to an l2pcinstance object? for example if i wanted for the whole players online it would be: for(L2PcInstance p:L2World.getInstance().getAllPlayers()) p.setHero(true); So, how will i do this ? :/ Quote
0 mogo Posted July 1, 2011 Posted July 1, 2011 You could do that with a simple SQL query. I don't remember the correct field names from the top of my head right now, but it would look something like UPDATE characters SET isHero=True WHERE char_name IN (SELECT char_name FROM characters ORDER BY onlinetime DESC LIMIT 4); Mix that with a bit of java or python so that the players wouldn't need to relog to actually become heroes or you can just run the query when the server is off for maintenance. Quote
0 UnixCode Posted July 1, 2011 Author Posted July 1, 2011 i need it in java please , for example i need to give them methods that there aren't in navicat Quote
0 vampir Posted July 2, 2011 Posted July 2, 2011 If i understood you right, you want top 4 players in online time to be hero Here it is: Make a method in enterworld or somewhere that would look something like that: private static void haveFun(L2PcInstance player){ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters ORDER BY onlinetime DESC LIMIT 4 where char_name = "+ player.getName()); ResultSet chars = statement.executeQuery(); if(chars.next()){ player.setHero(true); } chars.close(); statement.close(); } catch (Exception e) { System.out.println(e); } finally { L2DatabaseFactory.close(con); } } and write at main method in enterworld this: haveFun(activeChar); I didnt test it and i was writing it mainly at this textbox so i cant quarante that it will work, hf :) Quote
0 UnixCode Posted July 2, 2011 Author Posted July 2, 2011 If i understood you right, you want top 4 players in online time to be hero Here it is: Make a method in enterworld or somewhere that would look something like that: private static void haveFun(L2PcInstance player){ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters ORDER BY onlinetime DESC LIMIT 4 where char_name = "+ player.getName()); ResultSet chars = statement.executeQuery(); if(chars.next()){ player.setHero(true); } chars.close(); statement.close(); } catch (Exception e) { System.out.println(e); } finally { L2DatabaseFactory.close(con); } } and write at main method in enterworld this: haveFun(activeChar); I didnt test it and i was writing it mainly at this textbox so i cant quarante that it will work, hf :) no errors but doesn't work Quote
0 Tryskell Posted July 2, 2011 Posted July 2, 2011 It depends entirely of the idea. If it's only related to pvp or existing infos, it can be made from existing data. If you have to store players because you can't rely on infos, you need another table. Vampir idea is fine, but the query is wrong (+ the query columns names depends of chronicle aswell). My query is surely wrong too lol, but you got main idea. "SELECT objId FROM characters ORDER BY pvpkills DESC LIMIT 4" Goal is first to take the best "pvpers/pkers/whatever", then store them in a list then use this list in EnterWorld ==> if list.objId == player.objId then setHero(true). List will be initialized at server load, and updated on a daily base using a task. Quote
0 UnixCode Posted July 2, 2011 Author Posted July 2, 2011 i tried this but no work private static void haveFun(L2PcInstance player) throws SQLException{ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT obj_Id FROM characters ORDER BY pvpkills DESC LIMIT 4"); ResultSet chars = statement.executeQuery(); long obj = chars.getLong("obj_Id"); if(obj== player.getObjectId()){ player.sendMessage("TOP PVP"); player.setNoble(true); } chars.close(); statement.close(); } catch (Exception e) { System.out.println(e); } finally { con.close(); } } Quote
0 vampir Posted July 2, 2011 Posted July 2, 2011 yeah just realized that limit 4 is not working as i thought, so code would be something like that: private static void haveFun(L2PcInstance player) throws SQLException{ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT obj_Id FROM characters ORDER BY pvpkills DESC LIMIT 4"); ResultSet chars = statement.executeQuery(); while(chars.next()){ long obj = chars.getLong("obj_Id"); if(obj == player.getObjectId()){ player.sendMessage("TOP PVP"); player.setNoble(true); } } chars.close(); statement.close(); } catch (Exception e) { System.out.println(e); } finally { con.close(); } } Quote
Question
UnixCode
Ok hello all, i have made an npc instance showing top online players for example[top 10].
So for example i want those 10 or the frist 4 of them for example to make them setHero(true); //example.
But how will i store these 4 or 10 to an l2pcinstance object? for example if i wanted for the whole players online it would be:
for(L2PcInstance p:L2World.getInstance().getAllPlayers())
p.setHero(true);
So, how will i do this ? :/
7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.