Jump to content
  • 0

PvP Random Zone


Question

Posted

Hi everyone. I need some help, please. I want to create a random zone, but like an event. With a schedule, like TVT, I want to take an existing zone, for example, the city of Gludin, which is currently a peace zone, and make it PvP for a certain amount of time, then restore it, but I haven't been able to do it.

3 answers to this question

Recommended Posts

  • 0
Posted
package custom.events.RandomZoneEvent;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ScheduledFuture;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.commons.time.SchedulingPattern;
import org.l2jmobius.commons.time.TimeUtil;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.managers.ZoneManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.quest.Event;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.RandomZone;
import org.l2jmobius.gameserver.util.Broadcast;

/**
 * Random Zone Event - Activates one random PvP zone temporarily. No modifica la clase de la zona: usa flags PvP en runtime.
 * @author Juan
 */
public class RandomZoneEvent extends Event
{
	private static final String CONFIG_FILE = "data/scripts/custom/events/RandomZoneEvent/config.xml";
	
	private static int EVENT_DURATION_MINUTES = 15;
	
	private static boolean _isActive = false;
	private ScheduledFuture<?> _eventTask = null;
	
	private final List<ZoneType> _availableZones = new ArrayList<>();
	private ZoneType _activeZone = null;
	
	public RandomZoneEvent()
	{
		loadConfig();
		loadZones();
		registerZoneListeners();
	}
	
	/**
	 * Registra listeners a TODAS LAS ZONAS random
	 */
	private void registerZoneListeners()
	{
		for (ZoneType zone : _availableZones)
		{
			addEnterZoneId(zone.getId());
			addExitZoneId(zone.getId());
			LOGGER.info("[RandomZoneEvent] Registered listener for zone: " + zone.getName());
		}
	}
	
	private void loadConfig()
	{
		new IXmlReader()
		{
			@Override
			public void load()
			{
				parseDatapackFile(CONFIG_FILE);
			}
			
			@Override
			public void parseDocument(Document doc, File file)
			{
				forEach(doc, "event", eventNode ->
				{
					final StatSet att = new StatSet(parseAttributes(eventNode));
					final String name = att.getString("name");
					
					for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling())
					{
						if ("schedule".equals(node.getNodeName()))
						{
							final StatSet attributes = new StatSet(parseAttributes(node));
							final String pattern = attributes.getString("pattern");
							final SchedulingPattern schedulingPattern = new SchedulingPattern(pattern);
							
							final StatSet params = new StatSet();
							params.set("Name", name);
							params.set("SchedulingPattern", pattern);
							
							final long delay = schedulingPattern.getDelayToNextFromNow();
							getTimers().addTimer("Schedule_" + name, params, delay + 5000, null, null);
							LOGGER.info("[RandomZoneEvent] Event " + name + " scheduled at " + TimeUtil.getDateTimeString(System.currentTimeMillis() + delay));
						}
					}
				});
			}
		}.load();
	}
	
	private void loadZones()
	{
		for (ZoneType zone : ZoneManager.getInstance().getAllZones(RandomZone.class))
		{
			if ((zone.getName() != null) && zone.getName().toLowerCase().startsWith("random_zone"))
			{
				_availableZones.add(zone);
				LOGGER.info("[RandomZoneEvent] Loaded zone: " + zone.getName() + " (id=" + zone.getId() + ")");
			}
		}
		
		LOGGER.info("[RandomZoneEvent] Total random zones loaded: " + _availableZones.size());
	}
	
	@Override
	public void onTimerEvent(String event, StatSet params, Npc npc, Player player)
	{
		if (event.startsWith("Schedule_"))
		{
			eventStart(null);
			
			final SchedulingPattern schedulingPattern = new SchedulingPattern(params.getString("SchedulingPattern"));
			final long delay = schedulingPattern.getDelayToNextFromNow();
			
			getTimers().addTimer(event, params, delay + 5000, null, null);
			
			LOGGER.info("[RandomZoneEvent] Rescheduled for " + TimeUtil.getDateTimeString(System.currentTimeMillis() + delay));
		}
	}
	
	@Override
	public boolean eventStart(Player eventMaker)
	{
		if (_isActive)
		{
			if (eventMaker != null)
			{
				eventMaker.sendMessage("RandomZoneEvent already active.");
			}
			return false;
		}
		
		if (_availableZones.isEmpty())
		{
			Broadcast.toAllOnlinePlayers("[RandomZoneEvent] No zones configured.");
			return false;
		}
		
		_isActive = true;
		Broadcast.toAllOnlinePlayers("⚔️ Random Zone Event has started!");
		
		_eventTask = ThreadPool.schedule(this::activateRandomZone, 5_000);
		return true;
	}
	
	private void activateRandomZone()
	{
		_activeZone = _availableZones.get(new Random().nextInt(_availableZones.size()));
		
		_activeZone.setEnabled(true);
		
		Broadcast.toAllOnlinePlayers("🔥 Random Zone Event: " + _activeZone.getName() + " is now PvP for " + EVENT_DURATION_MINUTES + " minutes!");
		
		_eventTask = ThreadPool.schedule(this::eventStop, EVENT_DURATION_MINUTES * 60 * 1000L);
	}
	
	@Override
	public boolean eventStop()
	{
		if (!_isActive)
		{
			return false;
		}
		
		_isActive = false;
		
		if (_eventTask != null)
		{
			_eventTask.cancel(true);
			_eventTask = null;
		}
		
		if (_activeZone != null)
		{
			_activeZone.setEnabled(false);
			Broadcast.toAllOnlinePlayers("🏁 Random Zone Event ended. " + _activeZone.getName() + " is back to normal.");
			_activeZone = null;
		}
		else
		{
			Broadcast.toAllOnlinePlayers("🏁 Random Zone Event ended.");
		}
		
		return true;
	}
	
	@Override
	public void onEnterZone(Creature creature, ZoneType zone)
	{
		if (!_isActive || (_activeZone == null))
		{
			return;
		}
		
		if ((zone == _activeZone) && creature.isPlayable())
		{
			creature.setInsideZone(ZoneId.PVP, true);
			
			if (creature.isPlayer())
			{
				creature.sendMessage("Esta zona está en modo PvP temporalmente.");
			}
		}
	}
	
	@Override
	public void onExitZone(Creature creature, ZoneType zone)
	{
		if (!_isActive || (_activeZone == null))
		{
			return;
		}
		
		if ((zone == _activeZone) && creature.isPlayable())
		{
			creature.setInsideZone(ZoneId.PVP, false);
			
			if (creature.isPlayer())
			{
				creature.sendMessage("Abandonaste la zona PvP temporal.");
			}
		}
	}
	
	@Override
	public boolean eventBypass(Player player, String bypass)
	{
		return true;
	}
	
	@Override
	public String onEvent(String event, Npc npc, Player player)
	{
		return super.onEvent(event, npc, player);
	}
	
	@Override
	public String onFirstTalk(Npc npc, Player player)
	{
		return null;
	}
	
	public static void main(String[] args)
	{
		new RandomZoneEvent();
	}
}



i have this but its not working

  • 0
Posted
55 minutes ago, cheto45 said:
package custom.events.RandomZoneEvent;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ScheduledFuture;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.commons.time.SchedulingPattern;
import org.l2jmobius.commons.time.TimeUtil;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.managers.ZoneManager;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.quest.Event;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.type.RandomZone;
import org.l2jmobius.gameserver.util.Broadcast;

/**
 * Random Zone Event - Activates one random PvP zone temporarily. No modifica la clase de la zona: usa flags PvP en runtime.
 * @author Juan
 */
public class RandomZoneEvent extends Event
{
	private static final String CONFIG_FILE = "data/scripts/custom/events/RandomZoneEvent/config.xml";
	
	private static int EVENT_DURATION_MINUTES = 15;
	
	private static boolean _isActive = false;
	private ScheduledFuture<?> _eventTask = null;
	
	private final List<ZoneType> _availableZones = new ArrayList<>();
	private ZoneType _activeZone = null;
	
	public RandomZoneEvent()
	{
		loadConfig();
		loadZones();
		registerZoneListeners();
	}
	
	/**
	 * Registra listeners a TODAS LAS ZONAS random
	 */
	private void registerZoneListeners()
	{
		for (ZoneType zone : _availableZones)
		{
			addEnterZoneId(zone.getId());
			addExitZoneId(zone.getId());
			LOGGER.info("[RandomZoneEvent] Registered listener for zone: " + zone.getName());
		}
	}
	
