Jump to content

Recommended Posts

Posted (edited)

Hi,

 

Admin command, scans a specified range around the admin. It gathers about players within the specified range, including their clan names, party leaders, and class names. Counting all players around can be a helpful task for admins.

You could limit the scanning to players within the same region or zone as the admin - this would reduce the number of players to be processed and improve performance.

image.png

 

Index: /main/L2GoldClassic/dist/game/config/AdminCommands.xml
===================================================================
--- /main/L2GoldClassic/dist/game/config/AdminCommands.xml	(revision 26)
+++ /main/L2GoldClassic/dist/game/config/AdminCommands.xml	(revision 27)
@@ -626,4 +626,5 @@
 	<admin command="admin_scan" accessLevel="100" />
 	<admin command="admin_deleteNpcByObjectId" accessLevel="100" confirmDlg="true" />
+	<admin command="admin_scan_players" accessLevel="50" />
 
 	<!-- ADMIN SERVERINFO -->
Index: /main/L2GoldClassic/dist/game/data/scripts/handlers/MasterHandler.java
===================================================================
--- /main/L2GoldClassic/dist/game/data/scripts/handlers/MasterHandler.java	(revision 26)
+++ /main/L2GoldClassic/dist/game/data/scripts/handlers/MasterHandler.java	(revision 27)
@@ -124,4 +124,5 @@
 import handlers.admincommandhandlers.AdminRide;
 import handlers.admincommandhandlers.AdminScan;
+import handlers.admincommandhandlers.AdminScanPlayers;
 import handlers.admincommandhandlers.AdminServerInfo;
 import handlers.admincommandhandlers.AdminShop;
@@ -463,4 +464,5 @@
 			AdminRide.class,
 			AdminScan.class,
+			AdminScanPlayers.class,
 			AdminServerInfo.class,
 			AdminShop.class,
Index: /main/L2GoldClassic/dist/game/data/scripts/handlers/admincommandhandlers/AdminScanPlayers.java
===================================================================
--- /main/L2GoldClassic/dist/game/data/scripts/handlers/admincommandhandlers/AdminScanPlayers.java	(revision 27)
+++ /main/L2GoldClassic/dist/game/data/scripts/handlers/admincommandhandlers/AdminScanPlayers.java	(revision 27)
@@ -0,0 +1,134 @@
+/*
+ * This file is part of the L2Gold Classic project.
+ * 
+ * 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 handlers.admincommandhandlers;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import gold.lineage2.gameserver.data.sql.ClanTable;
+import gold.lineage2.gameserver.handler.IAdminCommandHandler;
+import gold.lineage2.gameserver.model.Location;
+import gold.lineage2.gameserver.model.World;
+import gold.lineage2.gameserver.model.actor.instance.PlayerInstance;
+import gold.lineage2.gameserver.model.clan.Clan;
+import gold.lineage2.gameserver.util.Util;
+
+/**
+ * @author Trance
+ */
+public class AdminScanPlayers implements IAdminCommandHandler
+{
+	private static final String[] ADMIN_COMMANDS =
+	{
+		"admin_scan_players"
+	};
+	
+	@Override
+	public boolean useAdminCommand(String command, PlayerInstance player)
+	{
+		if (command.startsWith("admin_scan_players"))
+		{
+			String[] args = command.split(" ");
+			if (args.length > 1)
+			{
+				String rangeStr = args[1];
+				scanPlayers(player, rangeStr);
+			}
+			else
+			{
+				player.sendMessage("Usage: //admin_scan_players <range>");
+			}
+		}
+		return true;
+	}
+	
+	private void scanPlayers(PlayerInstance player, String rangeStr)
+	{
+		// Parse the range from the command arguments
+		int range = Util.parseNextInt(rangeStr, 0);
+		
+		// Get the player's location
+		Location playerLocation = player.getLocation();
+		
+		// Initialize data structures for storing the scan results
+		Map<String, Set<String>> clanMembers = new HashMap<>();
+		Map<String, Set<String>> partyMembers = new HashMap<>();
+		Map<String, List<String>> classMembers = new HashMap<>();
+		
+		// Iterate through all players in the game world
+		for (PlayerInstance otherPlayer : World.getInstance().getPlayers())
+		{
+			// Check if the other player is within the specified range of the player
+			if (playerLocation.distanceTo(otherPlayer.getLocation()) <= range)
+			{
+				// Gather data for clans, parties, and classes
+				String clanName = otherPlayer.getClan() != null ? otherPlayer.getClan().getName() : "No Clan";
+				String partyLeaderName = otherPlayer.getParty() != null ? otherPlayer.getParty().getLeader().getName() : null;
+				String className = otherPlayer.getTemplate().getClassId().name();
+				
+				// Update the player lists for clans, parties, and classes
+				clanMembers.computeIfAbsent(clanName, k -> new HashSet<>()).add(otherPlayer.getName());
+				if (partyLeaderName != null)
+				{
+					partyMembers.computeIfAbsent(partyLeaderName, k -> new HashSet<>()).add(otherPlayer.getName());
+				}
+				classMembers.computeIfAbsent(className, k -> new ArrayList<>()).add(otherPlayer.getName());
+			}
+		}
+		
+		// Display the scan results to the player
+		player.sendMessage("Scan Results:");
+		player.sendMessage("Range: " + range);
+		player.sendMessage("Clans (" + clanMembers.size() + "):");
+		for (Map.Entry<String, Set<String>> entry : clanMembers.entrySet())
+		{
+			String clanLeaderName = "Unknown";
+			Clan clan = ClanTable.getInstance().getClanByName(entry.getKey());
+			if (clan != null)
+			{
+				PlayerInstance clanLeader = World.getInstance().getPlayer(clan.getLeaderId());
+				if (clanLeader != null)
+				{
+					clanLeaderName = clanLeader.getName();
+				}
+			}
+			player.sendMessage(" - " + entry.getKey() + " (Leader: " + clanLeaderName + "): " + entry.getValue().size() + " members");
+			player.sendMessage("   Members: " + String.join(", ", entry.getValue()));
+		}
+		player.sendMessage("Parties (" + partyMembers.size() + "):");
+		for (Map.Entry<String, Set<String>> entry : partyMembers.entrySet())
+		{
+			player.sendMessage(" - Leader: " + entry.getKey() + ", " + entry.getValue().size() + " members");
+			player.sendMessage("   Members: " + String.join(", ", entry.getValue()));
+		}
+		player.sendMessage("Classes (" + classMembers.size() + "):");
+		for (Map.Entry<String, List<String>> entry : classMembers.entrySet())
+		{
+			player.sendMessage(" - " + entry.getKey() + ": " + entry.getValue().size() + " players " + entry.getValue().stream().collect(Collectors.joining(", ", "(", ")")));
+		}
+	}
+	
+	@Override
+	public String[] getAdminCommandList()
+	{
+		return ADMIN_COMMANDS;
+	}
+}
Index: /main/L2GoldClassic/java/gold/lineage2/gameserver/model/Location.java
===================================================================
--- /main/L2GoldClassic/java/gold/lineage2/gameserver/model/Location.java	(revision 26)
+++ /main/L2GoldClassic/java/gold/lineage2/gameserver/model/Location.java	(revision 27)
@@ -56,4 +56,17 @@
 		_z = set.getInt("z");
 		_heading = set.getInt("heading", 0);
+	}
+	
+	/**
+	 * Calculates the Euclidean distance between two 3D points in the world
+	 * @param other
+	 * @return
+	 */
+	public double distanceTo(Location other)
+	{
+		int dx = _x - other._x;
+		int dy = _y - other._y;
+		int dz = _z - other._z;
+		return Math.sqrt((dx * dx) + (dy * dy) + (dz * dz));
 	}
 	
Index: /main/L2GoldClassic/java/gold/lineage2/gameserver/util/Util.java
===================================================================
--- /main/L2GoldClassic/java/gold/lineage2/gameserver/util/Util.java	(revision 26)
+++ /main/L2GoldClassic/java/gold/lineage2/gameserver/util/Util.java	(revision 27)
@@ -266,4 +266,22 @@
 	
 	/**
+	 * Tries to parse an integer from a string. If it fails, it returns the default value provided.
+	 * @param value
+	 * @param defaultValue
+	 * @return
+	 */
+	public static int parseNextInt(String value, int defaultValue)
+	{
+		try
+		{
+			return Integer.parseInt(value);
+		}
+		catch (NumberFormatException e)
+		{
+			return defaultValue;
+		}
+	}
+	
+	/**
 	 * @param text - the text to check
 	 * @return {@code true} if {@code text} is float, {@code false} otherwise

 

Edited by Trance
  • Trance changed the title to Admin Scan Players command

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

    • Well u need to change when sm1 press exit it keeps it in game..  
    • That’s just part of buying and selling; if your service didn't appeal to me at the time, there's no reason for me to force myself to buy it. After all, I regularly buy other interfaces and clients from other users mostly Russians using USDT. But *I'm* the child here, even though *you're* the incredibly arrogant one.   The payment method or the amounts were never the problem you were. But life goes on; you’d rather stay caught up in your delusions, thinking you’re the protagonist of some anime. Princess Alice 😂   I have all the interfaces for the 474/506/509/520/542/563/557. and olds too.  Some were created by me, including the ARENA P140 interface, which will soon be released for free. This includes everything you make available. It will no longer be a monopoly held by just a few people.   Including your clients with system. like  
    • NEW: Ryzen 9 9950X VPS now Available! Our most Powerful VPS plans now available with dedicated Zen 5 cores clocked up to 5.7 GHz, DDR5 ECC, blazing NVMe Gen4 storage (~7 GB/s), 10 Gbit/s uplink with up to 50 TB traffic, and premium Anti-DDoS included on every plan. No KYC, crypto payments accepted, deployed in minutes. ⭐ RYZEN 9 9950X VPS: [ 9.99 ] 2vCore | 6GB DDR5 | 30GB NVMe - DEPLOY [ 19.99 ] 4vCore | 12GB DDR5 | 50GB NVMe - DEPLOY [ 39.99 ] 8vCore | 24GB DDR5 | 80GB NVMe - DEPLOY [ 69.99 ] 12vCore | 48GB DDR5 | 120GB NVMe - DEPLOY - 10 Gbit/s Port included in ALL Plans - Premium Anti-DDoS included in ALL Plans - No-KYC signup, crypto payments accepted ✅ Ryzen 9 9950X VPS ( vpslab.cloud )
    • I thiunk RU Federation having issues now with paypal?
    • 👑 [FOR SALE] Lineage 2 Premium UCP – Modern Web Panel with Progression & Reward Systems. Looking for the ultimate edge to make your server boom and boost revenue? Introducing the L2 Premium UCP—the most comprehensive and modern User Control Panel on the market. Developed with a total focus on player experience (UX) and administrative automation. Say goodbye to outdated, buggy panels. Give your server the look and feel of an official game!  
  • 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..