Jump to content
  • 0

Anti-KS System


Statique

Question

It is very annoying usually in server with farming zones and mobs which they won't die easily when the player is about to kill it someone else comes up makes the last hit and takes the reward. Can somehow make a way to give the reward to the player which has the player on him which means if I keep hitting a mob it faces me and hits me if somebody else comes and starts hitting if his damage is more that mine he will take the mob toward him and the mob will start hitting him instead of me, what I want to do that the reward from the mob should take the person who has the mob on him which means that the reward should go to the player who has the mob on him and hits him.

 

confusing...

 

thanks in advance...

Link to comment
Share on other sites

Recommended Posts

  • 0

i update that script becouse on that last if player will attack by pole or with mass skill then he will get some bugs, now it will work good:

Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/config/l2jmods.properties
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/config/l2jmods.properties	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/config/l2jmods.properties	(working copy)
@@ -256,4 +256,8 @@
# This option will enable core support for:
# Mana Drug (item ID 726), using skill ID 9007.
# Mana Potion (item ID 728), using skill ID 9008.
-EnableManaPotionSupport = False
\ No newline at end of file
+EnableManaPotionSupport = False
+
+#KS Protected moobs id
+#Format: moobId1,moobid2
+KsProtectedMoobs = 20001,20002
\ No newline at end of file
Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/model/actor/L2Npc.java
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/model/actor/L2Npc.java	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/model/actor/L2Npc.java	(working copy)
@@ -19,9 +19,12 @@
import java.text.DateFormat;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.Vector;
import java.util.logging.Level;

import javolution.util.FastList;
+import javolution.util.FastMap;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.SevenSigns;
import net.sf.l2j.gameserver.SevenSignsFestival;
@@ -161,6 +164,9 @@
	private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
	private int _currentCollisionHeight; // used for npc grow effect skills
	private int _currentCollisionRadius; // used for npc grow effect skills
+	
+	public L2PcInstance[] _attackedBy;
+	public Double[] _attackedByDmg;

	/** Task launching the function onRandomAnimation() */
	protected class RandomAnimationTask implements Runnable
@@ -2457,6 +2463,17 @@
	@Override
	public boolean doDie(L2Character killer)
	{
+		if(Config.KS_PROTECT_MOOBS.contains(this.getNpcId()))
+		{
+			double bestDmg = 0;
+			for(int i=0;i<_attackedBy.length;i++)
+				if (_attackedByDmg[i] > bestDmg)
+				{
+					bestDmg = _attackedByDmg[i];
+					killer = _attackedBy[i];
+				}
+		}
+
		if (!super.doDie(killer))
			return false;

Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/skills/Formulas.java
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/skills/Formulas.java	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/skills/Formulas.java	(working copy)
@@ -32,6 +32,7 @@
import net.sf.l2j.gameserver.model.actor.L2Summon;
import net.sf.l2j.gameserver.model.actor.instance.L2CubicInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
+import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
import net.sf.l2j.gameserver.model.base.PlayerState;
@@ -1269,6 +1270,26 @@
				damage *= attacker.calcStat(Stats.PVP_PHYS_SKILL_DMG, 1, null, null);	
		}

