Jump to content
  • 0

[Help] Remaining Time + Teleport


Question

Posted

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

5 answers to this question

Recommended Posts

  • 0
Posted (edited)
	@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
  • 0
Posted (edited)
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
  • 0
Posted
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

  • 0
Posted
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
  • 0
Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • https://prnt.sc/Bkkc0ShGXv9m https://prnt.sc/-JFLvZXsn27A
    • Hello guys want to sell adena in L2 Reborn Signature x1  Stock =14kk good price 
    • Hi guys, I have the following problem, I want to set up two servers on the same dedicated server and I can't.   L2jacis 409 Linux Server. The first gameserver has the following configuration: # ================================================================ # Gameserver setting # ================================================================ # This is transmitted to the clients, so it has to be an IP or resolvable hostname. If this ip is resolvable by Login just leave * Hostname = 190.25.103.103 # Bind ip of the gameserver, use * to bind on all available IPs. GameserverHostname = * GameserverPort = 7777 # The Loginserver host and port. LoginHost = 127.0.0.1 LoginPort = 9014 # This is the server id that the gameserver will request. RequestServerID = 1 # If set to true, the login will give an other id to the server (if the requested id is already reserved). AcceptAlternateID = True UseBlowfishCipher = True # ================================================================ # Database informations # ================================================================ URL = jdbc:mariadb://localhost/server1 Login = server1 Password = server1 I configured the second gameserver like this:   # ================================================================ # Gameserver setting # ================================================================ # This is transmitted to the clients, so it has to be an IP or resolvable hostname. If this ip is resolvable by Login just leave * Hostname = 0.0.0.0 # Bind ip of the gameserver, use * to bind on all available IPs. GameserverHostname = * GameserverPort = 7788 # The Loginserver host and port. LoginHost = 127.0.0.1 LoginPort = 9014 # This is the server id that the gameserver will request. RequestServerID = 2 # If set to true, the login will give an other id to the server (if the requested id is already reserved). AcceptAlternateID = True UseBlowfishCipher = True # ================================================================ # Database informations # ================================================================ URL = jdbc:mariadb://localhost/server2 Login = server2 Password = server2 apart from having tested 0.0.0.0 on the second gameserver I also tried 127.0.0.1 In both cases I see the two servers in the login when I log in, but I try to enter the one with the lowest ping and it kicks me out. The other server always appears with ping 9999 and I try to enter but it doesn't do anything and it freezes the login so I have to log in again. The hexids are in their respective folders. For server 1, it has its hexid inside the gameserver config folder, and I checked that the hexid id is the same id, for example id 1 in the gameserver is also id1 for server 1, and hexid 2 has its hexid 2 for server 2. The server ports are open and listening when I turn on both gameservers. I really don't know what could be wrong. If you could give me some help I would appreciate it. Excuse my English.
    • We have both old channels from 2006-2009 with the 3rd verification function enabled, and new ones.   For availability, please contact us below: Link - Telegram Link - Facebook WhatsApp - Click here to go to WhatsApp chat
    • You can contact me on skype: niedziolek50
  • Topics

×
×
  • Create New...