Jump to content

Question

Posted

Hello guys,
I have a script that checks who has most pvp in one day,it checks it by checking database and at the end of the day I want to set a player,who has most pvps, to hero.I don't know how to get character instance,so I can't do player.setHero(true).I can change database table "heroes",but I am not sure what columns like played,active,message mean.
I can get any info from database,but I am not sure how to set the player with most pvp to Hero(changing hero to 1 in characters table doesn't work).
So I either need a way to make a player a hero using database or better thing would be to get Character instance so I can use Player.setHero(true);

5 answers to this question

Recommended Posts

  • 0
Posted

Have you tried the //admin feature ingame ? 

 

Have in my mind that in order for some changes to the DB to take place , character has to be offline and account logged out . 

I don't see why the hero status could not stay when you change it in the DB. 

 

greetings

  • 0
Posted (edited)

It stays and I think I found why it doesn't make person a hero after restart:because in L2PcInstance when loading character info it doesn't load anything related to hero.
//sethero makes you a hero only till restart and it uses targeted player instance.

Edited by StealthyS4m
  • 0
Posted (edited)

You probably have there a method which determine the top 1, announce it or so. So use it.

 

topOne.setHero(true); or simply player / activeChar

 

You got the point. And if you dont, you have to create it.

Edited by SweeTs
  • 0
Posted (edited)

Ok,I am going to try my best now to explain what I wanted and how I got it.
This is how I get top player:

PreparedStatement statement = con.prepareStatement("SELECT char_name,hero,obj_Id FROM characters ORDER BY zone_pvp DESC LIMIT 1");

So I wanted to create l2player instance out of it and use player.setHero(true);
So I built a method which returns my l2player instance.
 

	public static L2PcInstance getPlayerById(int id){
		final Collection<L2PcInstance> allPlayers = L2World.getInstance().getAllPlayers().values();
		final int playersCount = allPlayers.size();
		final L2PcInstance[] players = allPlayers.toArray(new L2PcInstance[playersCount]);
		for(int a = 0;a<playersCount;a++){
			if(players[a].getObjectId() == id){
				_log.log(Level.WARNING,"Player is online!");
				return players[a];
			} 
		}
		return null;
	}

Then I turned player into hero using this method:
 

	static void makeHero(Connection con,String name,int id) throws SQLException{
		PreparedStatement makeHero = con.prepareStatement("UPDATE characters SET is_pvphero=?,hero=? WHERE char_name=?");
		makeHero.setInt(1, 1);
		makeHero.setInt(2, 1);
		makeHero.setString(3, name);
		L2PcInstance player = getPlayerById(id);
		makeHero.executeUpdate();
		makeHero.close();
		if(player !=null){
		player.setHero(true);
		player.broadcastUserInfo();
		}
		
	}

and added these lines to L2PcInstance,so players after restart are stil heroes:

private static final String RESTORE_CHARACTER = "SELECT ............. is_pvphero FROM characters WHERE obj_id=?";
player.setHero(rset.getInt("is_pvphero")==1);

I hope I made it a bit clearer.
Could you tell me how to improve my code?
And I have a question,when player becomes a hero through olympiad does hero column value in characters table is changed to 1?

Edited by StealthyS4m

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...