Hello guys, I have a custom zone and whenever you die in that zone it shows you the timer when you will respawn and after timer reaches 0 it respawns you.This was my first try:
public void onDieInside(L2Character character)
{
if(character instanceof L2PcInstance){
final L2PcInstance player = (L2PcInstance) character;
countdown = 5;
ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable(){
@Override
public void run(){
if(player.isDead()){
if(countdown >0){
SystemMessage smg = SystemMessage.getSystemMessage(SystemMessageId.RESPAWN_AFTER_S1_SECONDS);
smg.addString(String.valueOf(countdown));
player.sendPacket(SystemMessageId.RESPAWN_AFTER_S1_SECONDS);
countdown--;
}else if(countdown == 0){
player.doRevive();
int x = 174132 + (int)(Math.random() * ((179862 - 174132) + 1));
int y = 112225 + (int)(Math.random() * ((117715 - 112225) + 1));
int z = -7708;
Location loc = new Location(x, y, z);
player.teleToLocation(loc,0);
}
}
}
}
,0,1000);
}
}
It works fine for first time,but then it just get shorter and shorter.I believe it's because thread doesn't stop working after respawning player,so whenever a player dies again the countdown is set to 5,but there is 2threads running and subtracting 1from countdown and then threads just keep increasing. My second try was this method:
public void onDieInside(L2Character character)
{
if(character instanceof L2PcInstance){
final L2PcInstance player = (L2PcInstance) character;
countdown = 5;
while(countdown > 0 && player.isDead()){
ThreadPoolManager.getInstance().scheduleGeneral(new showCountdown(countdown,player), 6000-countdown*1000);
countdown--;
}
ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
@Override
public void run(){
if(player.isDead()){
player.doRevive();
int x = 174132 + (int)(Math.random() * ((179862 - 174132) + 1));
int y = 112225 + (int)(Math.random() * ((117715 - 112225) + 1));
int z = -7708;
Location loc = new Location(x, y, z);
player.teleToLocation(loc,0);
}
}
}, 6000);
}
}
This is showCountdown class:
class showCountdown implements Runnable{
int timer = 0;
L2PcInstance player;
public showCountdown(int countdown,L2PcInstance p){
timer = countdown;
player = p;
}
@Override
public void run(){
SystemMessage smg = SystemMessage.getSystemMessage(SystemMessageId.RESPAWN_AFTER_S1_SECONDS);
smg.addNumber(timer);
player.sendPacket(smg);
}
}
It works just fine,but it seems dumb just to create so many Threads for a simple countdown.
DISCORD :
utchiha_market
telegram :
https://t.me/utchiha_market
SELLIX STORE :
https://utchiha.sellpass.io/
Join our server for more products :
https://discord.gg/uthciha-services
https://campsite.bio/utchihaamkt
DISCORD :
utchiha_market
telegram :
https://t.me/utchiha_market
SELLIX STORE :
https://utchiha.sellpass.io/
Join our server for more products :
https://discord.gg/uthciha-services
https://campsite.bio/utchihaamkt
🔥 L2Gold.co x15 Interlude Server 2025 – Grand Opening! 🔥
Join us today and be part of the legendary L2Gold community!
🎉 Grand Opening: 14 March 2025 🎉
⏰ Time: 21:00 GMT +2
🌍 Server Type: EURO PTS/L2OFF
🌟 Why Play on L2Gold.co? 🌟
✅ No Wipes – Keep Your Progress Forever!
Your characters and progress are permanent. No resets!
✅ Balanced & Fun Gameplay!
Experience x15 rates for a smooth and enjoyable progression.
✅ Solo or Party Play
Use MP potions and NPC buffers for a great solo experience or team up with friends.
✅ Long-Term Stability
Our server is built to last with no interruptions!
📊 Server Rates & Details 📊
Category
Rate
EXP/SP
x15 (Official rate without rune or VIP)
Adena
x10 (Official rate without rune or VIP)
Drop
x10 (Official rate without rune or VIP)
Spoil
x10 (Official rate without rune or VIP)
Raid Boss Drop
x10 (Official rate without rune or VIP)
🚀 Exciting New Features! 🚀
🎟️ 💰 Weekly Lottery System! – Win rare items, in-game currency, and exclusive rewards!
🎁 More Events & Rewards! – Special in-game activities with exclusive items!
📈 Real-Time Stats! – Track your progress, achievements, and rankings live!
⚔️ New Items Weekly! – Discover rare gear and unique items every week!
🌍 A Growing Global Community 🌍
Players from Greece 🇬🇷, Brazil 🇧🇷, Spain 🇪🇸, and beyond!
🔗 Stay Connected 🔗
Follow us on social media to stay updated!
🌎 Website: L2Gold.co
🎙️ Discord: Server
📘 Facebook: Page | Group
🎥 YouTube: Watch Videos
🎵 TikTok: Follow Us
🔥 Prepare for Battle! 🔥
📅 The adventure begins on 14 March 2025!
Join L2Gold.co and Experience an Unforgettable Adventure! 🎮✨
Hi, im looking for cardinal pvp script for auto cleanse/rez/nobles etc etc and guide on how to setup as well as what programms do i need to run such scripts as i have never used any helper or something before,
Question
StealthyS4m
Hello guys,
I have a custom zone and whenever you die in that zone it shows you the timer when you will respawn and after timer reaches 0 it respawns you.This was my first try:
It works fine for first time,but then it just get shorter and shorter.I believe it's because thread doesn't stop working after respawning player,so whenever a player dies again the countdown is set to 5,but there is 2threads running and subtracting 1from countdown and then threads just keep increasing.
My second try was this method:
This is showCountdown class:
It works just fine,but it seems dumb just to create so many Threads for a simple countdown.
Edited by StealthyS4m15 answers to this question
Recommended Posts