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
  • Thanks 1
  • 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

    • L2 Kings    Stage 1 – The Awakening Dynasty and Moirai Level Cap: 83 Gear: Dynasty -Moirai & Weapons (Shop for Adena + Drop from mobs/instances ) Masterwork System: Available (Neolithics S required with neolithics u can do armor parts foundation aswell) Class Cloaks: Level 1 - Masterwork sets such us moirai/dynasty stats are boosted also vesper(stage 2) Olf T-Shirt: +6 (fails don’t reset) safe is +2 Dolls: Level 1 Belts: Low & Medium Enchant: Safe +3 / Max +8 / Attribution Easy in Moirai-Dynasty . Main Zones: Varka Outpost: Easy farm, Adena, EXP for new players = > 80- 100kk hour Dragon Valley: Main farm zone — , 100–120kk/hour Weapon Weakness System active (all classes can farm efficiently) Archers get vampiric auto-hits vs mobs Dragon Valley Center: Main Party Zone — boosted drops (Blessed enchants, Neolithics chance) => farm like 150-200kk per hour. Dragon Valley North: Spoil Zone (Asofe + crafting materials for MW) Primeval Isle: Safe autofarm zone (low adena for casual players) ==> 50kk per hour Forge of the Gods & Imperial Tomb: Available from Stage 1 (lower Adena reward in compare with Dragon Valley) Hellbound also avaliable from stage 1 In few words all zones opened but MAIN farm zone with boosted adena and drops is Dragon valley also has more mobs Instances: Zaken (24h Reuse) → Instead of Vespers drop Moirai , 100% chance to drop 1 of 9 dolls lvl 1, Zaken 7-Day Jewelry Raid Bosses (7 RBs): Drop Moirai Parts + Neolithic S grade instead of Vespers parts that has 7 Rb Quest give Icarus Weapons Special Feature 7rb bosses level up soul crystals aswell. Closed Areas : Monaster of SIlence, LOA, ( It wont have mobs) / Mahum Quest/Lizardmen off) Grand Epics: Unlocked on Day 4 of Stage 1 → Antharas, Valakas, Baium, AQ, etc ================================================================================= Stage 2 – Rise of Vespers Level Cap: 85 Gear: Moirai Armors (Adena GM SHOP / Craft/ Drop) Weapons: Icarus Cloaks: Level 2 Olf: +8 Dolls: Level 2 Belts: High & Top Enchant: Safe +3 / Max +8 Masterwork can be with Neolithics S84 aswell but higher so craft will be usefull aswell. 7 Raid Boss Quest Updated: Now works retail give vesper weapons 7rb Bosses Drops : Vespers Instances: Zaken : Drops to retail vespers + the dolls and the extra items that we added on stage 1 New Freya Instance: Added — drops vespers and instead of mid s84 weapons will drop vespers . Extra drops Blessed Bottle of Freya - drops 100% chance 1 of 9 dolls. Farm Areas Dragon Valley remains main farm New Zone : Lair of Antharas (mobs nerfed and added drop Noble stone so solo players can farm too) New Party Zone : LOA Circle   ============================================================================   Stage 3 – The Vorpal ERA Gear: Vorpal Unclock Cloaks: Level 3 Olf: +10 (max cap) Dolls: Level 3 Enchant: Safe +3 / Max +12 Farm Zones : Dragon Valley Center Scorpions becomes a normal solo zone (no longer party zone) Drops:   LOA & Knorik → Mid Weapons avaliable in drop New Party Zone Kariks Instances: Easy Freya Drops Mid Weapons Frintezza Release =================================================================================     Stage 4 – Elegia Era (Final Stage) Elegia Unlock Gear: Elegia Weapons: Elegia TOP s84 ( farmed via H-Freya/ Drops ) Cloaks: Level 5 Dolls: Level 3 (final bonuses) Enchant: Safe +6 / Max +16 Instances: Hard Freya → Drops Elegia Weapons + => The Instance will drop 2-3 parts for sure and also will be able to Join with 7 people . Party Zone will have also drop chances for elegia armor parts and weapons but small   Events (Hourly): Win: 50 Event Medals + 3 GCM + morewards Lose: 25 Medals + 1 GCM + more rewards Tie: 30 Medals + 2 GCM + more rewards   ================================================================================ Epic Fragments Currency Participating in Daily Bosses mass rewarding all players Participating in Instances (zaken freya frintezza etc) all players get reward ================================================================================ Adena - Main server currency (all items in gm shop require adena ) Event Medals (Festival Adena) - Event shop currency Donation coins you can buy with them dressme,cosmetics and premium account Epic Fragments you can buy with them fake epic jewels Olympiad Tokens you can buy many items from olympiad shop (Hero Coin even items that are on next stages) Olympiad Win = 1000 Tokens / Lose = 500 Tokens ================================================================================= Offline Autofarm Allows limited Offline farming requires offline autofarm ticket that you get by voting etc ================================================================================= Grand Epics have Specific Custom NPC that can spawn Epics EU/LATIN TIME ZONE ================================================================================= First Olympiad Day 19 December First Heroes 22 December ( 21 December Last day of 1st Period) After that olympiad will be weekly. ================================================================================= Item price and economy Since adena is main coin of server and NOT donation coins we will always add new items in gm shop with adena in order to burn the adena of server and not be inflation . =================================================================================        
    • Hello, I'd like to change a title color for custom npc.  I created custom NPC, cloned existing. I put unique id for it in npcname-e, npcgrp and database. I have "0" to serverSideName in db, so that it would use npcname-e, but instead it has "NoNameNPC"and no title color change.
    • Trusted Guy 100% ,  I asked him for some work and he did it right away.
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock