Looking to add a timer to using the logout button in-game (deadman mode mechanic)
this will prevent players from instantly being able to logout - instead they will have to wait approximately 10 seconds countdown before the logout button will remove them from game ( this countdown timer can be interrupted by combat from another player/npc! )
Using the base code from spawning animated armor in warrior's guild for this, so including that here
Spoiler for Spawn animated armor in Warriors' Guild:
Code:
private void spawn(Player player, GameObject gameObject) {
if(player.npcTarget) {
player.sendMessage("You are already under attack!");
return;
}
ArrayList<Item> items = player.getInventory().collectOneOfEach(armorIds);
if(items == null) {
player.sendMessage("To animate this armor, you'll need a full helm, platebody, and pair of platelegs.");
return;
}
player.startEvent(event -> {
player.lock();
player.dialogue(new MessageDialogue("You place your armour on the platform where it disappears...").hideContinue());
event.delay(1);
player.animate(827);
event.delay(3);
for(Item armor : items)
armor.remove();
event.delay(2);
player.dialogue(new MessageDialogue("The animator hums, something appears to be working. You stand back...").hideContinue().lineHeight(31));
event.delay(2);
player.getMovement().force(0, 2, 0, 0, 45, 126, Direction.SOUTH);
event.delay(1);
player.animate(820, 5);
event.delay(3);
NPC npc = new NPC(npcId)
.spawn(gameObject.x, gameObject.y, 0, Direction.SOUTH, 0)
.targetPlayer(player, true);
npc.forceText("I'M ALIVE!");
npc.animate(4166, 1);
event.delay(2);
npc.attackTargetPlayer(() -> !player.getPosition().inBounds(ATTACK_BOUNDS), () -> {
if(npc.getCombat().isDead())
new GroundItem(8851, tokenCount).owner(player).position(npc.getPosition()).spawn();
for(int id : armorIds)
new GroundItem(id, 1).owner(player).position(npc.getPosition()).spawn();
});
player.closeInterface(InterfaceType.CHATBOX);
player.unlock();
});
}
this is as far as I have got with the code so far:
Spoiler for 1st revision:
Code:
public void attemptLogout() {
if (combat.isDead() || combat.isDefending(16)) { //TODO 16 (9.6) or 17 (10.2) ?
sendMessage("You can't log out until 10 seconds after the end of combat.");
return;
}
if (supplyChestRestricted) {
sendMessage("The power of the supply chest prevents you from logging out!");
return;
}
if (isLockedExclude(LockType.FULL_ALLOW_LOGOUT) && player.getAppearance().getNpcId() == -1)
return;
if (logoutListener != null && logoutListener.attemptAction != null && !logoutListener.attemptAction.allow(this))
return;
// TODO
player.startEvent(event -> {
player.sendMessage("Trying to escape? You must wait 10 seconds before logging out.");
event.delay(16);
if (player.getCombat().isDefending(16)) {
logoutStage = 0;
} else {
logoutStage = 1;
}
//0=no logout, 1=logout required, -1=logout accepted
//logoutStage = 1;
packetSender.sendDiscordPresence("In Lobby");
packetSender.sendLogout();
});
}
Spoiler for 2nd revision:
Code:
public void attemptLogout() {
if(combat.isDead() || combat.isDefending(16)) { //TODO 16 (9.6) or 17 (10.2) ?
sendMessage("You can't log out until 10 seconds after the end of combat.");
return;
}
if(supplyChestRestricted) {
sendMessage("The power of the supply chest prevents you from logging out!");
return;
}
if(isLockedExclude(LockType.FULL_ALLOW_LOGOUT) && player.getAppearance().getNpcId() == -1)
return;
if(logoutListener != null && logoutListener.attemptAction != null && !logoutListener.attemptAction.allow(this))
return;
player.startEvent(event -> {
player.sendMessage("Running away? Not so fast!"); //There are X seconds remaining until you can logout...
sendMessage("There are 7 seconds remaining until you can logout...");
event.delay(2); // 6.0
sendMessage("There are 6 seconds remaining until you can logout...");
event.delay(2); // 4.8
sendMessage("There are 5 seconds remaining until you can logout...");
event.delay(2); // 3.6
sendMessage("There are 4 seconds remaining until you can logout...");
event.delay(2); // 2.4
sendMessage("There are 3 seconds remaining until you can logout...");
event.delay(2); // 1.2
sendMessage("There are 2 seconds remaining until you can logout...");
event.delay(2); // 0
sendMessage("There is 1 second remaining until you can logout...");
if (player.getCombat().isDefending(16)) {
logoutStage = 0;
}
else {
logoutStage = 1;
packetSender.sendDiscordPresence("In Lobby");
packetSender.sendLogout();
}
});
}
I'm not sure how Kronos is but we did this back when i did work for some Project Insanity servers and it might be useful or put you in the correct direction.
You could send a dialogue in the timer itself to start the countdown when called upon
Code:
public void runTimer(){
int i = 10; //Time In Seconds
while (i>0){
c.getDH().sendDialogue( "You can not logout!', "You can not logout for" +i+ "Seconds!", null);
try {
i--;
Thread.sleep(1000L); // 1000L = 1000ms = 1 second
}
catch (InterruptedException e) {
}
}
}
}
Then where you call your denyLogout() method you could call in that bit of code and it *should* work?
As i said it has been a while but i hope i helped you in the correct direction.
Originally Posted by i am here
I have never messed with Eclipse. Is it a whole new revision or type of code?
Originally Posted by bibl
hahaha, good one m9. "deob" is short for "deobfuscated" which is not the same as decompiled.
I'm not sure how Kronos is but we did this back when i did work for some Project Insanity servers and it might be useful or put you in the correct direction.
You could send a dialogue in the timer itself to start the countdown when called upon
Code:
public void runTimer(){
int i = 10; //Time In Seconds
while (i>0){
c.getDH().sendDialogue( "You can not logout!', "You can not logout for" +i+ "Seconds!", null);
try {
i--;
Thread.sleep(1000L); // 1000L = 1000ms = 1 second
}
catch (InterruptedException e) {
}
}
}
}
Then where you call your denyLogout() method you could call in that bit of code and it *should* work?
As i said it has been a while but i hope i helped you in the correct direction.
would avoid using thread.sleep, it renders that specific thread unusable. This should only be used in small cases, my suggestion would be to use an eventcycle and inside of the event itself use your "senddialogue" method to send the message and then in the stop portion of the event do the teleport/logout code, also make sure you do stop checks for things like teleblock and getting attacked by other players. (put those stop checks obviously in the event)
▼▼▼ Click to checkout DarkScape a World PvP server in the works! ▼▼▼