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.



×
×
  • Create New...