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

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

    • TG Support: https://t.me/buyingproxysup | Channel: https://t.me/buyingproxycom Discord support: #buyingproxy | Server: Join the BuyingProxy Discord Server!  Create your free account here
    • I came out of my cave as I do once every 5 years. By now, I know nobody really cares about L2, but I still find it fun to experiment. Everything you see here will be free and open source. I have no interest in selling anything.   Long story short, I like to revisit Interlude and apply what I've learned to see how far I can push it. Here's Outerlude, a public fork of aCis for the modern age.   Video demo:   Work that has been done:   Redone the netcode from scratch to be async The NPC AI was completely redone based on Finite State Machines Moved to PostgreSQL and using some of its cool features Lots of config that should be hot reloadable has moved to the database OpenTelemetry instrumentation, where it makes sense, and a Grafana dashboard A built-in REST API for server management A built-in MCP Server for LLMs Nidrah AI, an AI Agent to make managing the server easier Real-time server map view Chat auditing and live snooping A new Fake Players Engine with a Node logic system and a new LLM planner for any behavior Just watch the video   If there is interest in this and I'm happy with it, or I get bored (which I always do), I will open-source it. Let me know what you think and if there is some feature you'd like me to implement.
    • Hello everyone!   I offer Java development services for L2-like projects.   I have been working with Java since 2015-2016. During the last years I worked on contract Lineage 2 server development and related infrastructure. My main focus is server-side Java, L2JMobius-based forks, custom systems, packets, datapack/XML, SQL/JDBC, optimization and fixing unstable logic.   Experience with: L2JMobius main/original branch; L2JMobius Essence branch; Lucera interlude; Custom L2-like packs where many things were already changed from the original codebase;   What I can help with: custom systems for your pack; skills / effects / triggers / formulas; NPC / AI / scripts; shops / services / buffer / GM shop logic; items / enchant / rewards / missions; special hunting zones, instances, spawn/zone logic; custom packets and server-side integration with existing client UI changes; server-side integration for existing client-side edits/maps/geodata; SQL/JDBC, XML/datapack, XSD, configs; porting mechanics between branches/chronicles; bug fixing, cleanup, legacy refactoring; performance fixes: memory leaks, race conditions, broadcast/task-manager bottlenecks. other server-side game mechanics;   Examples of larger systems I worked on: clan/economy systems: roles, permissions, auction, shop, warehouse, ranks, seasons, history; PvP/event-like systems: territory/conquest mechanics, rankings, rewards, schedules; hunt pass / season pass / progression systems; account panel / web API for a game project; launcher backend, token-login flow, updater tooling; parsers and analyzers for game/client data; internal testing tools for server-side validation.   I can work with Git, separate branches, commits, pull/merge requests or patches, depending on your workflow. For tasks I usually provide a short note about what was changed and what should be tested.   Format: hourly: 15-20 USD/hour, depending on the task; fixed price per task after checking the requirements/code; small task: from 15 USD; payment: USDT; no revenue share and no unpaid test tasks; a small paid task is usually the best way to check quality and communication first. Contact: Discord: @stroke_dan Telegram @castirom
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..