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
  On 7/2/2011 at 12:05 AM, vampir said:

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

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

    • ⚔️ Balance or Power? The community decides!   During spot hunting and battles, the Destroyer (under limits) can wipe out dozens of mobs in seconds, outperforming other classes. A player on Destroyer (with three windows) can monopolize top farming spots solo, while most other classes require additional characters to compete. Result: Resources end up concentrated in the hands of a single player rather than being distributed among multiple participants.   We propose discussing possible changes: Reducing the number of targets the Destroyer can hit under limits. Balancing vampirism by implementing progressive efficiency reduction based on the number of enemies attacked. These changes would preserve the class identity while making PvE more fair for everyone.   🎯 What do you think?
    • Newcomers always raise suspicion. At first, people look at the newcomer cautiously. “Who is this? Where did they come from? Are they here to stay?” That’s just how it is trust isn’t given right away. It’s the same with services, especially when it comes to your accounts, money, and verifications. But the truth is, every major player was once that “newbie” entering the chat. VibeSMS we’re new on the forum, but definitely not new to the game: — Fast and stable SMS verification — Numbers from 68+ countries — Rentals for PayPal, Telegram, Amazon, and dozens of other services — Prices starting at $0.1 per activation or $5–8/month for rental We don’t promise mountains from the sky. We simply make sure the code arrives quickly, and you get what you paid for. No extra words or surprises. Because in the world of SMS verifications, it’s not magic that counts, but reliability consistent speed, transparent pricing, and a service you can depend on every day.
    • sell adena l2rebon signature x1 - 1kk = 1.4 dollars l2reborn x10 - 500kk = 7 dollars E-Global x Lu4 - 1kk = 4 dollars DISCORD - GODDARDSHOP TELEGRAM - MMOPROMO
    • Locked. Not following the rules.
    • Put prices on your first post. Read the rules.
  • 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