I want to buy a working code for kamaloka:
1. 1 instance where a party can join only 1 time per day. The time need to reset every day 6:30
if the player die, he can not go again.
2. Instance 2. Solo instance. 60 minutes time limit.
- Can join 2 times per day. 1st reset at 6:30 am second reset 6:30 pm.
If the player dies he can not enter again
Both instances need to have IP and account protection so the players can not join second time.
DM with your offer!
I tried many ways but nothing works. I even write custom code and again it don't work.
I'm tired of this kamaloka!!!!!!!!!!!!!!!
1. 1 instance where a party can join only 1 time per day. The time need to reset every day 6:30
if the player die, he can not go again.
2. Instance 2. Solo instance. 60 minutes time limit.
- Can join 2 times per day. 1st reset at 6:30 am second reset 6:30 pm.
If the player dies he can not enter again
Both instances need to have IP and account protection so the players can not join second time.
DM with your offer!
I tried many ways but nothing works. I even write custom code and again it don't work.
I'm tired of this kamaloka!!!!!!!!!!!!!!!
Code:
package npc.model;
import l2.gameserver.database.DatabaseFactory;
import l2.gameserver.instancemanager.ReflectionManager;
import l2.gameserver.model.Party;
import l2.gameserver.model.Player;
import l2.gameserver.model.entity.Reflection;
import l2.gameserver.model.instances.NpcInstance;
import l2.gameserver.templates.npc.NpcTemplate;
import l2.gameserver.utils.ItemFunctions;
import l2.gameserver.utils.ReflectionUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
public final class EventReflectionManagerInstance extends NpcInstance {
private static final int PARTY_INSTANCE_ID = 72;
private static final int SOLO_INSTANCE_ID = 71;
private static final int PARTY_ENTRY_ITEM_ID = 16101;
private static final int SOLO_ENTRY_ITEM_ID = 16103;
private static final int REQUIRED_PARTY_ITEM_COUNT = 100;
private static final int REQUIRED_SOLO_ITEM_COUNT = 3;
private static final Map<Integer, Boolean> deadPlayers = new HashMap<>();
public EventReflectionManagerInstance(int objectId, NpcTemplate template) {
super(objectId, template);
}
@Override
public void onBypassFeedback(Player player, String command) {
if (!canBypassCheck(player, this)) {
return;
}
if (command.startsWith("event_instance 72")) {
handleEnterInstance(player, true);
} else if (command.startsWith("event_instance 71")) {
handleEnterInstance(player, false);
} else if (command.startsWith("escape_event_instance")) {
handleEscapeInstance(player);
} else if (command.startsWith("return")) {
handleReturn(player);
} else {
super.onBypassFeedback(player, command);
}
}
private void handleEnterInstance(Player player, boolean isPartyInstance) {
int instanceId = isPartyInstance ? PARTY_INSTANCE_ID : SOLO_INSTANCE_ID;
int requiredItemId = isPartyInstance ? PARTY_ENTRY_ITEM_ID : SOLO_ENTRY_ITEM_ID;
int requiredItemCount = isPartyInstance ? REQUIRED_PARTY_ITEM_COUNT : REQUIRED_SOLO_ITEM_COUNT;
String accountName = player.getAccountName();
String ipAddress = player.getNetConnection().getIpAddr();
// Check if the player has already entered or died in this instance
if (!canEnterInstance(accountName, ipAddress, instanceId, player)) {
player.sendMessage("You have already entered this instance today or died inside.");
return;
}
if (!isPartyInstance && player.getInventory().getCountOf(requiredItemId) < requiredItemCount) {
player.sendMessage("You need " + requiredItemCount + " of item " + requiredItemId + " to enter.");
return;
}
if (isPartyInstance) {
Party party = player.getParty();
if (party == null || !party.isLeader(player)) {
player.sendMessage("You must be the party leader to enter.");
return;
}
for (Player member : party.getPartyMembers()) {
if (member.getInventory().getCountOf(requiredItemId) < requiredItemCount) {
member.sendMessage("You do not have enough items to enter.");
return;
}
}
}
Reflection existingReflection = player.getActiveReflection();
if (existingReflection != null) {
player.teleToLocation(existingReflection.getTeleportLoc(), existingReflection);
} else {
if (player.canEnterInstance(instanceId)) {
ItemFunctions.removeItem(player, requiredItemId, requiredItemCount, true);
ReflectionUtils.enterReflection(player, instanceId);
// Save entry to the database to prevent re-entry
saveEntryTime(accountName, ipAddress, instanceId, player);
}
}
}
private void handleEscapeInstance(Player player) {
player.sendMessage("Instance will collapse.");
player.getReflection().collapse();
}
private void handleReturn(Player player) {
Reflection r = player.getReflection();
if (r.getReturnLoc() != null) {
player.teleToLocation(r.getReturnLoc(), ReflectionManager.DEFAULT);
} else {
player.setReflection(ReflectionManager.DEFAULT);
}
}
private long getNextResetTime(boolean isPartyInstance) {
java.util.Calendar nextReset = java.util.Calendar.getInstance();
int hour = isPartyInstance ? 6 : (nextReset.get(java.util.Calendar.HOUR_OF_DAY) < 18 ? 6 : 18);
nextReset.set(java.util.Calendar.HOUR_OF_DAY, hour);
nextReset.set(java.util.Calendar.MINUTE, 30);
nextReset.set(java.util.Calendar.SECOND, 0);
if (nextReset.getTimeInMillis() < System.currentTimeMillis()) {
nextReset.add(java.util.Calendar.DAY_OF_MONTH, 1);
}
return nextReset.getTimeInMillis();
}
private void saveEntryTime(String accountName, String ipAddress, int instanceId, Player player) {
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(
"INSERT INTO event_instance_restrictions (account_name, ip_address, last_entry_time, instance_id, dead) " +
"VALUES (?, ?, ?, ?, 0) ON DUPLICATE KEY UPDATE last_entry_time = VALUES(last_entry_time)")) {
ps.setString(1, accountName);
ps.setString(2, ipAddress);
ps.setLong(3, System.currentTimeMillis());
ps.setInt(4, instanceId);
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean canEnterInstance(String accountName, String ipAddress, int instanceId, Player player) {
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(
"SELECT last_entry_time, dead FROM event_instance_restrictions WHERE (account_name = ? OR ip_address = ?) AND instance_id = ?")) {
ps.setString(1, accountName);
ps.setString(2, ipAddress);
ps.setInt(3, instanceId);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
long lastEntryTime = rs.getLong("last_entry_time");
boolean isDead = rs.getBoolean("dead");
return lastEntryTime < getNextResetTime(instanceId == PARTY_INSTANCE_ID) && !isDead;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}