+		if((attacker instanceof L2PcInstance) && (target instanceof L2Npc))
+		{
+			L2PcInstance player = ((L2PcInstance)attacker);
+			L2NpcInstance moob = ((L2NpcInstance)target);
+			
+			if(moob._attackedBy.equals(player))
+			{
+				for(int i=0;i<moob._attackedBy.length;i++)
+				{
+					if(moob._attackedBy[i] == player)
+						moob._attackedByDmg[i] += damage;
+				}
+			}
+			else
+			{
+				moob._attackedBy[moob._attackedBy.length] = player;
+				moob._attackedByDmg[moob._attackedByDmg.length] = damage;
+			}
+		}	
+		
		return damage < 1 ? 1. : damage;
	}
	/** Calculated damage caused by ATTACK of attacker on target,
@@ -1490,6 +1511,26 @@

		damage *= calcElemental(attacker, target, skill);

+		if((attacker instanceof L2PcInstance) && (target instanceof L2Npc))
+		{
+			L2PcInstance player = ((L2PcInstance)attacker);
+			L2NpcInstance moob = ((L2NpcInstance)target);
+			
+			if(moob._attackedBy.equals(player))
+			{
+				for(int i=0;i<moob._attackedBy.length;i++)
+				{
+					if(moob._attackedBy[i] == player)
+						moob._attackedByDmg[i] += damage;
+				}
+			}
+			else
+			{
+				moob._attackedBy[moob._attackedBy.length] = player;
+				moob._attackedByDmg[moob._attackedByDmg.length] = damage;
+			}
+		}	
+		
		return damage;
	}

@@ -1596,6 +1637,26 @@

		damage *= calcElemental(attacker, target, skill); 

+		if((attacker instanceof L2PcInstance) && (target instanceof L2Npc))
+		{
+			L2PcInstance player = ((L2PcInstance)attacker);
+			L2NpcInstance moob = ((L2NpcInstance)target);
+			
+			if(moob._attackedBy.equals(player))
+			{
+				for(int i=0;i<moob._attackedBy.length;i++)
+				{
+					if(moob._attackedBy[i] == player)
+						moob._attackedByDmg[i] += damage;
+				}
+			}
+			else
+			{
+				moob._attackedBy[moob._attackedBy.length] = player;
+				moob._attackedByDmg[moob._attackedByDmg.length] = damage;
+			}
+		}
+		
		return damage;
	}

@@ -1659,6 +1720,26 @@

		damage *= calcElemental(owner, target, skill);

+		if(target instanceof L2Npc)
+		{
+			L2PcInstance player = attacker.getOwner();
+			L2NpcInstance moob = ((L2NpcInstance)target);
+			
+			if(moob._attackedBy.equals(player))
+			{
+				for(int i=0;i<moob._attackedBy.length;i++)
+				{
+					if(moob._attackedBy[i] == player)
+						moob._attackedByDmg[i] += damage;
+				}
+			}
+			else
+			{
+				moob._attackedBy[moob._attackedBy.length] = player;
+				moob._attackedByDmg[moob._attackedByDmg.length] = damage;
+			}
+		}
+		
		return damage;
	}

Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/Config.java
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/Config.java	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/Config.java	(working copy)
@@ -616,6 +616,7 @@
	public static boolean OFFLINE_SET_NAME_COLOR;
	public static int OFFLINE_NAME_COLOR;
	public static boolean L2JMOD_ENABLE_MANA_POTIONS_SUPPORT;
+	public static List<Integer> KS_PROTECT_MOOBS = new ArrayList<Integer>();


	//--------------------------------------------------
@@ -2014,6 +2015,20 @@
					OFFLINE_NAME_COLOR = Integer.decode("0x" + L2JModSettings.getProperty("OfflineNameColor", "808080"));

					L2JMOD_ENABLE_MANA_POTIONS_SUPPORT = Boolean.parseBoolean(L2JModSettings.getProperty("EnableManaPotionSupport", "false"));
+				
+					String[] propertySplit = L2JModSettings.getProperty("KsProtectedMoobs", "0").split(",");
+					for(String moobId: propertySplit)
+					{
+						try
+						{
+							KS_PROTECT_MOOBS.add(Integer.parseInt(moobId));
+						}
+						catch (NumberFormatException nfe)
+						{
+							if (propertySplit.length > 0)
+								_log.warning("Error in load config.");
+						}
+					}
				}
				catch (Exception e)
				{

Link to comment
Share on other sites

  • 0

ok then i w8 for description of errors when you test

 

Well I tried to adapt it to the l2jfree-core rev. 8089 (where I need it) but im getting this error somehow (???):

 

SEVERE [21 Mar 13:26:21,155] com.l2jfree.gameserver.model.actor.L2Npc.onAction():

java.lang.ClassCastException: com.l2jfree.gameserver.model.actor.instance.L2MonsterInstance cannot be cast to com.l2jfree.gameserver.model.actor.instance.L2NpcInstance

at com.l2jfree.gameserver.skills.Formulas.calcPhysDam(Formulas.java:1526)

at com.l2jfree.gameserver.model.actor.L2Character.doAttackHitByBow(L2Character.java:1190)

at com.l2jfree.gameserver.model.actor.L2Character.doAttack(L2Character.java:1041)

at com.l2jfree.gameserver.model.actor.L2Character$AIAccessor.doAttack(L2Character.java:3717)

at com.l2jfree.gameserver.model.actor.instance.L2PcInstance$AIAccessor.doAttack(L2PcInstance.java:442)

at com.l2jfree.gameserver.ai.L2PlayerAI.thinkAttack(L2PlayerAI.java:92)

at com.l2jfree.gameserver.ai.L2PlayerAI.onEvtThink(L2PlayerAI.java:213)

at com.l2jfree.gameserver.ai.AbstractAI.notifyEvent(AbstractAI.java:546)

at com.l2jfree.gameserver.ai.AbstractAI.notifyEvent(AbstractAI.java:518)

at com.l2jfree.gameserver.ai.L2CharacterAI.onIntentionAttack(L2CharacterAI.java:212)

at com.l2jfree.gameserver.ai.AbstractAI.setIntention(AbstractAI.java:404)

at com.l2jfree.gameserver.ai.AbstractAI.setIntention(AbstractAI.java:355)

at com.l2jfree.gameserver.model.actor.L2Npc.onAction(L2Npc.java:670)

at com.l2jfree.gameserver.network.clientpackets.Action.runImpl(Action.java:105)

at com.l2jfree.mmocore.network.ReceivablePacket.run(ReceivablePacket.java:64)

at com.l2jfree.util.concurrent.ExecuteWrapper.execute(ExecuteWrapper.java:59)

at com.l2jfree.gameserver.threadmanager.FIFORunnableQueue.removeAndExecuteFirst(FIFORunnableQueue.java:28)

at com.l2jfree.gameserver.threadmanager.FIFOExecutableQueue.run(FIFOExecutableQueue.java:73)

at com.l2jfree.util.concurrent.ExecuteWrapper.execute(ExecuteWrapper.java:59)

at com.l2jfree.util.concurrent.ExecuteWrapper.run(ExecuteWrapper.java:40)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:619)

 

But I will try it with l2j rev. 4014 now to see if it works there.

 

Not working too..

 

java.lang.ClassCastException: com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance cannot be cast to com.l2jserver.gameserver.model.actor.instance.L2

NpcInstance

       at com.l2jserver.gameserver.skills.Formulas.calcPhysDam(Formulas.java:1600)

       at com.l2jserver.gameserver.model.actor.L2Character.doAttackHitByBow(L2Character.java:1041)

       at com.l2jserver.gameserver.model.actor.L2Character.doAttack(L2Character.java:930)

       at com.l2jserver.gameserver.model.actor.L2Character$AIAccessor.doAttack(L2Character.java:3438)

       at com.l2jserver.gameserver.model.actor.instance.L2PcInstance$AIAccessor.doAttack(L2PcInstance.java:353)

       at com.l2jserver.gameserver.ai.L2PlayerAI.thinkAttack(L2PlayerAI.java:251)

       at com.l2jserver.gameserver.ai.L2PlayerAI.onEvtThink(L2PlayerAI.java:346)

       at com.l2jserver.gameserver.ai.AbstractAI.notifyEvent(AbstractAI.java:419)

       at com.l2jserver.gameserver.ai.AbstractAI.notifyEvent(AbstractAI.java:362)

       at com.l2jserver.gameserver.ai.L2CharacterAI.onIntentionAttack(L2CharacterAI.java:261)

       at com.l2jserver.gameserver.ai.L2PlayableAI.onIntentionAttack(L2PlayableAI.java:97)

       at com.l2jserver.gameserver.ai.AbstractAI.setIntention(AbstractAI.java:310)

       at com.l2jserver.gameserver.ai.AbstractAI.setIntention(AbstractAI.java:250)

       at handlers.actionhandlers.L2NpcAction.action(L2NpcAction.java:103)

       at com.l2jserver.gameserver.model.actor.L2Character.onAction(L2Character.java:2422)

       at com.l2jserver.gameserver.model.L2Object.onAction(L2Object.java:256)

       at com.l2jserver.gameserver.network.clientpackets.Action.runImpl(Action.java:126)

       at com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket.run(L2GameClientPacket.java:92)

       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

       at java.lang.Thread.run(Thread.java:619)

Link to comment
Share on other sites

  • 0

in free time i will change it on l2jfree for you

 

Wow very nice. :-)

 

I couldn't hit the mobs. Try it yourself if you can... please...

 

Exactly this happens when you add this patch and the error what I posted earlier appears in the server log.

Link to comment
Share on other sites

  • 0

ok i FIXED and TESTED that, work very good ;]

Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/config/l2jmods.properties
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/config/l2jmods.properties	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/config/l2jmods.properties	(working copy)
@@ -256,4 +256,8 @@
# This option will enable core support for:
# Mana Drug (item ID 726), using skill ID 9007.
# Mana Potion (item ID 728), using skill ID 9008.
-EnableManaPotionSupport = False
\ No newline at end of file
+EnableManaPotionSupport = False
+
+#KS Protected moobs id
+#Format: moobId1,moobid2
+KsProtectedMoobs = 20001,20002
\ No newline at end of file
Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/model/actor/L2Npc.java
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/model/actor/L2Npc.java	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/model/actor/L2Npc.java	(working copy)
@@ -17,11 +17,15 @@
import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;

import java.text.DateFormat;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.Vector;
import java.util.logging.Level;

import javolution.util.FastList;
+import javolution.util.FastMap;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.SevenSigns;
import net.sf.l2j.gameserver.SevenSignsFestival;
@@ -161,6 +165,9 @@
	private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
	private int _currentCollisionHeight; // used for npc grow effect skills
	private int _currentCollisionRadius; // used for npc grow effect skills
+	
+	public ArrayList<L2PcInstance> _attackedBy = new ArrayList<L2PcInstance>();
+	public ArrayList<Double> _attackedByDmg = new ArrayList<Double>();

	/** Task launching the function onRandomAnimation() */
	protected class RandomAnimationTask implements Runnable
@@ -2457,6 +2464,20 @@
	@Override
	public boolean doDie(L2Character killer)
	{
+		if(Config.KS_PROTECT_MOOBS.contains(this.getNpcId()))
+		{
+			double bestDmg = 0;
+			for(int i=0;i<_attackedBy.size();i++)
+				if (_attackedByDmg.get(i) > bestDmg)
+				{
+					bestDmg = _attackedByDmg.get(i);
+					killer = _attackedBy.get(i);
+				}
+		}
+
+		_attackedBy.clear();
+		_attackedByDmg.clear();
+		
		if (!super.doDie(killer))
			return false;

Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/skills/Formulas.java
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/skills/Formulas.java	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/gameserver/skills/Formulas.java	(working copy)
@@ -1269,6 +1269,23 @@
				damage *= attacker.calcStat(Stats.PVP_PHYS_SKILL_DMG, 1, null, null);	
		}

+		if((attacker instanceof L2PcInstance) && (target instanceof L2Npc))
+		{
+			L2Npc moob = ((L2Npc)target);
+			if(Config.KS_PROTECT_MOOBS.contains(moob.getNpcId()))
+			{
+				L2PcInstance player = ((L2PcInstance)attacker);
+
+				if(moob._attackedBy.contains(player))
+					moob._attackedByDmg.set(moob._attackedBy.indexOf(player), (moob._attackedByDmg.get(moob._attackedBy.indexOf(player))+damage));
+				else
+				{
+					moob._attackedBy.add(player);
+					moob._attackedByDmg.add(damage);
+				}
+			}
+		}
+		
		return damage < 1 ? 1. : damage;
	}
	/** Calculated damage caused by ATTACK of attacker on target,
@@ -1490,6 +1507,23 @@

		damage *= calcElemental(attacker, target, skill);

+		if((attacker instanceof L2PcInstance) && (target instanceof L2Npc))
+		{
+			L2Npc moob = ((L2Npc)target);
+			if(Config.KS_PROTECT_MOOBS.contains(moob.getNpcId()))
+			{
+				L2PcInstance player = ((L2PcInstance)attacker);
+
+				if(moob._attackedBy.contains(player))
+					moob._attackedByDmg.set(moob._attackedBy.indexOf(player), (moob._attackedByDmg.get(moob._attackedBy.indexOf(player))+damage));
+				else
+				{
+					moob._attackedBy.add(player);
+					moob._attackedByDmg.add(damage);
+				}
+			}
+		}
+		
		return damage;
	}

@@ -1596,6 +1630,23 @@

		damage *= calcElemental(attacker, target, skill); 

+		if((attacker instanceof L2PcInstance) && (target instanceof L2Npc))
+		{
+			L2Npc moob = ((L2Npc)target);
+			if(Config.KS_PROTECT_MOOBS.contains(moob.getNpcId()))
+			{
+				L2PcInstance player = ((L2PcInstance)attacker);
+
+				if(moob._attackedBy.contains(player))
+					moob._attackedByDmg.set(moob._attackedBy.indexOf(player), (moob._attackedByDmg.get(moob._attackedBy.indexOf(player))+damage));
+				else
+				{
+					moob._attackedBy.add(player);
+					moob._attackedByDmg.add(damage);
+				}
+			}
+		}
+		
		return damage;
	}

@@ -1659,6 +1710,23 @@

		damage *= calcElemental(owner, target, skill);

+		if(target instanceof L2Npc)
+		{
+			L2Npc moob = ((L2Npc)target);
+			if(Config.KS_PROTECT_MOOBS.contains(moob.getNpcId()))
+			{
+				L2PcInstance player = attacker.getOwner();
+
+				if(moob._attackedBy.contains(player))
+					moob._attackedByDmg.set(moob._attackedBy.indexOf(player), (moob._attackedByDmg.get(moob._attackedBy.indexOf(player))+damage));
+				else
+				{
+					moob._attackedBy.add(player);
+					moob._attackedByDmg.add(damage);
+				}
+			}
+		}
+		
		return damage;
	}

Index: C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/Config.java
===================================================================
--- C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/Config.java	(revision 4013)
+++ C:/Program Files/Eclipse/workspace/L2_GameServer_T2.3_2x/java/net/sf/l2j/Config.java	(working copy)
@@ -616,6 +616,7 @@
	public static boolean OFFLINE_SET_NAME_COLOR;
	public static int OFFLINE_NAME_COLOR;
	public static boolean L2JMOD_ENABLE_MANA_POTIONS_SUPPORT;
+	public static List<Integer> KS_PROTECT_MOOBS = new ArrayList<Integer>();


	//--------------------------------------------------
@@ -2014,6 +2015,20 @@
					OFFLINE_NAME_COLOR = Integer.decode("0x" + L2JModSettings.getProperty("OfflineNameColor", "808080"));

					L2JMOD_ENABLE_MANA_POTIONS_SUPPORT = Boolean.parseBoolean(L2JModSettings.getProperty("EnableManaPotionSupport", "false"));
+				
+					String[] propertySplit = L2JModSettings.getProperty("KsProtectedMoobs", "0").split(",");
+					for(String moobId: propertySplit)
+					{
+						try
+						{
+							KS_PROTECT_MOOBS.add(Integer.parseInt(moobId));
+						}
+						catch (NumberFormatException nfe)
+						{
+							if (propertySplit.length > 0)
+								_log.warning("Error in load config.");
+						}
+					}
				}
				catch (Exception e)
				{

Link to comment
Share on other sites

  • 0

all the codes iv seen till now are over exaggerated >.> and the idea of it is confusing.

 

U want some code that will calculate the rewords only to the one who did most dmg? or the one who hit him first?

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