I have followed the tutorial how to add custom ext.jar.
I have successfully made a custom NPC instance but I can't make this modification to my gatekeeper.
Basically I need a custom button that will show only from 20:00 to 21:00 every Saturday.
And 1 more button that will change the zones every day at 00:00 server time.
Here is the code and if someone can help me to fix it or to tell me where I wrong I will be very thankful.
FIle name: TeleporterInstance.java
Pakage: npc.model
I have successfully made a custom NPC instance but I can't make this modification to my gatekeeper.
Basically I need a custom button that will show only from 20:00 to 21:00 every Saturday.
And 1 more button that will change the zones every day at 00:00 server time.
Here is the code and if someone can help me to fix it or to tell me where I wrong I will be very thankful.
FIle name: TeleporterInstance.java
Pakage: npc.model
Code:
package npc.model;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import l2.gameserver.model.Player;
import l2.gameserver.model.instances.MerchantInstance;
import l2.gameserver.network.l2.s2c.NpcHtmlMessage;
import l2.gameserver.templates.npc.NpcTemplate;
public class TeleporterInstance extends MerchantInstance {
public TeleporterInstance(int i, NpcTemplate npcTemplate) {
super(i, npcTemplate);
System.out.println("Teleporter script loaded successfully.");
}
public void showChatWindow(Player player, int val, Object... arg) {
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("mods/globalgk/40012.htm");
try {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String currentTime = formatter.format(new Date(System.currentTimeMillis()));
Date dateNow = formatter.parse(currentTime);
// PvP Warzone Button (show only on Saturday)
String pvpWarzoneButton = "";
if (isSaturday() && isPvPWarzoneActive(dateNow)) {
pvpWarzoneButton = "<button value=\"PvP Warzone\" action=\"bypass -h scripts_Util:Gatekeeper -53855 179302 -4640 0\" width=300 height=40 back=\"Iwanoff.ebtn\" fore=\"Iwanoff.01\">";
}
msg.replace("%pvp_warzone%", pvpWarzoneButton);
// Daily Coordinates Button
String dailyCoordsButton = getDailyCoordsButton(dateNow);
msg.replace("%daily_coords%", dailyCoordsButton);
} catch (ParseException e) {
e.printStackTrace();
}
player.sendPacket(msg);
}
private boolean isPvPWarzoneActive(Date currentDate) {
// Define PvP Warzone time interval (example: 20:00:00 to 21:00:00)
String from = "20:00:00";
String to = "21:00:00";
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
try {
Date date_from = formatter.parse(from);
Date date_to = formatter.parse(to);
return (date_from.before(currentDate) && date_to.after(currentDate));
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
private boolean isSaturday() {
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
return (dayOfWeek == Calendar.SATURDAY);
}
private String getDailyCoordsButton(Date currentDate) {
// Get current day of the week
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
// Define zone names for each day of the week
String[] zoneNames = {
"Elven Fortress", // Sunday
"Elven Ruins", // Monday
"Giants Cave", // Tuesday
"Giants Cave", // Wednesday
"Giants Cave", // Thursday
"Giants Cave", // Friday
"Giants Cave", // Saturday
};
// Define coordinates for each day of the week
String[] coordinates = {
"100 200 -300", // Sunday
"150 250 -350", // Monday
"200 300 -400", // Tuesday
"400 300 -400", // Wednesday
"500 300 -400", // Thursday
"100 200 -400", // Friday
"200 300 -400", // Saturday
};
// Return button with zone name for the current day
return "<button value=\"" + zoneNames[dayOfWeek - 1] + "\" action=\"bypass -h scripts_Util:Teleport " + coordinates[dayOfWeek - 1] + "\" width=300 height=40 back=\"Iwanoff.ebtn\" fore=\"Iwanoff.01\">";
}
}
