Jump to content

Recommended Posts

Posted

This isnt an event, nor a fantastic npc or voiced command

Its an abstract engine which will allow you to add customize code to many parts of the game where only core mod was the way.

With this, you can modify the most used core parts without touch it (which reduce sync problems)

PD: The code there in the script is just a sample so you can follow it to do whatever you want

PD2: Ofc, the engine can be extended to be called in more placed according to your needs

 

Core patch

Index: java/com/l2jserver/gameserver/handler/IScriptHandler.java
===================================================================
--- java/com/l2jserver/gameserver/handler/IScriptHandler.java	(revision 0)
+++ java/com/l2jserver/gameserver/handler/IScriptHandler.java	(revision 0)
@@ -0,0 +1,29 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.handler;
+
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public interface IScriptHandler
+{
+	public CallSite getCallSite();
+	public void execute(L2PcInstance activeChar, L2Character enemy);
+}
Index: java/com/l2jserver/gameserver/handler/ScriptHandler.java
===================================================================
--- java/com/l2jserver/gameserver/handler/ScriptHandler.java	(revision 0)
+++ java/com/l2jserver/gameserver/handler/ScriptHandler.java	(revision 0)
@@ -0,0 +1,77 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.handler;
+
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+import javolution.util.FastMap;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class ScriptHandler
+{	
+	public enum CallSite
+	{
+		// Entering to server
+		ON_ENTER,
+		// Killing any L2Character instance
+		ON_KILL,
+		// Dyeing
+		ON_DEATH,
+		// When revive
+		ON_RESS,
+		// Exiting from server
+		ON_EXIT,
+	}
+	
+	private static FastMap<CallSite, IScriptHandler> _handler;
+	
+	private ScriptHandler()
+	{
+		if(_handler == null)
+			_handler = new FastMap<CallSite, IScriptHandler>();
+	}
+	
+	public static ScriptHandler getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	public void registerHandler(IScriptHandler handler)
+	{
+		CallSite site = handler.getCallSite();
+		_handler.put(site, handler);
+	}
+	
+	public void execute(CallSite site, L2PcInstance activeChar, L2Character enemy)
+	{
+		IScriptHandler handler = _handler.get(site);
+		if(handler != null)
+			handler.execute(activeChar, enemy);
+	}
+	
+	public int size()
+	{
+		return _handler.size();
+	}
+	
+	private static final class SingletonHolder
+	{
+		private static final ScriptHandler _instance = new ScriptHandler();
+	}
+}
Index: java/com/l2jserver/gameserver/model/actor/L2Character.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/L2Character.java	(revision 4330)
+++ java/com/l2jserver/gameserver/model/actor/L2Character.java	(working copy)
@@ -44,7 +44,9 @@
import com.l2jserver.gameserver.datatables.SkillTable;
import com.l2jserver.gameserver.datatables.MapRegionTable.TeleportWhereType;
import com.l2jserver.gameserver.handler.ISkillHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler;
import com.l2jserver.gameserver.handler.SkillHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
import com.l2jserver.gameserver.instancemanager.InstanceManager;
import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
@@ -2160,6 +2162,8 @@
		{
			_log.log(Level.SEVERE, "deleteMe()", e);
		}
+		if(killer instanceof L2PcInstance)
+			ScriptHandler.getInstance().execute(CallSite.ON_KILL, (L2PcInstance)killer, this);
		return true;
	}

Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(revision 4330)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(working copy)
@@ -76,6 +76,8 @@
import com.l2jserver.gameserver.datatables.SkillTreeTable;
import com.l2jserver.gameserver.handler.IItemHandler;
import com.l2jserver.gameserver.handler.ItemHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
import com.l2jserver.gameserver.instancemanager.CastleManager;
import com.l2jserver.gameserver.instancemanager.CoupleManager;
@@ -5455,7 +5457,7 @@
			L2PcInstance pk = killer.getActingPlayer();

			TvTEvent.onKill(killer, this);
-			
+			ScriptHandler.getInstance().execute(CallSite.ON_DEATH, this, pk);
			if (atEvent && pk != null)
			{
				pk.kills.add(getName());
@@ -11037,6 +11039,7 @@
			if (!DimensionalRiftManager.getInstance().checkIfInPeaceZone(getX(), getY(), getZ()))
				getParty().getDimensionalRift().memberRessurected(this);
		}
+		ScriptHandler.getInstance().execute(CallSite.ON_RESS, this, null);
	}

	@Override
