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: 

  Reveal hidden contents

 

Also i tried something like this but nothing:

  Reveal hidden contents

 

 

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)
  On 4/1/2021 at 2:37 AM, 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;
}

Expand  

like that?

 

  Reveal hidden contents

 

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)
  On 4/1/2021 at 9:57 AM, 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)

Expand  

like that in l2PcInstance?

  Reveal hidden contents

 

 

 

and in zone like that? 

  Reveal hidden contents



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)
  On 4/2/2021 at 7:18 AM, 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.

 

 

 

 

 

 

Expand  

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

    • Running ads or working with voice verification? We provide the essential tools for arbitrage, marketing, e-commerce, and anonymous operations! Ready-to-use Google Ads and Google Voice accounts — verified, warmed up, with logs and full access. Perfect for: ✔ Media buyers launching campaigns via Google ✔ Agencies and PPC specialists ✔ Businesses needing fast and safe ad launches without bans ✔ Users working with Google Voice (2nd-step verification, US numbers, etc.) ✔ Google Ads: accounts with budgets from €10 to $1000+, with or without verification ✔ All come with 2FA, backup email, cookies, and UserAgent Promo code: GOOGLE10 (10% discount) Payment: bank cards · crypto · other popular methods How to buy: ➡ Online Store: Click ➡ Telegram Bot: Click Other services: ➡ SMM Panel: Click Assortment: ➡Google Voice Accounts (GMAIL US NEW) | Year: 2024 (random) | Phone Verified | Price from: $9.00 ➡Google Voice Accounts (GMAIL US OLD) | Year: 2006–2018 | Phone Verified | Price from: $14.00 ➡Google Ads Account USA/EUROPE (UK, Germany, France, etc.) | Manually farmed 7+ days | Created ad account | Includes 2FA, backup codes, backup email, UserAgent, Cookies | Price from: $13.00 ➡Google Ads Account USA/EUROPE | VERIFICATION COMPLETED – €10 BILL | Manually farmed 7+ days | Ad created | Includes 2FA, backup email, UserAgent, Cookies | Price from: $55.00 ➡Google Ads Account EUROPE/USA with ad campaigns and spend $100/$500/$1000+ | Verification not completed | Full access & setup | Price from: $200.00 ➡Google Ads Account EUROPE/USA with ad campaigns and spend $100/$500/$1000+ | Verification completed | Full access & setup | Price from: $400.00 Regular buyers get extra discounts and promo codes! Support: ➡ Telegram: https://t.me/solomon_bog ➡ Discord: https://discord.gg/y9AStFFsrh ➡ WhatsApp: https://wa.me/79051904467 ➡ ✉ Email: solomonbog@socnet.store ➡ Telegram Channel: https://t.me/accsforyou_shop You can also use these contacts to: — Discuss wholesale orders — Propose partnerships (current partners: https://socnet.bgng.io/partners ) — Become a supplier SocNet — Digital Goods & Premium Subscriptions Store
    • Running ads or working with voice verification? We provide the essential tools for arbitrage, marketing, e-commerce, and anonymous operations! Ready-to-use Google Ads and Google Voice accounts — verified, warmed up, with logs and full access. Perfect for: ✔ Media buyers launching campaigns via Google ✔ Agencies and PPC specialists ✔ Businesses needing fast and safe ad launches without bans ✔ Users working with Google Voice (2nd-step verification, US numbers, etc.) ✔ Google Ads: accounts with budgets from €10 to $1000+, with or without verification ✔ All come with 2FA, backup email, cookies, and UserAgent Promo code: GOOGLE10 (10% discount) Payment: bank cards · crypto · other popular methods How to buy: ➡ Online Store: Click ➡ Telegram Bot: Click Other services: ➡ SMM Panel: Click Assortment: ➡Google Voice Accounts (GMAIL US NEW) | Year: 2024 (random) | Phone Verified | Price from: $9.00 ➡Google Voice Accounts (GMAIL US OLD) | Year: 2006–2018 | Phone Verified | Price from: $14.00 ➡Google Ads Account USA/EUROPE (UK, Germany, France, etc.) | Manually farmed 7+ days | Created ad account | Includes 2FA, backup codes, backup email, UserAgent, Cookies | Price from: $13.00 ➡Google Ads Account USA/EUROPE | VERIFICATION COMPLETED – €10 BILL | Manually farmed 7+ days | Ad created | Includes 2FA, backup email, UserAgent, Cookies | Price from: $55.00 ➡Google Ads Account EUROPE/USA with ad campaigns and spend $100/$500/$1000+ | Verification not completed | Full access & setup | Price from: $200.00 ➡Google Ads Account EUROPE/USA with ad campaigns and spend $100/$500/$1000+ | Verification completed | Full access & setup | Price from: $400.00 Regular buyers get extra discounts and promo codes! Support: ➡ Telegram: https://t.me/solomon_bog ➡ Discord: https://discord.gg/y9AStFFsrh ➡ WhatsApp: https://wa.me/79051904467 ➡ ✉ Email: solomonbog@socnet.store ➡ Telegram Channel: https://t.me/accsforyou_shop You can also use these contacts to: — Discuss wholesale orders — Propose partnerships (current partners: https://socnet.bgng.io/partners ) — Become a supplier SocNet — Digital Goods & Premium Subscriptions Store
  • 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