Welcome to MaxCheaters.com

Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads

  • 0

Help how to stop following script if voiced command used


Question

Hi,

 

I'm trying to sort my PvP zone, basically it has auto revive after x seconds if died in specific zone.

Now I'm working on exit functionality and I've created voiced command .exit it works in two ways, either if you in the zone but not combat it will teleport you out in x seconds, or if you dead and in the zone it will teleport you straight away to the town.

now the problem I have when you are dead and use .exit command it does teleport you to the town, but the zone script is still running in the background and after x seconds from initial death it teleports you right back in the zone

 

this is my exit command script while dead,

 

if(command.equalsIgnoreCase("exit"))
		
		if(!player.isInsideZone(L2Character.ZONE_PvP))
		{
			player.sendMessage("You can only use this command in PVP Zone");
			return false;
		}	

if(player.isDead())
		{
			player.setInsideZone(L2Character.ZONE_PvP, false);
			player.doRevive();
			player.teleToLocation(Config.CSPAWN_X, Config.CSPAWN_Y, Config.CSPAWN_Z);
			player.sendMessage("You have been teleported to Main Town"); 
			return false;
		}	

 

 

this is my auto revive script,

 

 

  public void onDieInside(final L2Character character)
  {
      if (character instanceof L2PcInstance)
      {
          final L2PcInstance activeChar = ((L2PcInstance) character);
          if(revive)
          {
              ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
              {
                  @Override
                  public void run()
                  {
                      activeChar.doRevive();
                      heal(activeChar);
                      int[] loc = spawn_loc[Rnd.get(spawn_loc.length)];
                      activeChar.teleToLocation(loc[0]+Rnd.get(-radius,radius), loc[1]+Rnd.get(-radius,radius), loc[2]);
                  }
              },revive_delay*1000);  
          }
      }
  }

 

basically I want it to work like below,

 

OnDieInside

if(command.equalsIgnoreCase("exit"))

{ do nothing }

else revive as usual.

 

but whichever way I try to add it in there, it doesn't work, it doesn't allow me to add public boolean useVoicedCommand in "Public Void"

 

any help would be appreciated.

thanks,

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

You have to store your running task to a ScheduledFuture<?> _task (stored in L2PcInstance / Player) and then

 

        if (_task != null)
        {
            _task.cancel(false);
            _task = null;
        }

 

over it if you need to abort it. That code section can be put in a public method to be triggered anywhere, anytime. You got over 50+ occurrences on any regular L2J pack of that way of coding.

Edited by Tryskell
  • Like 1

Share this post


Link to post
Share on other sites
  • 0

thank you for advise, will research it to see if I can apply in any future codes, However I managed to fix this issue (with some help) by adding the check if player is still in the zone at the time of reviving. it works well, what do you think about doing it this way? any concerns regarding it?

 

  public void onDieInside(final L2Character character)
  {
      if (character instanceof L2PcInstance)
      {
          final L2PcInstance activeChar = ((L2PcInstance) character);
          if(revive)
          {
              ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
              {
                  @Override
                  public void run()
                  {
			if(activeChar.isInsideZone(character.ZONE_PvP)) // with this line, so when it runs this script it checks whether I'm in zone at the time of reviving
			{
                      activeChar.doRevive();
                      heal(activeChar);
                      int[] loc = spawn_loc[Rnd.get(spawn_loc.length)];
                      activeChar.teleToLocation(loc[0]+Rnd.get(-radius,radius), loc[1]+Rnd.get(-radius,radius), loc[2]);
                  }
              },revive_delay*1000);  
          }
      }
  }

 

Share this post


Link to post
Share on other sites
  • 0

The task still runs silently in background.

 

While the task is only few dozens of seconds and is barely exploitable, it's not a good practice. Using that type of logic will pown you, one day or another.

Share this post


Link to post
Share on other sites
  • 0

Simplest solution. Before you do revive, make a zone check.. Sounds obvious, right.

 

Whatever you like. Could be assigned to some method, variable as suggested. But it's not like it's a must, nor the whole code is super duper. Keep it simple stupid.

Edited by SweeTs

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.