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.
L2 ArenaWar: Low Rate PvP Server with Free Buffs & Autofarm [PVP]⚔️ [Free]🆓
Classic Interlude with 3x XP rates!
Free starter pack(no grade) to kickstart your adventure!
Autofarm for convenient grinding!
Free buffs to keep you fighting fit! (2 job buffs)
No experience loss on death! (Except with Karma)
Clear Karma system to keep things fair! ⚖️
Active community of 800-1k players!
Join our Discord to learn more!
>> Discord <<
Server website: https://l2arenawar.com/en/
You indeed have to save player position over Enterworld to properly clean it up later (if you don't, even trying to delete packet content would eventually keep it up), that's what we do with debug packet (which is a reusable Map of ExServerPrimitive packets) on aCis.
It doesn't solve the FPS stuttering - more you draw/delete lines, more your client becomes laggy. It's like if client wasn't deleting drawn points/lines properly, but instead simply hide them and redrawn content above.
If you got a solution, I would happy to integrate it.
You should check aCis#Player _debug packet integration, it allows very big amount of lines/points to be drawn, it is also reusable.
https://gitlab.com/Tryskell/acis_public/-/blob/master/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java?ref_type=heads
https://gitlab.com/Tryskell/acis_public/-/blob/master/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java?ref_type=heads
we sell website templates, make websites to order. Great selection at very good prices.
My contacts
discord : advert1231
telegram : https://t.me/ggwpins
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 StealthyS4mLink to comment
Share on other sites
15 answers to this question
Recommended Posts