Jump to content
  • 0

[help]litle help with a code


UnixCode

Question

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 ? :/

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

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.

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Welcome to my store :  https://topestore.mysellix.io/fr/ 2015-2022 Aged Discord Account 2015 Discord Account : 50.99 $ 2016 Discord Account : 10$ 2017 Discord Account :3.99 $ 2018 Discord Account : 3.50$ 2019 Discord Account : 2.70 $ 2020 Discord Account :1.50$ 2021 Discord Account :0.99$ 2022 Discord Account :0.70$ Warranty :Lifetime Payment Methods : Crypto/ PayPal Contact Me On Discord Or Telegram Discord : @ultrasstore11 Telegram : https://t.me/ultrastore1 Welcome to my store :  https://topestore.mysellix.io/fr/ 2015-2022 Aged Discord Account 2015 Discord Account : 50.99 $ 2016 Discord Account : 10$ 2017 Discord Account :3.99 $ 2018 Discord Account : 3.50$ 2019 Discord Account : 2.70 $ 2020 Discord Account :1.50$ 2021 Discord Account :0.99$ 2022 Discord Account :0.70$ Warranty :Lifetime Payment Methods : Crypto/ PayPal Contact Me On Discord Or Telegram Discord : @ultrasstore11
    • L2 ArenaWar: Low Rate PvP Server with Free Buffs & Autofarm [PVP]⚔️ [Free]🆓 Classic Interlude with  3x XP rates! Free starter pack(no grade) to kickstart your adventure! Autofarm for convenient grinding! Free buffs to keep you fighting fit! (2 job buffs) No experience loss on death! (Except with Karma) Clear Karma system to keep things fair! ⚖️ Active community of 800-1k players! Join our Discord to learn more! >> Discord <<     Server website: https://l2arenawar.com/en/    
    • This is dedication! 2 years working on a problem. Congratulations!
    • You indeed have to save player position over Enterworld to properly clean it up later (if you don't, even trying to delete packet content would eventually keep it up), that's what we do with debug packet (which is a reusable Map of ExServerPrimitive packets) on aCis.   It doesn't solve the FPS stuttering - more you draw/delete lines, more your client becomes laggy. It's like if client wasn't deleting drawn points/lines properly, but instead simply hide them and redrawn content above.   If you got a solution, I would happy to integrate it.   You should check aCis#Player _debug packet integration, it allows very big amount of lines/points to be drawn, it is also reusable.   https://gitlab.com/Tryskell/acis_public/-/blob/master/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java?ref_type=heads https://gitlab.com/Tryskell/acis_public/-/blob/master/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java?ref_type=heads  
    • we sell website templates, make websites to order. Great selection at very good prices. My contacts discord : advert1231 telegram : https://t.me/ggwpins  
  • Topics

×
×
  • Create New...