@@ -11629,6 +11632,15 @@

		try
		{
+			ScriptHandler.getInstance().execute(CallSite.ON_EXIT, this, null);
+		}
+		catch(Exception e)
+		{
+			_log.log(Level.SEVERE, "deleteMe()", e);
+		}
+		
+		try
+		{
			if (isFlying())
			{
				removeSkill(SkillTable.getInstance().getInfo(4289, 1));
Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
===================================================================
--- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(revision 4330)
+++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(working copy)
@@ -30,6 +30,8 @@
import com.l2jserver.gameserver.datatables.GMSkillTable;
import com.l2jserver.gameserver.datatables.MapRegionTable;
import com.l2jserver.gameserver.datatables.SkillTable;
+import com.l2jserver.gameserver.handler.ScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
import com.l2jserver.gameserver.instancemanager.CastleManager;
import com.l2jserver.gameserver.instancemanager.ClanHallManager;
import com.l2jserver.gameserver.instancemanager.CoupleManager;
@@ -493,6 +495,8 @@
			sm.addString(Integer.toString(birthday));
			activeChar.sendPacket(sm);
		}
+		
+		ScriptHandler.getInstance().execute(CallSite.ON_ENTER, activeChar, null);
	}

	/**

 

DP Patch

Index: data/scripts/handlers/MasterHandler.java
===================================================================
--- data/scripts/handlers/MasterHandler.java	(revision 7571)
+++ data/scripts/handlers/MasterHandler.java	(working copy)
@@ -19,6 +19,7 @@
import handlers.bypasshandlers.*;
import handlers.chathandlers.*;
import handlers.itemhandlers.*;
+import handlers.scripthandlers.*;
import handlers.skillhandlers.*;
import handlers.usercommandhandlers.*;
import handlers.voicedcommandhandlers.*;
@@ -31,6 +32,7 @@
import com.l2jserver.gameserver.handler.BypassHandler;
import com.l2jserver.gameserver.handler.ChatHandler;
import com.l2jserver.gameserver.handler.ItemHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler;
import com.l2jserver.gameserver.handler.SkillHandler;
import com.l2jserver.gameserver.handler.UserCommandHandler;
import com.l2jserver.gameserver.handler.VoicedCommandHandler;
@@ -314,6 +316,16 @@
		_log.config("Loaded " + VoicedCommandHandler.getInstance().size() + " VoicedHandlers");
	}

+	private static void loadScriptHandlers()
+	{
+		ScriptHandler.getInstance().registerHandler(new EnterWorld());
+		ScriptHandler.getInstance().registerHandler(new OnDeath());
+		ScriptHandler.getInstance().registerHandler(new OnExit());
+		ScriptHandler.getInstance().registerHandler(new OnKill());
+		ScriptHandler.getInstance().registerHandler(new OnRess());
+		_log.config("Loaded " + ScriptHandler.getInstance().size() + " ScriptHandlers");
+	}
+	
	/**
	 * @param args
	 */
@@ -329,6 +341,7 @@
		loadSkillHandlers();
		loadUserHandlers();
		loadVoicedHandlers();
+		loadScriptHandlers();
		_log.config("Handlers Loaded...");
	}
}
\ No newline at end of file
Index: data/scripts/handlers/scripthandlers/EnterWorld.java
===================================================================
--- data/scripts/handlers/scripthandlers/EnterWorld.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/EnterWorld.java	(revision 0)
@@ -0,0 +1,41 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.Announcements;
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class EnterWorld implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute()
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		activeChar.sendMessage("This is a test and damn it works!");
+		activeChar.setHero(true);
+		
+		if(activeChar.isGM())
+			Announcements.getInstance().announceToAll("GM "+activeChar.getName()+" has logged in!");
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		return CallSite.ON_ENTER;
+	}
+	
+}
Index: data/scripts/handlers/scripthandlers/OnDeath.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnDeath.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnDeath.java	(revision 0)
@@ -0,0 +1,47 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.Announcements;
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnDeath implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		activeChar.sendMessage("This is a test and damn, it works!");
+		if(enemy instanceof L2PcInstance)
+		{
+			L2PcInstance enem = (L2PcInstance)enemy;
+			enem.sendMessage("ffs");
+			if(enem.getKarma() > 0)
+				Announcements.getInstance().announceToAll(enem.getName()+" is PK!, Go get his stuff!");
+		}
+		else
+			enemy.doDie(activeChar);
+		activeChar.doRevive();
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		return CallSite.ON_DEATH;
+	}
+	
+}
Index: data/scripts/handlers/scripthandlers/OnExit.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnExit.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnExit.java	(revision 0)
@@ -0,0 +1,37 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnExit implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, com.l2jserver.gameserver.model.actor.L2Character)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		// TODO Auto-generated method stub
+		activeChar.sendMessage("Thanks for playing our server! You are welcome anytime.");
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		// TODO Auto-generated method stub
+		return CallSite.ON_EXIT;
+	}
+}
Index: data/scripts/handlers/scripthandlers/OnKill.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnKill.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnKill.java	(revision 0)
@@ -0,0 +1,38 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnKill implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, com.l2jserver.gameserver.model.actor.L2Character)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		// TODO Auto-generated method stub
+		activeChar.sendMessage(activeChar.getName()+ " what did you just do !? You are an assasin!");
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		// TODO Auto-generated method stub
+		return CallSite.ON_KILL;
+	}
+	
+}
Index: data/scripts/handlers/scripthandlers/OnRess.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnRess.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnRess.java	(revision 0)
@@ -0,0 +1,39 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnRess implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, com.l2jserver.gameserver.model.actor.L2Character)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		activeChar.setCurrentHp(activeChar.getMaxHp());
+		activeChar.setCurrentMp(activeChar.getMaxMp());
+		activeChar.setCurrentCp(activeChar.getMaxCp());
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		// TODO Auto-generated method stub
+		return CallSite.ON_RESS;
+	}
+	
+}

 