	private void loadConfig()
	{
		new IXmlReader()
		{
			@Override
			public void load()
			{
				parseDatapackFile(CONFIG_FILE);
			}
			
			@Override
			public void parseDocument(Document doc, File file)
			{
				forEach(doc, "event", eventNode ->
				{
					final StatSet att = new StatSet(parseAttributes(eventNode));
					final String name = att.getString("name");
					
					for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling())
					{
						if ("schedule".equals(node.getNodeName()))
						{
							final StatSet attributes = new StatSet(parseAttributes(node));
							final String pattern = attributes.getString("pattern");
							final SchedulingPattern schedulingPattern = new SchedulingPattern(pattern);
							
							final StatSet params = new StatSet();
							params.set("Name", name);
							params.set("SchedulingPattern", pattern);
							
							final long delay = schedulingPattern.getDelayToNextFromNow();
							getTimers().addTimer("Schedule_" + name, params, delay + 5000, null, null);
							LOGGER.info("[RandomZoneEvent] Event " + name + " scheduled at " + TimeUtil.getDateTimeString(System.currentTimeMillis() + delay));
						}
					}
				});
			}
		}.load();
	}
	
	private void loadZones()
	{
		for (ZoneType zone : ZoneManager.getInstance().getAllZones(RandomZone.class))
		{
			if ((zone.getName() != null) && zone.getName().toLowerCase().startsWith("random_zone"))
			{
				_availableZones.add(zone);
				LOGGER.info("[RandomZoneEvent] Loaded zone: " + zone.getName() + " (id=" + zone.getId() + ")");
			}
		}
		
		LOGGER.info("[RandomZoneEvent] Total random zones loaded: " + _availableZones.size());
	}
	
	@Override
	public void onTimerEvent(String event, StatSet params, Npc npc, Player player)
	{
		if (event.startsWith("Schedule_"))
		{
			eventStart(null);
			
			final SchedulingPattern schedulingPattern = new SchedulingPattern(params.getString("SchedulingPattern"));
			final long delay = schedulingPattern.getDelayToNextFromNow();
			
			getTimers().addTimer(event, params, delay + 5000, null, null);
			
			LOGGER.info("[RandomZoneEvent] Rescheduled for " + TimeUtil.getDateTimeString(System.currentTimeMillis() + delay));
		}
	}
	
	@Override
	public boolean eventStart(Player eventMaker)
	{
		if (_isActive)
		{
			if (eventMaker != null)
			{
				eventMaker.sendMessage("RandomZoneEvent already active.");
			}
			return false;
		}
		
		if (_availableZones.isEmpty())
		{
			Broadcast.toAllOnlinePlayers("[RandomZoneEvent] No zones configured.");
			return false;
		}
		
		_isActive = true;
		Broadcast.toAllOnlinePlayers(" Random Zone Event has started!");
		
		_eventTask = ThreadPool.schedule(this::activateRandomZone, 5_000);
		return true;
	}
	
	private void activateRandomZone()
	{
		_activeZone = _availableZones.get(new Random().nextInt(_availableZones.size()));
		
		_activeZone.setEnabled(true);
		
		Broadcast.toAllOnlinePlayers(" Random Zone Event: " + _activeZone.getName() + " is now PvP for " + EVENT_DURATION_MINUTES + " minutes!");
		
		_eventTask = ThreadPool.schedule(this::eventStop, EVENT_DURATION_MINUTES * 60 * 1000L);
	}
	
	@Override
	public boolean eventStop()
	{
		if (!_isActive)
		{
			return false;
		}
		
		_isActive = false;
		
		if (_eventTask != null)
		{
			_eventTask.cancel(true);
			_eventTask = null;
		}
		
		if (_activeZone != null)
		{
			_activeZone.setEnabled(false);
			Broadcast.toAllOnlinePlayers(" Random Zone Event ended. " + _activeZone.getName() + " is back to normal.");
			_activeZone = null;
		}
		else
		{
			Broadcast.toAllOnlinePlayers(" Random Zone Event ended.");
		}
		
		return true;
	}
	
	@Override
	public void onEnterZone(Creature creature, ZoneType zone)
	{
		if (!_isActive || (_activeZone == null))
		{
			return;
		}
		
		if ((zone == _activeZone) && creature.isPlayable())
		{
			creature.setInsideZone(ZoneId.PVP, true);
			
			if (creature.isPlayer())
			{
				creature.sendMessage("Esta zona está en modo PvP temporalmente.");
			}
		}
	}
	
	@Override
	public void onExitZone(Creature creature, ZoneType zone)
	{
		if (!_isActive || (_activeZone == null))
		{
			return;
		}
		
		if ((zone == _activeZone) && creature.isPlayable())
		{
			creature.setInsideZone(ZoneId.PVP, false);
			
			if (creature.isPlayer())
			{
				creature.sendMessage("Abandonaste la zona PvP temporal.");
			}
		}
	}
	
	@Override
	public boolean eventBypass(Player player, String bypass)
	{
		return true;
	}
	
	@Override
	public String onEvent(String event, Npc npc, Player player)
	{
		return super.onEvent(event, npc, player);
	}
	
	@Override
	public String onFirstTalk(Npc npc, Player player)
	{
		return null;
	}
	
	public static void main(String[] args)
	{
		new RandomZoneEvent();
	}
}



