Jump to content
  • 0

[help]litle help with a code


Question

Posted

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

  • 0
Posted

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.

  • 0
Posted

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 :)

  • 0
Posted

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
  • 0
Posted

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.

  • 0
Posted

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();
	}
}

  • 0
Posted

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();
	}
}

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 account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Hi,   I’m reporting @nuturazvan for attempting to scam me out of 70€.   Last week, he contacted me on Discord saying he was looking for a control panel. I initially offered NimeraCP, but after I told him the price, he said he couldn’t afford it. I then told him I could develop a custom control panel within his budget. After discussing the details, we agreed on the following:   Control / Donate Panel includes: Donate page Account registration page Login page Password reset page Stripe integration Agreed price: 70€ Deal date: December 3, 2025   I finished developing the panel on December 6, 2025, but I have not delivered it yet. The code is complete and currently sitting in a private GitHub repository, waiting for payment. As of December 14, 2025, I still haven’t received any payment. I’ve asked him multiple times when I can expect it, and he keeps making excuses, saying a friend owes him money and that he’s waiting to get paid first.   If you don’t have the money, you shouldn’t be ordering work. I take responsibility for starting the work without upfront payment, but that doesn’t excuse repeatedly delaying payment.   Posting this as a warning to others.  
    • WTB GRACIA FINAL INTERFACE
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock