nvh Posted September 28, 2021 Share Posted September 28, 2021 SELECT Name, Level, Exp, PlayerId FROM Players order by Exp desc can u this for client dialog?? Link to comment Share on other sites More sharing options...
0 boasfesta Posted September 28, 2021 Share Posted September 28, 2021 You dont need to use raw SQL, let EntityFramework do that for you. An example for what are you trying to do is OnlinePlayers.OrderByDescending(p => p.Value.Exp).ToList(); So you got an ordered list of online players by Exp amount. Put that in communication between packets so clients can see it. Link to comment Share on other sites More sharing options...
0 nvh Posted September 28, 2021 Author Share Posted September 28, 2021 10 hours ago, boasfesta said: You dont need to use raw SQL, let EntityFramework do that for you. An example for what are you trying to do is OnlinePlayers.OrderByDescending(p => p.Value.Exp).ToList(); So you got an ordered list of online players by Exp amount. Put that in communication between packets so clients can see it. Oh thank u. where do i write that code? how to show top 20 player (Name & level, no need online) ? Link to comment Share on other sites More sharing options...
0 nvh Posted September 28, 2021 Author Share Posted September 28, 2021 1 minute ago, nvh said: Oh thank u. But how to show top 20 player (name and level, no need online) ? Link to comment Share on other sites More sharing options...
0 Cheshire Posted September 29, 2021 Share Posted September 29, 2021 5 hours ago, nvh said: Oh thank u. where do i write that code? how to show top 20 player (Name & level, no need online) ? You'd likely want to add your own new compiled query in Player.Database.cs on the server, then write up a UI or something on the client that will display this and request it from the server with a packet when the user opens this menu. Personally I would cache this query result, because once you get a couple thousand accounts it could start taking longer and longer as your game keeps getting players to come and try it. Link to comment Share on other sites More sharing options...
0 nvh Posted September 29, 2021 Author Share Posted September 29, 2021 27 minutes ago, Cheshire said: You'd likely want to add your own new compiled query in Player.Database.cs on the server, then write up a UI or something on the client that will display this and request it from the server with a packet when the user opens this menu. Personally I would cache this query result, because once you get a couple thousand accounts it could start taking longer and longer as your game keeps getting players to come and try it. What is the syntax to be able to write it? Can I save it to a file top.json and update it every 12h to keep the server from slowing down? Dialog from client can call command like \onlinelist Link to comment Share on other sites More sharing options...
0 boasfesta Posted September 29, 2021 Share Posted September 29, 2021 10 hours ago, nvh said: What is the syntax to be able to write it? Can I save it to a file top.json and update it every 12h to keep the server from slowing down? Dialog from client can call command like \onlinelist Chesire is right. Caching its best way to keep performance. Try to declare an public static List and update it every 60m for example. But if you're using MySQL and considering that people wont check the toplist everytime. You dont need to worry about caching up at all. Even a huge table wont be affected that much. So for a command /top, just code something like this: if (command = "/top") { var topList = OnlinePlayers.OrderByDescending(x => x.Value.Exp).ToList(); var topListString = string.Empty; foreach (var player in topList){ // concat topListString here } //SendChatMsg blablabla topliststring } HelenaToDev 1 Link to comment Share on other sites More sharing options...
0 nvh Posted September 30, 2021 Author Share Posted September 30, 2021 8 hours ago, boasfesta said: Chesire is right. Caching its best way to keep performance. Try to declare an public static List and update it every 60m for example. But if you're using MySQL and considering that people wont check the toplist everytime. You dont need to worry about caching up at all. Even a huge table wont be affected that much. So for a command /top, just code something like this: if (command = "/top") { var topList = OnlinePlayers.OrderByDescending(x => x.Value.Exp).ToList(); var topListString = string.Empty; foreach (var player in topList){ // concat topListString here } //SendChatMsg blablabla topliststring } which file .cs for this code? can show player name of this.valueEXP ? Link to comment Share on other sites More sharing options...
0 boasfesta Posted September 30, 2021 Share Posted September 30, 2021 2 hours ago, nvh said: which file .cs for this code? can show player name of this.valueEXP ? Function public void HandlePacket(Client client, ChatMsgPacket packet) in PacketHandler.cs at Intersect.Server its a good place. And yup, you can show the player name since the list only order players by exp, but his whole data is returned. Link to comment Share on other sites More sharing options...
0 nvh Posted October 1, 2021 Author Share Posted October 1, 2021 21 hours ago, boasfesta said: Hàm public void HandlePacket (Client client, gói ChatMsgPacket) trong PacketHandler.cs tại Intersect.Server là một nơi tốt. Và đúng vậy, bạn có thể hiển thị tên người chơi vì danh sách chỉ sắp xếp người chơi theo điểm kinh nghiệm, nhưng toàn bộ dữ liệu của anh ta sẽ được trả về. can I using this ? Link to comment Share on other sites More sharing options...
0 boasfesta Posted October 1, 2021 Share Posted October 1, 2021 You can. But that method seems to be called at every event command, so even if you're not asking for a toplist, the system will check the database for a ordered list. Consider making a cache if that becomes laggy. Just do that string.Join in a topList.Select(x => x.Name).toList(), it should world. Link to comment Share on other sites More sharing options...
0 nvh Posted October 1, 2021 Author Share Posted October 1, 2021 1 hour ago, boasfesta said: You can. But that method seems to be called at every event command, so even if you're not asking for a toplist, the system will check the database for a ordered list. Consider making a cache if that becomes laggy. Just do that string.Join in a topList.Select(x => x.Name).toList(), it should world. is there any way to fix it? {@“\command”, set method in here}?? Link to comment Share on other sites More sharing options...
0 boasfesta Posted October 1, 2021 Share Posted October 1, 2021 {@“\command”, string.Join(Environment.NewLine, topList.Select(x => x.Name).ToList())} should work nvh 1 Link to comment Share on other sites More sharing options...
0 nvh Posted October 3, 2021 Author Share Posted October 3, 2021 On 10/1/2021 at 11:23 PM, boasfesta said: {@“\command”, string.Join(Environment.NewLine, topList.Select(x => x.Name).ToList())} should work thank u. I have toplv online (auto) I will query with .db to create a top lv offline (manually) boasfesta 1 Link to comment Share on other sites More sharing options...
Question
nvh
SELECT Name, Level, Exp, PlayerId
FROM Players
order by Exp desc
can u this for client dialog??
Link to comment
Share on other sites
13 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now