Jump to content
  • 0

Question about heroes


ChaoticLegend

Question

well, is there any way for doing a player permanent hero in the server? in any way either from navicat or from files of the server? or maybe is there any code for doing this? server is freya. thanks

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

I didn't checked at all, but you surely need to recode some parts, because hero table is cleaned each time Olympiad occurs...

 

Baiscally, heroes are put heroes in EnterWorld, using database entries.

 

In the "hero clean section when olympiad occurs" you have to add a special symbol in an existing column "if column blabla == 999 don't delete the line", or to add a new column.

Link to comment
Share on other sites

  • 0

should be

 

setHero(true)

 

example :

 

if (!isHero() && getLevel() == 80)

{

setHero(true);

rewardSkills();

}

 

just an example

 

 

sorry did misunderstood your question. try as matim said

Link to comment
Share on other sites

  • 0

the only "code" which exists for heroes into enterworld is this one

// Set Hero status if it applies

if (Hero.getInstance().getHeroes() != null && Hero.getInstance().getHeroes().containsKey(activeChar.getObjectId()))

activeChar.setHero(true);

 

setPledgeClass(activeChar);

 

so, what do you mean tryskell by adding a special symbol in an existing column? there isnt any column same as you told...

as for creating a new column, i didnt understand exactly what you mean matim...

Link to comment
Share on other sites

  • 0

Index: java/com/l2jserver/gameserver/GameServer.java
===================================================================
--- java/com/l2jserver/gameserver/GameServer.java	(revision 4492)
+++ java/com/l2jserver/gameserver/GameServer.java	(working copy)
@@ -41,6 +41,7 @@
import com.l2jserver.gameserver.datatables.CharNameTable;
import com.l2jserver.gameserver.datatables.CharTemplateTable;
import com.l2jserver.gameserver.datatables.ClanTable;
+import com.l2jserver.gameserver.datatables.CustomHeroTable;
import com.l2jserver.gameserver.datatables.DoorTable;
import com.l2jserver.gameserver.datatables.EnchantGroupsTable;
import com.l2jserver.gameserver.datatables.EnchantHPBonusData;
@@ -405,6 +406,7 @@

		TvTManager.getInstance();
		KnownListUpdateTaskManager.getInstance();
+		CustomHeroTable.getInstance();

		if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
			OfflineTradersTable.restoreOfflineTraders();
Index: java/com/l2jserver/gameserver/Shutdown.java
===================================================================
--- java/com/l2jserver/gameserver/Shutdown.java	(revision 4492)
+++ java/com/l2jserver/gameserver/Shutdown.java	(working copy)
@@ -21,6 +21,7 @@
import com.l2jserver.Config;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.datatables.ClanTable;
+import com.l2jserver.gameserver.datatables.CustomHeroTable;
import com.l2jserver.gameserver.datatables.OfflineTradersTable;
import com.l2jserver.gameserver.instancemanager.CastleManorManager;
import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
@@ -539,6 +540,8 @@
		ClanTable.getInstance().storeClanScore();
		_log.info("Clan System: Data saved!!");

+		CustomHeroTable.getInstance().saveHeros();
+		
		// Save Cursed Weapons data before closing.
		CursedWeaponsManager.getInstance().saveData();

