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.
Hello. You may encounter the Push item fail error when trying to pick up an item dropped on the ground by a mob.
or
You can throw something out of your inventory and pick it up again, several times.
Probably this is a quantum dependency) I don't understand at what point this happens, sometimes two items one after another experience push item errors, and sometimes I don't have enough thousands of attempts to repeat this trick)
In any case, this is just a visual error and after the relog, the item appears in the inventory. I think first i need to disconnect the extender and check it on a bare server. I still need time to check this, maybe it's not even about the autoloot function.
https://youtu.be/6mcfmdImofE
-----------
In general, I would like to thank our wonderful Emca Eressea for her deep knowledge in programming and reverse engineering. And for the fact that her work is open to everyone, this is very amazing, and incredibly valuable.
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