Jump to content
  • 0

Remaining Time on Screen/ Event countdown


Question

Posted

Hello everybody.

Well, i've been implementing a code for a type of zone that changes every 'x' minutes.

but I want to show only to all players inside these zones the time left for this zone change using ExShowScreenMessage or another method.

I tried some stuff to make this work.

Here is the code:

 

Quote

package l2r.gameserver.instancemanager;

import java.util.logging.Logger;

import l2r.gameserver.ThreadPoolManager;
import l2r.gameserver.enums.ZoneIdType;
import l2r.gameserver.model.L2World;
import l2r.gameserver.model.Location;
import l2r.gameserver.model.SpawnLocation;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.network.serverpackets.ExShowScreenMessage;
import l2r.gameserver.util.Broadcast;
import l2r.util.Rnd;

public class ZoneRandom implements Runnable
{
    private static final Logger _log = Logger.getLogger(ZoneRandom.class.getName());
    
    public int REFRESH = 2; //for debug
    public int RANDOM_RANGE = 100;
    public int RANDOM;
    public int seconds;
    
    public int timeLeft;
    
    private static final SpawnLocation[] ZONES =
    {
        new SpawnLocation(10468, -24569, -3650, 0), // Primeval Isle Wharf.
        // new SpawnLocation(106024, 114968, -1560, 0), // Hardin's Academy.
        new SpawnLocation(52113, 83315, -3372, 0),
    
    // Elven Fortress.
    };
    
    public ZoneRandom()
    {
        _log.info("ZoneRandom: Loading zones...");
        
        ThreadPoolManager.scheduleAiAtFixedRate(this, 0, REFRESH * 1000 * 60);
        
    }
    
    @Override
    public void run()
    {
        RANDOM = Rnd.get(ZONES.length - 1);
        
        for (L2PcInstance player : L2World.getInstance().getPlayers())
        {
            if (player.isInsideZone(ZoneIdType.RANDOM_ZONE))
            {
                player.teleToLocation(getRandomZone().getX() + Rnd.get(-RANDOM_RANGE, RANDOM_RANGE), getRandomZone().getY() + Rnd.get(-RANDOM_RANGE, RANDOM_RANGE), getRandomZone().getZ(), 20);
            }
        }
        
        Broadcast.toAllOnlinePlayers("The pvp area was changed to a random.", true);
        
        Broadcast.toAllOnlinePlayers("Next random pvp area will be change after " + REFRESH + " minute(s).", true);
        Broadcast.toAllOnlinePlayers("Use ''.arenajoin'' to enter on pvp zone and ''.arenaleave'' to leave.", true);
    }
    //here i treid to show on players screen the remaining time
    public void showTimeOnScreen(L2PcInstance player)
    {
        
        if (player.isInsideZone(ZoneIdType.RANDOM_ZONE))
        {
            
            player.sendPacket(new ExShowScreenMessage("02:00", 20000));
            /*
             * ThreadPool.schedule(() -> { for (seconds = 60; seconds <= 60; seconds--) { player.sendPacket(new ExShowScreenMessage("Time left: " + String.valueOf(REFRESH) + String.valueOf(seconds), 1000)); if (seconds == 0) { REFRESH = REFRESH - 1; seconds = 60; } } }, 1000);
             */
            
        }
    }
    
    public Location getRandomZone()
    {
        return ZONES[RANDOM];
    }
    
    public static ZoneRandom getInstance()
    {
        return SingletonHolder._instance;
    }
    
    private static class SingletonHolder
    {
        protected static final ZoneRandom _instance = new ZoneRandom();
    }
}

 

9 answers to this question

Recommended Posts

  • 0
Posted (edited)

code

 

 

 

take what you need and make it work

 

edit: I made it in town zone for example... you dont have to c/p that for your event

Edited by melron
  • 0
Posted

I've solved part of problem... Now players receives packets every 1000 milliseconds for 1000 miliseconds till the counter reaches zero and then they all are teleported to a randomzone previously defined. However, when the new zone 'starts', the countdown decreases two by two seconds and not one by one like it was supposed to be.  As if it were not enough, after another zone change the countdown decreases every three by three, and so on.

 

here's the new code:

public ZoneRandom()
	{
		_log.info("ZoneRandom: Loading zones...");
		
		ThreadPoolManager.scheduleAiAtFixedRate(this, 0, REFRESH * 1000);
		
	}
	
	@Override
	public void run()
	{
		RANDOM = Rnd.get(ZONES.length - 1);
		
		for (L2PcInstance player : L2World.getInstance().getPlayers())
		{
			SECONDS = REFRESH;
			if (player.isInsideZone(ZoneIdType.RANDOM_ZONE))
			{
				player.teleToLocation(getRandomZone().getX() + Rnd.get(-RANDOM_RANGE, RANDOM_RANGE), getRandomZone().getY() + Rnd.get(-RANDOM_RANGE, RANDOM_RANGE), getRandomZone().getZ(), 20);
				
				timer = new Timer();
				
				timer.scheduleAtFixedRate(new TimerTask()
				{
					
					@Override
					public void run()
					{
						showTime(player);
					}
				}, 1000, 1000);
			}
			
		}
		
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.BATTLEFIELD, "Arena Manager: ", "The pvp area was changed to a random."));
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.BATTLEFIELD, "Arena Manager: ", "Next random pvp area will be change after " + REFRESH + " minute(s)."));
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.BATTLEFIELD, "Arena Manager: ", "Use ''.arenajoin'' to enter on pvp zone and ''.arenaleave'' to leave."));
		
	}
	
	public static void showTime(L2PcInstance player)
	{
		SECONDS = REFRESH--;
		player.sendPacket(new ExShowScreenMessage("Time Left: " + SECONDS, 1000));
		
	}


 

  • 0
Posted
2 hours ago, Reborn12 said:

You have to use ScheduledFeature for that...

Hi , bro 

I tried this code above usind ScheduleFuture. But sometimes countdown timer don't matches with zone change time. Could you give me some light?

 

 

public ZoneRandom()
	{
		_log.info("ZoneRandom: Loading zones...");
		
		ThreadPoolManager.scheduleAiAtFixedRate(this, 0, REFRESH * 1000);
		// ThreadPoolManager.scheduleAiAtFixedRate(new TimerZoneTask(), 0, REFRESH * 1000);
		
	}

@Override
	public void run()
	{
		RANDOM = Rnd.get(ZONES.length - 1);
		
		for (L2PcInstance player : L2World.getInstance().getPlayers())
		{
			
			if (player.isInsideZone(ZoneIdType.RANDOM_ZONE))
			{
				
				player.teleToLocation(getRandomZone().getX() + Rnd.get(-RANDOM_RANGE, RANDOM_RANGE), getRandomZone().getY() + Rnd.get(-RANDOM_RANGE, RANDOM_RANGE), getRandomZone().getZ(), 20);
				
				final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
				
				final Runnable seconds = () -> player.sendPacket(new ExShowScreenMessage("Time Left: " + getSeconds(), 1000));
				
				final ScheduledFuture<?> timerHandle = scheduler.scheduleAtFixedRate(seconds, 0, 1, TimeUnit.SECONDS);
				
				final Runnable canceler = () -> timerHandle.cancel(false);
				if (getSeconds() <= 0)
				{
					timerHandle.cancel(true);
				}
				scheduler.schedule(canceler, REFRESH, TimeUnit.SECONDS);
				
			}
			
		}
		
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.BATTLEFIELD, "Arena Manager: ", "The pvp area was changed to a random."));
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.BATTLEFIELD, "Arena Manager: ", "Next random pvp area will be change after " + REFRESH + " minute(s)."));
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.BATTLEFIELD, "Arena Manager: ", "Use ''.arenajoin'' to enter on pvp zone and ''.arenaleave'' to leave."));
		
	}

public static int getSeconds()
	{
		
		return --REFRESH;
		
	}

 

  • 0
Posted

I invite you to check some other code countdown, like Duel, Olympiad, Derby or so. It's using a countdown to display time left. 

  • 0
Posted
1 hour ago, SweeTs said:

I invite you to check some other code countdown, like Duel, Olympiad, Derby or so. It's using a countdown to display time left. 

Good idea, lemme try

  • 0
Posted

Also, don't loop all players, use ZoneManager to get only the players of RandomZone. Take a look at grand boss script, even Baium. It's using zone to broadcast various things. 

  • 0
Posted
3 hours ago, melron said:

 

take what you need and make it work

 

