Jump to content
  • 0

check if player.isDead() method


Irrelevant

Question

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
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

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
  • Thanks 1
Link to comment
Share on other sites

  • 0

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;
}

Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Posts

    • - lost love spells caster in, Amsterdam,Brazil,London,Kuwait .Egypt, Atlanta, Latvia, Lithuania, Sweden۞۩ஜ???? +256704892479  Results are 100% s=ure and guaranteed, spell casting specialist, , black magic death spells that work overnight or by accident. I Cast these strongest black magic revenge death spells that work fast overnight to kill ex-lover, husband, wife girlfriend Enemies overnight Https://nativelovespellscaster.com or she is in a far location, I guarantee you to have your results you are looking for immediately. Just make sure before you contact me you are committed and you want what you are looking for (Victim Death) because my death spell work fast overnight after casting the spells that work, guaranteed black magic love spells, guaranteed voodoo spells, spell to make someone sick and die, revenge spells that work instantly, real witches for hire, revenge spells on an ex- lover, how to put a Black magic death spells on ex-lover, Revenge instant death spells on toxic uncles powerful instant death spells online instant spell that work fast in USA, UK, Kuwait, Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece. Death spell on someone, death spells that Death Revenge Spell on wicked friends, Voodoo Death Spells to kill Enemies Black Magic Spells To Harm Someone, Black magic death spells on ex-lover, Revenge instant death spells on toxic uncles powerful instant death spells online instant spell that work fast in USA, UK, Kuwait, Germany, Asian, Europe, Philippines, Canada, revenge spells, most powerful death spell, spell to die in your sleep, successful death spell, most powerful voodoo spell caster, voodoo spell casters in new Orleans, voodoo love spells reviews, proven authentic voodoo spell casters, most powerful voodoo priest in world, black magic tricks to destroy enemy. Results are 100% sure and guaranteed whatapp or cal, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. spells, guaranteed voodoo spells, spell to make someone sick and die, revenge spells that work instantly, real witches for hire, revenge spells on an ex- lover, how to put a spell on someone who hurts you, spell to make someone sick, voodoo spells to hurt someone, spells to curse someone, powerful revenge spells, most powerful death spell, spell to die in your sleep, successful death spell, most powerful voodoo spell caster, voodoo spell casters in new Orleans, voodoo love spells reviews, proven authentic voodoo spell casters, most powerful voodoo priest in world, black magic tricks to destroy enemy. Results are 100% sure and guaranteed whatapp or call  ஜ۩۞۩ஜ ??? + 256704892479ஜ۩۞۩ஜ ??Https://nativelovespellscaster.com
    • Hello, my discord is : misanthropic1085           I am selling Frintezza Aq Baium     Reborn origins x1    
    • L2Topzone has a lower traffic ranking than every other website! We spent over 160 Euro for listing server and banner and we've got only 4 download conversions!  Proof: https://prnt.sc/YeJudEKFov1m
    • Any WTS code global chat for this? 
    • Hi, I see what you mean, but I do it differently.   I don't want some features from Hi5 in my project, so I gradually add Ai, zones, items, etc... manually.   And again I want some features from Classic.   So I'm continuing the Classic storyline up to High Five.   My project runs on the client's Prelude of War.   I will release the first public test version soon, which will still be without some "hi5" stuff, because first I need to test for example Fortress Siege, pets and some instances/quests. In the future, I also want to "unlock" new locations from the GoD story.   And what I like most about Classic is that you don't have SA in weapons and it goes back to the roots of Lineage 2. Also you can connect to my discord and talk about with me.
  • Topics

×
×
  • Create New...