i have this but its not working

what pack you use 
send me on discord for it

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

    • Update M54: Global HP/MP/CP consumable handling expanded beyond combat-only usage. Offensive mage idle recovery with learned skill Battle Heal. Spellhowler/Storm Screamer prioritizes Hurricane, using Vampiric Claw mostly below 90% HP. Major structural refactor initialized: Added category/class organization such as Archer, Dagger, Tank, Mage, Healer, Support and Specialized class files. Further structural cleanup. Extracted combat memory/state and more class-policy logic from the main controller. Added global stuck/inactivity watchdog for bots blocked by terrain/geodata. Added unreachable dropped ground-item timeout/temporary blacklist. Reworked Necromancer/Soultaker PvP: Dominator level 78+ maintains learned Arcane Power toggle on. Overlord/Dominator level 44+ maintains learned Soul Guard toggle automatically. Stability/scalability update: Bot controller ticks staggered instead of all starting in the same phase: Same 350 ms update rate retained Reduces simultaneous AI workload bursts. Removed the old manual aggressive-monster EVT_AGGRESSION bridge. Phantoms now use native Lucera setActive() behavior so monsters aggro them naturally. Reduced unnecessary NPC scans and native AI event pressure. Added saved-bot equipment overrides using a separate database table:         lucera_autobots_items Existing lucera_autobots remains the main saved-bot identity/state table. Equipment rows are linked to saved bots through bot_id. Added optional convenience view to show bot name together with equipment overrides:         lucera_autobots_items_view Added editable equipment slots in columns: Weapon Shield Helmet Chest Legs Gloves Boots Necklace Left/Right Earrings Left/Right Rings Equipment override values: 0 = use normal class/level profile item -1 = force slot empty >0 = equip that Item ID Custom equipment works only for saved database bots. Default class/level equipment profiles remain unchanged. Supports custom equipment from No Grade to S Grade, regardless of the bot's current level. Added validation for invalid item IDs and incompatible equipment slots. Added handling for: Two-handed weapons vs shields Full-body armor vs separate leggings Added all-grade Soulshots and Spiritshots to bot inventory/replenishment so custom lower-grade weapons still use the correct shots. Mage profiles that already use Blessed Spiritshots keep that behavior with all relevant grades available. First save the bot normally so it exists in table:         lucera_autobots Then open:         lucera_autobots_items Find the row with the same bot_id and edit only the equipment slots you want. Example: weapon_id = 6608 shield_id = -1 helmet_id = 0 chest_id = 0 legs_id = 0 gloves_id = 0 boots_id = 0 This means: weapon_id 6608 → custom weapon shield_id -1 → no shield all 0 values → keep normal default profile equipment After editing the DB, despawn and respawn the saved bot so M54 reloads its equipment overrides. Do not edit bot_id. Use it only to identify which saved bot the equipment row belongs to.   DOWNLOAD
    • It will be multi client so it will detect the client from the files and adapt the packets and asset loading. I am aiming for C4 and H5 after IL
    • this is just to simplify your life, time, and can be done for free by yourself just watch some tutorials, in case you don't wanna waste time check it out!   https://l2getwork.art   https://l2getwork.art/showcase.html  
    • Good job! Any chance for it to be downgradeable or at least compatible with older chronicles?
    • Fermata now runs in a web browser too. Try it here: https://web.fermata.gg/    
  • 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..