edit: I made it in town zone for example... you dont have to c/p that for your event

 

Now it's in full working, thank you!

Guest
This topic is now closed to further replies.


  • Posts

    • Website: https://l2aurum.com/ Discord: https://discord.gg/ngaD9DJRjE   Dear Players, We are excited to announce that the x300 Summer Season Beta server will open on 19‑06‑2026 at 20:00 GMT+2. As previously mentioned, there will be no wipe and no account deletion. All accounts, characters, items, and progress from Season 1 will remain completely safe. To ensure a fair and competitive start for new players, all Season 1 accounts will be temporarily locked. The official Summer Season launch will take place on 26‑06‑2026 at 20:00 GMT+2. A few weeks after the official launch, Season 1 accounts will be unlocked so previous players can access their characters and continue their journey. This approach allows new players to enjoy a fresh start while preserving the progress and achievements of our long-term community. Thank you for your continued support, and we look forward to welcoming everyone to the new Summer Season. L2Aurum Team   Explore L2 Aurum Features Discover the Enhancements that set us apart!   Information Server Version: Interlude - PvP Server Client Interface: Unique Interface   Rates     Additional Features and changes When you create a new character, you will start in Giran Harbor at Level 1, equipped with full No-Grade items. Auto Farm is available for free for 2 hour daily without VIP. VIP players receive 4 hours of Auto Farm per day. The Auto Farm time resets with the server restart at 5:30 AM. Status Noblesse: Last hit Barakiel. Player Spawn Protection: 7 seconds. Geodata + Pathnodes: Enabled. All commands are available in the Community Board. Maximum 3 Bishops Per Party: Enabled. Boss Protect - Anti-Zerg: Enabled. Shift + click on monsters to see the droplist. Offline shop. Mana Potion Restores 1000 MP with a cooldown of 8 seconds. Inventory Slots: 250.   Weapon Information Lv1 Black Chaotic Weapons. Lv2 Aurum Weapons.   Armor Information Lv1 Blue Apella Armor. Lv2 Aurum Apella Armor. Misc additions Accessories +50 and +150 pdef|mdef. Tattoos: Resolve | Soul | Avadon. Agathions: Cosmetic only (no stats).   Buffs / Dances / Songs / Prophecies Duration: 2 hours. Total Buff Slots: 32 + 4 (Divine Inspiration). Vote Buff: You must vote on 3 of 6 vote sites to get the vote buff blessing. Castle Reward Every clan that captures a castle receives the castle owner clan blessing buff. To receive it, the clan leader must be online.   Events   Raid Bosses Epic Bosses Final Bosses     For full server information please visit website PvP: Server Features   Website: https://l2aurum.com/ Discord: https://discord.gg/ngaD9DJRjE      
    • ⭐ L2Dexter.eu – Interlude x200 The Ultimate PvP Experience 🔥 RATES XP/SP x200 Adena x60 Drop x30 – Spoil x20 Safe Enchant +3 / +4 Armor Max Enchant +16   ⚔️ GAMEPLAY Main Town: Giran NPC Buffer: 3h buffs Auto Loot • Offline Shop • Anti‑Bot Max 5 clients per HWID Unique PvP Zones with rewards Upgraded Armor System Auto Learn Skills • 30+4 Buff Slots Subclass: Free Nobless: Quest or alternative path Shift+Click drop info Global Shout: 7 sec   🏆 OLYMPIAD Cycle: 14 days Hours: 18:00–00:00 GMT+2 Classed & Non‑Classed 1 char per PC   🐉 EPIC BOSSES Baium: 120h Antharas: 192h Valakas: 264h Zaken: 48h AQ: 24h Frintezza: 48h Anakim/Lilith: 56–84h   💠 SOUL CRYSTALS 10→12: Baium/Zaken/Anakim/Lilith 100% 12→13: Valakas/Antharas/Frintezza 100%   🏰 CLAN SYSTEM Max players in epics: 72 Alliances: 3 clans Clan penalty: 1 day Alliance penalty: 2 days Sieges: Clan lvl 6 + rewards   💰 CURRENCIES Vote Coins – Voting Rune +6% P.Def/M.Def, +4% Speed Event Medals – Events, streaming, RB kills Premium Account – Donate, RBs, Top10 NPC Donate Coins – Donate, RBs, competitions
  • 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..