Jump to content

Rouxy

Members
  • Posts

    8
  • Credits

  • Joined

  • Last visited

  • Feedback

    0%

Everything posted by Rouxy

  1. 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; }
  2. 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)); }
  3. 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:
×
×
  • Create New...