Gatakeeper event like L2Gold - (need help with this)

fa1thDEV

Baron
Customer
1- Create the EventGatekeeper class that extends L2Npc.
2- Add a stopwatch to check the time.
3- Change the HTML of the NPC at the specified time.
4- Make the NPC disappear after one hour.
5- Keep the original teleportation functionality.


CODE EXAMPLE:


JavaScript:
// File path: java/com/l2jserver/gameserver/services/EventGatekeeper.java

package services;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import l2.gameserver.ThreadPoolManager;
import l2.gameserver.model.actor.L2Npc;
import l2.gameserver.model.actor.instance.L2PcInstance;
import l2.gameserver.model.actor.templates.L2NpcTemplate;
import l2.gameserver.network.serverpackets.NpcHtmlMessage;

public class EventGatekeeper extends L2Npc {
    private boolean isEventActive = false;
    private Timer timer;

    public EventGatekeeper(int objectId, L2NpcTemplate template) {
        super(objectId, template);
        startEventTimer();
    }

    private void startEventTimer() {
        timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                checkEventTime();
            }
        }, 0, 60000); // Check every minute
    }

    private void checkEventTime() {
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        
        if (hour >= 18 && hour < 19) { // Assuming event is from 18:00 to 19:00
            isEventActive = true;
        } else {
            isEventActive = false;
        }
        
        if (hour == 19) { // At 19:00 make the NPC disappear
            this.deleteMe();
            timer.cancel();
        }
    }

    @Override
    public void showChatWindow(L2PcInstance player) {
        if (isEventActive) {
            NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
            html.setHtml("<html><body>Event Teleport<br><button value=\"Go to Event\" action=\"bypass -h npc_" + getObjectId() + "_event_teleport\" width=200 height=30 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></body></html>");
            player.sendPacket(html);
        } else {
            super.showChatWindow(player); // Show normal teleport options
        }
    }

    @Override
    public void onBypassFeedback(L2PcInstance player, String command) {
        if (command.startsWith("event_teleport")) {
            teleportPlayerToEvent(player);
        } else {
            super.onBypassFeedback(player, command); // Handle normal teleport options
        }
    }

    private void teleportPlayerToEvent(L2PcInstance player) {
        // Implement event teleport logic
        player.teleToLocation(12345, 67890, -9876); // Example coordinates
    }
}

Integration with the server:
Register the new NPC on the server:
Make sure to define the NPC in the server data files so that it appears in the game world.

Update the server startup logic:
In the server startup logic, instance and register the new EventGatekeeper.

CODE:


JavaScript:
// File path: java/com/l2jserver/gameserver/GameServer.java

import services.EventGatekeeper;
import l2.gameserver.model.actor.templates.L2NpcTemplate;
import l2.gameserver.data.xml.holder.NpcTemplateHolder;

// Somewhere in the server initialization logic
L2NpcTemplate template = NpcTemplateHolder.getInstance().getTemplate(npcId); // Use the appropriate NPC ID
EventGatekeeper eventGatekeeper = new EventGatekeeper(objectId, template);
 
btw, for lack of time, I have not been able to test them, but if some being of light, could verify and give me the possible errors, I will try to solve it.
 
Back
Top