Jump to content

Recommended Posts

Posted

Had a big issue with afkers in my tvt event, so I whipped this up really quick. Only Tested on Freya, maybe will work on Hi5, maybe not.

 

It checks every 1 min(default setting), if tvt is started or not. If it is, it then checks every player in tvt, x/y/z locations and if they are fighting or casting, every 1 min.  If the player has been in the same x/y/z location and not fighting/casting 4 times(default setting) in a row, it simply boots them from the server.

 

Ran on live server 6+ months with no problems and flawlessly. Only works on servers that don't have massive spawn killing at tvt events(because of random offset respawn). This one uses no database connections.

 

This script requires one SMALL core patch.

In CORE com.l2jserver.gameserver.model.entity.TvTEvent.java file, find near the TOP of the code this line..

 
    private static TvTEventTeam[] _teams = new TvTEventTeam[2];

And change it to this

 
    public static TvTEventTeam[] _teams = new TvTEventTeam[2];

Now rebuild and install your new l2jserver.jar.

 

Create a new folder named AntiAfk in your server files under gameserver/data/scripts/custom and put this script into it.

AntiAfkTvt.java

package custom.AntiAfk;

import java.util.ArrayList;
import java.util.logging.Logger;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.TvTEvent;
import com.l2jserver.gameserver.model.entity.TvTEventTeam;

/** 
*
* @author Phear3d
*/

public class AntiAfkTvt
{
    // Debug
    private static boolean debug = false;
    // Delay between location checks , Default 60000 ms (1 minute)
    private final int CheckDelay = 30000;
   
    private static Logger _log = Logger.getLogger(AntiAfkTvt.class.getName());
private static ArrayList<String> TvTPlayerList = new ArrayList<String>();
private static String[] Splitter;
private static int xx,yy,zz,SameLoc;
private static L2PcInstance _player;

   private AntiAfkTvt()
   {
       _log.info("AntiAfkTvt: Auto-Kick AFK in TVT System initiated.");
       ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AntiAfk(), 60000, CheckDelay);
   }

   private class AntiAfk implements Runnable
   {
       public void run()
       {
     	  if (TvTEvent.isStarted())
     	  {
     		  // Iterate over all teams
     		  for (TvTEventTeam team : TvTEvent._teams)
     		  {
     			  // Iterate over all participated player instances in this team
     			  for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
     			  {
     				  if (playerInstance != null && playerInstance.isOnline())
     				  {
     					  _player = playerInstance;
     					  AddTvTSpawnInfo(playerInstance.getName(),playerInstance.getX(),playerInstance.getY(),playerInstance.getZ());
     					  if (debug)
     						  System.err.println("TvT Player: " + playerInstance.getName() + " " + playerInstance.getX() + " " +  playerInstance.getY() + " " +  playerInstance.getZ());
     				  }
     			  }
     		  }
     	  }
     	  else
     	  {
     		  TvTPlayerList.clear();
     	  }
       }
   }
   
private static void AddTvTSpawnInfo(String name, int _x, int _y, int _z)
{
	if(!CheckTvTSpawnInfo(name))
	{
		String temp = name + ":" + Integer.toString(_x) + ":" + Integer.toString(_y) + ":" + Integer.toString(_z) + ":1";
		TvTPlayerList.add(temp);
	}
	else
	{
        Object[] elements = TvTPlayerList.toArray();
        for(int i=0; i < elements.length ; i++)
        {
        	Splitter = ((String) elements[i]).split(":");
        	String nameVal = Splitter[0];
		       if (name.equals(nameVal))
		       {
		    	   GetTvTSpawnInfo(name);
		    	   if (_x == xx && _y == yy && _z == zz && _player.isAttackingNow() == false && _player.isCastingNow() == false && _player.isOnline() == true && _player.isParalyzed() == false)
		    	   {
		    		   ++SameLoc;
		    		   if (SameLoc >= 4)//Kick after 4 same x/y/z, location checks
		    		   {
		    			   //kick here
		    			   TvTPlayerList.remove(i);
		    			   _player.logout();
		    			   return;
		    		   }
		    		   else
		    		   {
		    			   TvTPlayerList.remove(i);
		    			   String temp = name + ":" + Integer.toString(_x) + ":" + Integer.toString(_y) + ":" + Integer.toString(_z) + ":" + SameLoc;
		    			   TvTPlayerList.add(temp);
		    			   return;
		    		   }
		    	   }
		    	   TvTPlayerList.remove(i);
				   String temp = name + ":" + Integer.toString(_x) + ":" + Integer.toString(_y) + ":" + Integer.toString(_z) + ":1";
				   TvTPlayerList.add(temp);
		       }
        }
	}
}

private static boolean CheckTvTSpawnInfo(String name)
{

        Object[] elements = TvTPlayerList.toArray();
        for(int i=0; i < elements.length ; i++)
        {
        	Splitter = ((String) elements[i]).split(":");
        	String nameVal = Splitter[0];
	       if (name.equals(nameVal))
	       {
		       return true;
	       }
        }
        return false;
}

private static void GetTvTSpawnInfo(String name)
{

        Object[] elements = TvTPlayerList.toArray();
        for(int i=0; i < elements.length ; i++)
        {
        	Splitter = ((String) elements[i]).split(":");
        	String nameVal = Splitter[0];
	       if (name.equals(nameVal))
	       {
		       xx = Integer.parseInt(Splitter[1]);
		       yy = Integer.parseInt(Splitter[2]);
		       zz = Integer.parseInt(Splitter[3]);
		       SameLoc = Integer.parseInt(Splitter[4]);
	       }
        }
}

   public static AntiAfkTvt getInstance()
   {
       return SingletonHolder._instance;
   }

   @SuppressWarnings("synthetic-access")
   private static class SingletonHolder
   {
       protected static final AntiAfkTvt _instance = new AntiAfkTvt();
   }

   public static void main(String[] args)
   {
   AntiAfkTvt.getInstance();
   }
}

 

Finally, edit your scripts.cfg file and add.......

 
custom/AntiAfk/AntiAfkTvt.java

Posted

In the code it checks every 30000 ms so 30 seconds  not  1 minute

 

indeed. Copy/pasted the post from my original post on l2jserver forums to here, and my current live code (which has been adjusted a little)

8)

 

that is why it says "It checks every 1 min(default setting)" , in the code also.. ;)

Posted

If you are afk that very specific momment of check, i mean: u play but u stay afk 2 sec, and in those 2 sec the check takes place, you are considered afk? if yes fail bad coded trash, otherwise a very good one

Posted

If you are afk that very specific momment of check, i mean: u play but u stay afk 2 sec, and in those 2 sec the check takes place, you are considered afk? if yes fail bad coded trash!!!

 

It checks every 1 min(default setting), if tvt is started or not. If it is, it then checks every player in tvt, x/y/z locations and if they are fighting or casting, every 1 min.  If the player has been in the same x/y/z location and not fighting/casting 4 times(default setting) in a row, it simply boots them from the server.

  • 6 months later...
  • SweeTs locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...