Jump to content
  • 0

check if player.isDead() method


Question

Posted (edited)

Hello again! XD .

 

Well i created a zone with auto-revive  when a player is dead inside zone.

But i want check if players is dead before auto-revive..

Because even he get res before cooldown of auto-revive, after cooldown he teleport to revived-location even he is alive :/.

 

i want check if player isDead before auto-revive to avoid if he is alive to revive .

 

i hope you understand :) 

Code i use: 

Spoiler

        public void onDieInside(final L2Character character)
        { 
            if (character instanceof L2PcInstance)
            {
                final L2PcInstance activeChar = ((L2PcInstance) character);

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

 

Also i tried something like this but nothing:

Spoiler

        public void onDieInside(final L2Character character)
        { 
            if (character instanceof L2PcInstance)
            {
                final L2PcInstance activeChar = ((L2PcInstance) character);
                try
                {
                    Thread.sleep(600);
                }
                catch (InterruptedException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if(Config.revive && activeChar.isDead())
                {
                    ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                            activeChar.doRevive();
                            heal(activeChar);
                            int[] loc = Config.spawn_loc[Rnd.get(Config.spawn_loc.length)];
                            activeChar.teleToLocation(loc[0]+Rnd.get(-Config.radius,Config.radius), loc[1]+Rnd.get(-Config.radius,Config.radius), loc[2]);
                        }
                    },Config.revive_delay*1000);    
                } 
            }

 

 

Help!! i tried to find similar code to find a solution but couldnt!

Edited by Irrelevant

7 answers to this question

Recommended Posts

  • 0
Posted (edited)

You don't have to code anything inside the zone's method since the feature is about the player instance. You could make a manager to handle all these actions but this is just another case.

 

Lets begin about the basics. The zone, should only call a method in the player instance without any check for dead/alive since this call will be executed inside of Zone#onDieInside.

So,

 	@Override
 	protected void onDieInside(final L2Character character)
 	{
+		final L2PcInstance player = character.getActingPlayer();
+		if (player == null)
+			return;
+		
+		if (!Config.revive)
+			return;
+		
+		player.startAutoReviveTask();
 	}
 	
 	@Override

 

 

The player instance now will handle the next actions by itself.

The concept is:

  • Before start the task scheduler, you should check if the speficic scheudler is already running.
  • When the scheduler fires the runnable, you should just check if the player is dead or not.
  • If the player will be revived without the auto revive task, just cancel the auto revive.

So,

 

Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
@@ -15415,6 +15469,7 @@
 	public void doRevive()
 	{
 		super.doRevive();
+		resetAutoReviveTask();
 		updateEffectIcons();
 		sendPacket(new EtcStatusUpdate(this));
 		_reviveRequested = 0;

@@ -19644,4 +19705,41 @@
 		_currentPetSkill = new SkillDat(currentSkill, ctrlPressed, shiftPressed);
 	}
 	
+	// The task
+	private ScheduledFuture<?> _autoReviveTask = null;
+	
+	public void startAutoReviveTask()
+	{
+		// Before initiate the auto revive task, check if another scheduler is active
+		resetAutoReviveTask();
+		
+		// Start the task
+		_autoReviveTask = ThreadPoolManager.getInstance().scheduleGeneral(() -> doAutoRevive(), TimeUnit.SECONDS.toMillis(Config.revive_delay));
+	}
+	
+	private void resetAutoReviveTask()
+	{
+		// If is not running, do nothing
+		if (_autoReviveTask == null)
+			return;
+		
+		_autoReviveTask.cancel(true);
+		_autoReviveTask = null;
+	}
+	
+	private void doAutoRevive()
+	{
+		// Check for any possible scenario if the player is alive
+		if (!isDead())
+			return;
+		
+		doRevive();
+		heal();
+		teleToLocation(Rnd.get(Config.spawn_loc), false);
+	}
+	
+	private void heal()
+	{
+		// Heal the instance
+	}

 

 

And the last thing, get the Rnd#get which is generic from aCis sources which is returning a random element of the given list class as parameter.

 

Index: head-src/com/l2jfrozen/util/random/Rnd.java
===================================================================
--- head-src/com/l2jfrozen/util/random/Rnd.java	(revision 1118)
+++ head-src/com/l2jfrozen/util/random/Rnd.java	(working copy)
@@ -23,7 +23,19 @@
  */
 public final class Rnd
 {
+	
+ 	/**
+	 * Returns a randomly selected element taken from the given array.
+	 * @param <T> type of array elements.
+	 * @param array an array.
+	 * @return a randomly selected element.
+	 */
+	public static final <T> T get(T[] array)
+	{
+		return array[get(array.length)];
+	}
+	

 

With this version of Rnd#get, you can do this:

teleToLocation(Rnd.get(Config.spawn_loc), false);

instead of 

int[] loc = Config.spawn_loc[Rnd.get(Config.spawn_loc.length)];
teleToLocation(loc[0]+Rnd.get(-Config.radius,Config.radius), loc[1]+Rnd.get(-Config.radius,Config.radius), loc[2]);

 

Edited by melron
  • 0
Posted

Store this runnable into a ScheduledFuture<?> . Let's say you call this reviveTask. Upon Player#doRevive call you should cancel this task.

 

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

  • 0
Posted (edited)
7 hours ago, Zake said:

Store this runnable into a ScheduledFuture<?> . Let's say you call this reviveTask. Upon Player#doRevive call you should cancel this task.

 

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

like that?

 

Spoiler

public class L2PartyEventZone extends L2ZoneType
{
    
    public L2PartyEventZone (final int id)
    {
        super (id);
    }
+    protected ScheduledFuture<?> reviveTask;

 


 

 

        @Override
        public void onDieInside(final L2Character character)
        {
            if (character instanceof L2PcInstance)
            {
                final L2PcInstance activeChar = ((L2PcInstance) character);
    if(Config.revive)
                {

-                ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
+               reviveTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                           activeChar.doRevive();
+                           if (reviveTask != null)
+                            {
+                            reviveTask.cancel(false);
+                            reviveTask = null;
+                            }
                            heal(activeChar);

 

Edited by Irrelevant
  • 0
Posted (edited)

No, not really. At first , fields should be private in most cases. Furthermore, upon death (method onDieInside in your file) you should say something like

 

if (reviveTask == null)

reviveTask == ThreadPoolManager.getInstance().scheduleblabla()

 

Also, as i already mentioned above. You should cancel the task inside the method doRevive(L2PcInstance.java)

Edited by Zake
  • 0
Posted (edited)
1 hour ago, Zake said:

No, not really. At first , fields should be private in most cases. Furthermore, upon death (method onDieInside in your file) you should say something like

 

if (reviveTask == null)

reviveTask == ThreadPoolManager.getInstance().scheduleblabla()

 

Also, as i already mentioned above. You should cancel the task inside the method doRevive(L2PcInstance.java)

like that in l2PcInstance?

Spoiler

 

 

    /** The _donator. */
    private boolean _donator = false;
    
+    /**Auto Revive*/
+    public ScheduledFuture<?> reviveTask;

 

 

 

@@@

 

 

 

 

    @Override
    public void doRevive()
    {
        super.doRevive();
        updateEffectIcons();
        sendPacket(new EtcStatusUpdate(this));
        _reviveRequested = 0;
        _revivePower = 0;
        
+        if (isInsideZone(L2Character.ZONE_PARTYEVENT))
+                        
+                        if (reviveTask != null)
+                        {
+                        reviveTask.cancel(false);
+                        reviveTask = null;
+                       }
+                        doRevive();
+        }

 

 

 

and in zone like that? 

Spoiler

public class L2PartyEventZone extends L2ZoneType
{
    
    public L2PartyEventZone (final int id)
    {
        super (id);
    }
+    private ScheduledFuture<?> reviveTask;

 


 

 

        @Override
        public void onDieInside(final L2Character character)
        {
            if (character instanceof L2PcInstance)
            {
                final L2PcInstance activeChar = ((L2PcInstance) character);
    if(Config.revive)
                {

-                ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()

+               if (reviveTask == null)
+               reviveTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                           activeChar.doRevive();
                            heal(activeChar);



NOPE, i tried it! :/ 

Edited by Irrelevant
  • 0
Posted

reviveTask should be linked with players so you have to store this in L2PcInstance and not random classes. Also you don't need to check if a player is in a custom zone in doRevive() method, all you need is to cancel revive task.

  • 0
Posted (edited)
2 hours ago, melron said:

You don't have to code anything inside the zone's method since the feature is about the player instance. You could make a manager to handle all these actions but this is just another case.

 

 

 

 

 

 

DUDE <3 . I dont have words to thank you!! Awesome  for 1 more time!!!!!! THANK YOU! :hug
 

Edited by Irrelevant
Guest
This topic is now closed to further replies.


  • Posts

    • Thank you for your feedback, SkyLord — even the negative kind.   Let me give you some context on who we actually are, since you asked. L2Scripts has been around for nearly 20 years. Over that time, we've worked with a large number of developers — I've personally seen probably half of every serious (and not-so-serious) developer in this scene. The most significant figure in our studio's history was Bonux. Together with a small team of assistants, he was essentially the backbone of our old codebase, and we were the ones who brought virtually every chronicle to the community — Essence, Classic, Main — all of it came through us.   Back then, we worked at scale. That era is over. Today, L2Scripts is no longer a studio in the traditional sense. It's more of a developer collective. I work alongside the best developers I've encountered in 20 years. Bonux is still with us on Classic. A new developer named Den has joined — in just 3 years he became one of the top Essence developers in the world. Every one of us works independently, but we're united by long-standing friendships and shared projects.   We no longer chase every chronicle or every client. For the past several years, we've been focused exclusively on specific long-term projects where we're paid a proper salary — and when you focus like that, with 20 years of experience behind you, the quality of what you produce is on a completely different level. Our code is currently running on nearly all top Essence and Classic servers. We're now bringing Main (Last Protocol) up to that same standard.   You mentioned Nexvil. Yes, he worked with us. That was a difficult period — the lead developer at the time was not up to the standard we hold ourselves to. It was a short period, and it's long behind us.   As for the prices — I'd ask you not to judge a product by whether you personally can afford it. That's not a fair measure of value. The people running top-tier servers understand what they're paying for. If our pricing doesn't fit your budget, that's completely fine — but downvoting a service simply because it feels expensive to you doesn't reflect well, and it certainly doesn't make the product worse.   A special thank you to eMommy and Zenith for the honest and fair words — it genuinely means a lot. It's good to know there are people in this community who judge things as they are.
    • Just because someone does professional sales doesn’t mean everything is overpriced. If the products he provides are stable and good quality, then I see nothing wrong with it, and those prices aren’t even bad. Remember, we’re living in 2026, not 10 years in the past. Your mindset is probably stuck on buying the cheapest products because maybe you can’t afford better ones. And of course, there’s always someone who likes blaming others. I think you should mind your own business instead of blaming someone for how they run theirs. If you really think his prices are too expensive, then do better than him.
    • I have to be fair here and state that almost all 'good' servers on Essence/Classic are using bonux/l2scripts files and 10k for a decent essence build imo is not that bad of a price as long as nexvil is not touching these files
    • LF who can make systemchat, autoenchant, autologin and few little fix on 306 for me, pay $$$
    • Implemented ingame drop database, craft database, shop database, best farm for desired item
  • 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..