Posted

AWSOME MANY I LOVE YOU :D

 

now i can unhardcode every costum check i had also every events check can be done in a dp handler pure awsomeness :D

 

PS.: is it tested or still w8 for testing?

Posted

@Gabor:

 

Index: data/scripts/handlers/scripthandlers/OnDeath.java

===================================================================

--- data/scripts/handlers/scripthandlers/OnDeath.java (revision 0)

+++ data/scripts/handlers/scripthandlers/OnDeath.java (revision 0)

@@ -0,0 +1,47 @@

+/**

+ *

+ */

+package handlers.scripthandlers;

+

+import com.l2jserver.gameserver.Announcements;

+import com.l2jserver.gameserver.handler.IScriptHandler;

+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;

+import com.l2jserver.gameserver.model.actor.L2Character;

+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;

+

+/**

+ * @author BiggBoss

+ *

+ */

+public class OnDeath implements IScriptHandler

+{

+

+ /* (non-Javadoc)

+ * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance)

+ */

+ @Override

+ public void execute(L2PcInstance activeChar, L2Character enemy)

+ {

+ activeChar.sendMessage("This is a test and damn, it works!");

+ if(enemy instanceof L2PcInstance)

+ {

+ L2PcInstance enem = (L2PcInstance)enemy;

+ enem.sendMessage("ffs");

+ if(enem.getKarma() > 0)

+ Announcements.getInstance().announceToAll(enem.getName()+" is PK!, Go get his stuff!");

+ }

+ else

+ enemy.doDie(activeChar);

+ activeChar.doRevive();

+ }

+

+ /* (non-Javadoc)

+ * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()

+ */

+ @Override

+ public CallSite getCallSite()

+ {

+ return CallSite.ON_DEATH;

+ }

+

+}

Posted

Well Thank you, but i don`t rly got what this code is for could you explain better?

makes server core a little bit more abstract

btw, thx all  :)

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

    • Inventory restock: Premium business accounts are now available.   ✔ Wallester Business EU 🇪🇺|💳 Unlimited virtual cards, physical cards, 🏦 multi-currency IBAN, ₿ crypto & stablecoin deposits. ✔ Stripe Business UK 🇬🇧|💳 Instant virtual cards (Visa/Mastercard), high-conversion checkout, multi-currency payouts, ₿ crypto payments, no-code payment links. ✔ Mercury Business US 🇺🇸|🏦 US checking & savings, 💳 unlimited virtual cards, domestic & International wires, native stablecoin settlement. ✔ Payset Business EU 🇪🇺|🏦 Multiple IBANs, UK sort code, SEPA Instant, 💳 unlimited virtual cards, multi-currency accounts. ✔ Novo Business US 🇺🇸|🏦 Business checking account, ACH payments & invoicing, 💳 virtual & physical cards, novo boost.
    • Let me see if I understand correctly, older gentlemen, when a newcomer shows up to create modern things with the help of AI, doing what you charge them to do, you point the finger and laugh. I believe that's why everything is stagnant. The product isn't for programming experts, it's for newcomers. Don't buy from you if they can do it themselves using this base. You're going to deliver a similar product, maybe even worse than this one, so why are you complaining? PowerShell, as you well know, started with it, then came new platforms and new apps, new creation models, all with different languages; I chose the simplest one for my taste. This is about being organized and knowing how to choose the right words for each situation. It's not 100%, but it already gives a good impression. Nothing is 100%, so a topic written by AI, and all the code that you charge an absurd amount for to prohibit and sell hacks, could be open source so that everyone can create new practices, new models, new information for passing packets, prohibiting the use of cheats that cause server owners to break so much. Let's remember that the Admin doesn't always shut down the server; it's the players who find problems and take advantage by buying and reselling items, and they say that the GM shuts down the server every week, but that's a lie. What they do is duplicate items with packages and sell them, but perhaps this could give some future developers a starting point to create their own protection following the model in the initial documentation. Because none of you answer a question from a newbie, you think you're superior because you have knowledge, but with AI, people like that can have the same knowledge as you, but with less practice. And if they practice a lot, 10,000 hours, they can be as good as all of you older developers in the L2J field.
    • ✨ Exclusive Offer for Marketplace Growth 🔥 Elevate your performance with a premium bonus. 💲 Top up your balance with $100 or more and receive an additional $5 credit — seamlessly added to your account. ⭐️ Designed for those who value efficiency, scale, and results. ⚡️ Effortless. Refined. Effective. 💥 Enhance your strategy today 💥
  • 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..