Index: java/com/l2jserver/gameserver/datatables/CustomHeroTable.java
===================================================================
--- java/com/l2jserver/gameserver/datatables/CustomHeroTable.java	(revision 0)
+++ java/com/l2jserver/gameserver/datatables/CustomHeroTable.java	(revision 0)
@@ -0,0 +1,127 @@
+package com.l2jserver.gameserver.datatables;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.l2jserver.L2DatabaseFactory;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+public class CustomHeroTable
+{
+	private static final class SingletonHolder
+	{
+		private static final CustomHeroTable INSTANCE = new CustomHeroTable();
+	}
+	
+	private static final Logger _log = Logger.getLogger(CustomHeroTable.class.getName());
+	
+	private static final String SQL_LOAD_HERO = "SELECT objecId FROM custom_hero";
+	private static final String SQL_DEL_HERO = "DELETE FROM custom_hero";
+	private static final String SQL_SAVE_HERO = "INSERT INTO custom_hero VALUES ( ? )";
+	
+	private Set<Integer> _heros;
+	
+	private CustomHeroTable()
+	{
+		_heros = new HashSet<Integer>();
+		loadHeros();
+	}
+	
+	private final void loadHeros()
+	{
+		Connection con = null;
+		try
+		{
+			con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement st = con.prepareStatement(SQL_LOAD_HERO);
+			ResultSet rset = st.executeQuery();
+			while(rset.next())
+			{
+				final int objId = rset.getInt("objectId");
+				if(!addHero(objId))
+					_log.warning(">>> CustomHeroTable.loadHeros(): Duplicated object id in custom_hero table!");
+			}
+			_log.config("CustomHeroTable: Loaded "+_heros.size()+" custom Heroes!");
+		}
+		catch(SQLException e)
+		{
+			_log.log(Level.SEVERE, "CustomHeroTable.loadHeros()", e);
+		}
+		finally
+		{
+			L2DatabaseFactory.close(con);
+		}
+	}
+	
+	public final void saveHeros()
+	{
+		Connection con = null;
+		try
+		{
+			con = L2DatabaseFactory.getInstance().getConnection();
+			
+			PreparedStatement st = con.prepareStatement(SQL_DEL_HERO);
+			st.execute();
+			st.close();
+			
+			for(int hero : _heros)
+			{
+				PreparedStatement heroSt = con.prepareStatement(SQL_SAVE_HERO);
+				heroSt.setInt(1, hero);
+				heroSt.execute();
+				heroSt.close();
+			}
+			_log.config("CustomHeroTable: Suscessfully saved "+_heros.size()+" custom Heroes to database!");
+		}
+		catch(SQLException e)
+		{
+			_log.log(Level.SEVERE, "CustomHeroTable.saveHeros()", e);
+		}
+		finally
+		{
+			L2DatabaseFactory.close(con);
+		}
+	}
+	
+	public void onEnter(L2PcInstance plr)
+	{
+		if(_heros.contains(plr.getObjectId()))
+			plr.setHero(true);
+	}
+	
+	/*
+	 * Following methods may be used for admin commands
+	 * or the way to become custom hero for example 
+	 */
+	
+	public boolean addHero(L2PcInstance plr)
+	{
+		return addHero(plr.getObjectId());
+	}
+	
+	public boolean addHero(int objectId)
+	{
+		return _heros.add(objectId);
+	}
+	
+	public boolean removeHero(L2PcInstance plr)
+	{
+		return removeHero(plr.getObjectId());
+	}
+	
+	public boolean removeHero(int objectId)
+	{
+		return _heros.remove(objectId);
+	}
+	
+	public static CustomHeroTable getInstance()
+	{
+		return SingletonHolder.INSTANCE;
+	}
+}
Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
===================================================================
--- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(revision 4492)
+++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(working copy)
@@ -27,6 +27,7 @@
import com.l2jserver.gameserver.cache.HtmCache;
import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager;
import com.l2jserver.gameserver.datatables.AdminCommandAccessRights;
+import com.l2jserver.gameserver.datatables.CustomHeroTable;
import com.l2jserver.gameserver.datatables.GMSkillTable;
import com.l2jserver.gameserver.datatables.MapRegionTable;
import com.l2jserver.gameserver.datatables.SkillTable;
@@ -188,6 +189,8 @@
		if (activeChar.getCurrentHp() < 0.5)
			activeChar.setIsDead(true);

+		CustomHeroTable.getInstance().onEnter(activeChar);
+		
		boolean showClanNotice = false;

		// Clan related checks are here

l2jserver, freya last revision

Link to comment
Share on other sites

  • 0

to apply and run this code you have to create a new table in database called custom_hero (with 1 column called objectId (INT, 10))

Those object ids from players who you add there will be permanent heros

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...