Jump to content
  • 0

[Help] Remaining Time + Teleport


BAN_L2JDev

Question

PT_BR =   Ola membros do Fórum sou novato, e estou escrevendo esse código mais logo a quanto o tempo termina ele teleporta mais gera muitos erro ao GameServer

Esta funcionando mais queria retirar os erros que da em

 

 

Google translator

EN= 

The members of the Forum are newbies, and are signing this code sooner in time the teleports finish some more errors to GameServer

This works more wanted removed the errors that in

Model.Foke

Model.Player

Model.Walker

 

WARNING    Exception in a Runnable execution:java.lang.ClassCastException: net.sf.l2j.gameserver.model.actor.instance.Walker cannot be cast to net.sf.l2j.gameserver.model.actor.instance.Player

 

 

 


package net.sf.l2j.gameserver.model.zone.type;


import java.util.Collection;
import java.util.concurrent.ScheduledFuture;
import java.util.stream.Collectors;

import net.sf.l2j.commons.concurrent.ThreadPool;

import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;

import net.sf.l2j.gameserver.model.actor.Creature;
import net.sf.l2j.gameserver.model.actor.instance.Player;
import net.sf.l2j.gameserver.model.zone.SpawnZoneType;
import net.sf.l2j.gameserver.model.zone.ZoneId;

public class EventZone extends SpawnZoneType
    {

       protected ScheduledFuture<?> _counterTask = null;
       protected int _timer = 5 * 60;
       
       
       
    public EventZone(int id)
    {
        super(id);
    }
    

    
    @Override
    protected void onEnter(Creature character)
    {
        
        if (character instanceof Player && _counterTask == null)
        _counterTask = startCounter();

        character.setInsideZone(ZoneId.PEACE, true);
        

        

        
          ThreadPool.schedule(new Runnable()
               {
                   @Override
                   public void run()
                   {
                       
                       ((Player) character).teleToLocation(83597, 147888, -3405, 0);
                       ((Player) character).sendMessage("Evento Finalizado!");
                   }
               }, 1000 * 300);
          
        }

    
       private ScheduledFuture<?> startCounter()
       {
           return ThreadPool.scheduleAtFixedRate(new Counter(), 1000, 1000);
       }
       
    
    @Override
    protected void onExit(Creature character)
    {
        character.setInsideZone(ZoneId.PEACE, false);
        
              
               if (getPlayers().size() < 1)
                   resetCounter();
    }
    
    @Override
    public void onDieInside(Creature character)
    {
    }
    
    @Override
    public void onReviveInside(Creature character)
    {
        
        character.setCurrentHp(character.getMaxHp());
        character.setCurrentCp(character.getMaxCp());
        character.setCurrentMp(character.getMaxMp());
        onEnter(character);
        
        }
    
       public Collection<Player> getPlayers()
       {
           return getCharacters().stream().filter(pl -> pl instanceof Player).map(cr -> (Player) cr).collect(Collectors.toList());
       }
       

       protected void resetCounter() 
       {

           if (_counterTask != null)
           {
               _counterTask.cancel(true);
               _counterTask = null;
           }
           _timer = 5 * 60;
       }
      
       class Counter implements Runnable
       {
          
           protected Counter()
           {
           }
          
           @Override
           public void run()
           {
               if (_timer < 1)
               {
                   resetCounter();
                   return;
               }
               for (Player player : getPlayers())
               {
                   int minutes = _timer / 60;
                   int second = _timer % 60;
                   String timing = ((minutes < 10) ? ("0" + minutes) : minutes) + ":" + ((second < 10) ? ("0" + second) : second);
                   player.sendPacket(new ExShowScreenMessage("Event Farm: " + timing, 1100, SMPOS.TOP_CENTER, false));

               }
               _timer--;
           }
      }
}

 

BR= Soucer Acis Atual!

EN= Source Acis 

 

 

123123.png

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
	@Override
	protected void onEnter(Creature character)
	{
		if (character instanceof Player)
		{
			ThreadPool.schedule(() -> ((Player) character).teleToLocation(83597, 147888, -3405, 0), 1000 * 300);
			ThreadPool.schedule(() -> ((Player) character).sendMessage("Evento Finalizado!"), 1000 * 300);
			
			if (_counterTask == null)
				_counterTask = startCounter();
			
		}
		character.setInsideZone(ZoneId.PEACE, true);
	}

 

Edited by melron
Link to comment
Share on other sites

  • 0
22 hours ago, melron said:

	@Override
	protected void onEnter(Creature character)
	{
		if (character instanceof Player)
		{
			ThreadPool.schedule(() -> ((Player) character).teleToLocation(83597, 147888, -3405, 0), 1000 * 300);
			ThreadPool.schedule(() -> ((Player) character).sendMessage("Evento Finalizado!"), 1000 * 300);
			
			if (_counterTask == null)
				_counterTask = startCounter();
			
		}
		character.setInsideZone(ZoneId.PEACE, true);
	}

 

 

You can run 1 ThreadPool for both of them, also there need check before teleport the player if he still inside on that zone.

if (character instanceof Player)
{
	final Player player = (Player) character;
	ThreadPool.schedule(() ->
	{
		if (player.isInsideZone(ZoneId.ZONE)
		{
			player.teleToLocation(X, Y, Z, 0);
			player.sendMessage("Message");
		}
	}, 1000 * 300);

	if (_counterTask == null)
		_counterTask = startCounter();
}

 

Edited by StinkyMadness
Link to comment
Share on other sites

  • 0
44 minutes ago, StinkyMadness said:

 

You can run 1 ThreadPool for both of them, also there need check before teleport the player if he still inside on that zone.


if (character instanceof Player)
{
	final Player player = (Player) character;
	ThreadPool.schedule(() ->
	{
		if (player.isInsideZone(ZoneId.ZONE)
		{
			player.teleToLocation(X, Y, Z, 0);
			player.sendMessage("Message");
		}
	}, 1000 * 300);

	if (_counterTask == null)
		_counterTask = startCounter();
}

 

Y it can be in 1. Also you dont have to check about zone since this code is located at onEnter.

I didnt get what this guy us trying to do. He is teleporting the player when he is entering in that zone? 

 

Also after the teleport code should be a return statement ( or if else) because:

 

OnEnter -> teleport -> onExit -> and after that setIsInsideZone is taking place. That means the player is somewhere else with that zoneId

Link to comment
Share on other sites

  • 0
1 minute ago, melron said:

...

I mean that check needed because if the player enter and left the zone and be in town the task still count, so if you are in giran in next 5 minutes (1000 * 300) then he will be teleported like he is inside that zone.

  • Like 1
Link to comment
Share on other sites

  • 0
On 5/13/2019 at 6:12 AM, StinkyMadness said:

 

 

On 5/13/2019 at 6:10 AM, melron said:

 

 

Thank you for your attention with this I managed to reach the goal I was looking for.
I'm just a novice ...
Thank you all

Obrigado pela atenção de vocês com isso consegui a chegar no objetivo que eu buscava.
sou apenas um novado...
Grato a todos

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


  • Posts

    • L2 Insignia High Five 20x MID SERVER FOCUSED ON OLYMPIAD | PVP | AUTOFARM       OPEN BETA TEST SERVER 3 MAY 2024   GRAND OPENING 10 MAY 2024    Rates: 📜 XP/SP 20x | Spoil 15x | Drop 10x | Adena 10x 📜     Server Features: 🔥 No Olf-T Shirt, No big over-enchant, No over-power Donate 🔥 🔥 VIP Gold Color Chat, Unique Olympiad Extra Points Engine, GvG Event 🔥 🔥 Auto-Farm, LoA and DV scheduled PvP Zone, Calendar Daily Reward 🔥 🔥 Castle Instance, Solo Instance, PvP Solo Rift, Dress me system, Adena Boxes 🔥        Website: https://www.l2insignia.com  Discord: https://discord.com/invite/yEgsrHn2hQ      
    • I am selling the essence project which includes versions 388 and 439 that have been running for over 2 years or (447 as custom PVP like Pride). I have a test server for you to test them out. If you are really interested in it then contact my seller at discord: kiwi7106. Price: 4000 Euro P/s: This is a project that I have spent a lot of money and time developing, so if you are not interested in it, please get out of this topic, thank you. P/s 2: If you find the price too expensive, it's best to skip this article and find another project and don't comment negatively on my topic, thank you.
    • Someone ask me for this, it should work on any client that has Kamael race, preview:     Installation - there are two ways to install depending on how you want to use it:   Method 1: If you want to completely replace the original, do:   Copy all lines from your armorgrp to Notepad++, press Ctrl+H, check the "match whole word" option and replace:   kamael.Mkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_MKamael_m001_w_ad00   Then replace:   MKamael.Mkamael_m000_t00_w   by:   AvengersKamaelWings.MKamael_m001_t00_w   Now repeat the same process with the female, replace:   kamael.Fkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_FKamael_m001_w_ad00   Then replace:   FKamael.Fkamael_m000_t00_w   by:   AvengersKamaelWings.FKamael_m001_t00_w   You're done, paste everything back into File Edit and save!   Method 2: If you only want to replace in specific sets, execute the above process only on the armorgrp of those sets.   Repack by: AvengersTeamBr Password: LadrãoDeFrango      
  • Topics

×
×
  • Create New...