L2JMobius

High Five Custom Extends Mod

mafias · 4 · 1640

Offline mafias

  • Vassal
  • *
    • Posts: 7
npc GranBoss

Code: [Select]
package custom.GrandBossStatusNPC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.quest.Quest;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;

public class GrandBossStatusNPC extends Quest
{
    // ID NPC
    private static final int NPC_ID = 9000;

    private static final int[] GRAND_BOSS_IDS = { 25512, 29001, 29006, 29014, 29020, 29028, 29068, 29118 };

    private static final Map<Integer, String> GRAND_BOSS_NAMES = new HashMap<>();
    static
    {
        GRAND_BOSS_NAMES.put(25512, "Anakim");
        GRAND_BOSS_NAMES.put(29001, "Queen Ant");
        GRAND_BOSS_NAMES.put(29006, "Core");
        GRAND_BOSS_NAMES.put(29014, "Orfen");
        GRAND_BOSS_NAMES.put(29020, "Baium");
        GRAND_BOSS_NAMES.put(29028, "Antharas");
        GRAND_BOSS_NAMES.put(29068, "Valakas");
        GRAND_BOSS_NAMES.put(29118, "Beleth");
    }

    public GrandBossStatusNPC()
    {
        super(NPC_ID);
        addStartNpc(NPC_ID);
        addTalkId(NPC_ID);
        addFirstTalkId(NPC_ID);
       
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM HH:mm:ss");
        String currentTime = sdf.format(now);
       
        System.out.println("[" + currentTime + "] ✅ GrandBossStatus fue cargado correctamente");
    }

    private Map<Integer, Integer> getBossStatuses()
    {
        Map<Integer, Integer> bossStatuses = new HashMap<>();
        try (Connection con = DatabaseFactory.getConnection();
             PreparedStatement ps = con.prepareStatement("SELECT boss_id, status FROM grandboss_data"))
        {
            try (ResultSet rs = ps.executeQuery())
            {
                while (rs.next())
                {
                    int bossId = rs.getInt("boss_id");
                    int status = rs.getInt("status");
                    bossStatuses.put(bossId, status);
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return bossStatuses;
    }

    private boolean isBossAlive(int bossId, Map<Integer, Integer> bossStatuses)
    {
        Integer status = bossStatuses.get(bossId);
        return status != null && status == 0;
    }

    private String getHtmlForNpc(Npc npc, Player player)
    {
        Map<Integer, Integer> bossStatuses = getBossStatuses();
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body>");
        sb.append("<center><font color=\"LEVEL\">Estado de los Grand Bosses</font></center><br>");
        sb.append("<center><table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">");

        for (int bossId : GRAND_BOSS_IDS)
        {
            String bossName = GRAND_BOSS_NAMES.getOrDefault(bossId, "Desconocido");
            String status = isBossAlive(bossId, bossStatuses) ? "<font color=\"00FF00\">Vivo</font>" : "<font color=\"FF0000\">Muerto</font>";
            sb.append("<tr>");
            sb.append("<td width=\"150\" align=\"center\">").append(bossName).append("</td>");
            sb.append("<td width=\"100\" align=\"center\">").append(status).append("</td>");
            sb.append("</tr>");
        }

        sb.append("</table></center>");
        sb.append("<br><br><center><font color=\"LEVEL\">Información Adicional</font></center><br>");
        sb.append("<p><font color=\"00FF00\">Los Grand Bosses son enemigos formidables que requieren de una estrategia precisa para ser derrotados.</font></p>");
        sb.append("<p><font color=\"00FF00\">Estos jefes ofrecen recompensas únicas que no pueden ser obtenidas de ninguna otra forma.</font></p>");
        sb.append("</body></html>");
        return sb.toString();
    }

    [member=79]override[/member]
    public String onFirstTalk(Npc npc, Player player)
    {
        NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
        String htmlContent = getHtmlForNpc(npc, player);
        html.setHtml(htmlContent);
        player.sendPacket(html);
        return null;
    }

    [member=79]override[/member]
    public String onTalk(Npc npc, Player player)
    {
        NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
        String htmlContent = getHtmlForNpc(npc, player);
        html.setHtml(htmlContent);
        player.sendPacket(html);
        return null;
    }

    public static void main(String[] args)
    {
        new GrandBossStatusNPC();
    }
}

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../xsd/npcs.xsd">
<npc id="9000" displayId="30368" name="Riana" usingServerSideName="true" title="GrandBosses" usingServerSideTitle="true" type="Folk">
<race>HUMAN</race>
<sex>MALE</sex>
<stats>
<vitals hp="2444.46819" hpRegen="7.5" mp="1345.8" mpRegen="2.7" />
<attack physical="688.86373" magical="470.40463" random="30" critical="4" accuracy="95" attackSpeed="253" type="SWORD" range="40" distance="80" width="120" />
<defence physical="295.91597" magical="216.53847" />
<speed>
<walk ground="40" />
<run ground="120" />
</speed>
</stats>
<status attackable="false" />
<collision>
<radius normal="8" />
<height normal="23" />
</collision>
</npc>
</list>

Time Item Reward
Code: [Select]
// TimedItemReward.java
package custom.events;

import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.network.SystemMessageId;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.util.Broadcast;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class TimedItemReward
{
    private static final int REWARD_ITEM_ID_1 = 959;
    private static final long REWARD_AMOUNT_1 = 1;
    private static final int REWARD_ITEM_ID_2 = 960;
    private static final long REWARD_AMOUNT_2 = 1;
    private static final int REWARD_ITEM_ID_3 = 6577;
    private static final long REWARD_AMOUNT_3 = 1;
    private static final int REWARD_ITEM_ID_4 = 6578;
    private static final long REWARD_AMOUNT_4 = 1;
    private static final int REWARD_ITEM_ID_5 = 10639;
    private static final long REWARD_AMOUNT_5 = 1;
    private static final int REWARD_INTERVAL = 2;

    private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM HH:mm:ss");
    private static boolean isActive = true;

    public static void start()
    {
        if (!scheduler.isShutdown())
        {
            System.out.println("[" + LocalDateTime.now().format(formatter) + "] ✅ Iniciando evento de recompensas...");
            scheduler.scheduleAtFixedRate(TimedItemReward::giveRewards, 0, REWARD_INTERVAL, TimeUnit.MINUTES);
        }
        else
        {
            System.out.println("[" + LocalDateTime.now().format(formatter) + "] ⚠ El programador ya ha sido cerrado. Reinicie el evento.");
        }
    }

    public static void stop()
    {
        scheduler.shutdown();
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] ❌ Evento de recompensa detenido.");
    }

    public static void setActive(boolean active)
    {
        isActive = active;
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] 🔄 Evento de recompensas " + (active ? "activado" : "desactivado") + ".");
    }

    private static synchronized void giveRewards()
    {
        if (!isActive)
        {
            System.out.println("[" + LocalDateTime.now().format(formatter) + "] 🚫 Evento de recompensas está desactivado.");
            return;
        }

        String timestamp = LocalDateTime.now().format(formatter);
        System.out.println("[" + timestamp + "] 🔹 Ejecutando entrega de recompensas...");

        if (World.getInstance().getPlayers().isEmpty())
        {
            System.out.println("[" + timestamp + "] ❌ No hay jugadores conectados.");
            return;
        }

        for (Player player : World.getInstance().getPlayers())
        {
            if (player != null && player.isOnline() && !player.isInOfflineMode())
            {
                System.out.println("[" + timestamp + "] ➡ Recompensando a: " + player.getName());

                if (player.getInventory().validateCapacity(5) && player.getInventory().validateWeight(REWARD_AMOUNT_1 + REWARD_AMOUNT_2 + REWARD_AMOUNT_3 + REWARD_AMOUNT_4 + REWARD_AMOUNT_5))
                {
                    player.getInventory().addItem("TimedItemReward", REWARD_ITEM_ID_1, REWARD_AMOUNT_1, player, null);
                    player.getInventory().addItem("TimedItemReward", REWARD_ITEM_ID_2, REWARD_AMOUNT_2, player, null);
                    player.getInventory().addItem("TimedItemReward", REWARD_ITEM_ID_3, REWARD_AMOUNT_3, player, null);
                    player.getInventory().addItem("TimedItemReward", REWARD_ITEM_ID_4, REWARD_AMOUNT_4, player, null);
                    player.getInventory().addItem("TimedItemReward", REWARD_ITEM_ID_5, REWARD_AMOUNT_5, player, null);
                    player.sendItemList(true);

                    int[] itemIds = {REWARD_ITEM_ID_1, REWARD_ITEM_ID_2, REWARD_ITEM_ID_3, REWARD_ITEM_ID_4, REWARD_ITEM_ID_5};
                    long[] itemAmounts = {REWARD_AMOUNT_1, REWARD_AMOUNT_2, REWARD_AMOUNT_3, REWARD_AMOUNT_4, REWARD_AMOUNT_5};
                   
                    for (int i = 0; i < itemIds.length; i++)
                    {
                        SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1);
                        sm.addItemName(itemIds[i]);
                        sm.addLong(itemAmounts[i]);
                        player.sendPacket(sm);
                    }
                }
                else
                {
                    System.out.println("[" + timestamp + "] ⚠ " + player.getName() + " has no inventory space.");
                    player.sendMessage("You don't have inventory space to receive the reward.");
                }
            }
        }

        Broadcast.toAllOnlinePlayers("¡All players have received a reward for being online!");
    }
}
================================================================================
package custom.events;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Logger {

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM HH:mm:ss");

    public static void log(String message) {
 
        String currentDateTime = LocalDateTime.now().format(formatter);

        System.out.println("[" + currentDateTime + "] " + message);
    }
}
=====================================================================
package custom.events;

public class CustomEventsLoader {
    public static void main(String[] args) {

        Logger.log("🔹 Cargando eventos personalizados...");

        TimedItemRewardLoader.start();
    }
}

package custom.events;

public class TimedItemRewardLoader {
    public static void start() {
        try {

            Logger.log("✅ TimedItemReward iniciado correctamente.");

        } catch (Exception e) {

            Logger.log("❌ Error al iniciar TimedItemReward: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

Boss Event
Code: [Select]
package custom.events;

import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.network.serverpackets.NpcSay;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ThreadLocalRandom;

public class BossEvent
{
    private static final int BOSS_NPC_ID = 8001; // ID del NPC del jefe
    private static final int[][] SPAWN_POINTS = {
        {-82221, 150970, -3120},
        {116565, 76084, -2728},
        {44013, -50341, -792}
    };
    private static final String[] CITY_NAMES = {
        "Gludin",
        "Hunter Village",
        "Rune"
    };
    private static final int BOSS_RESPAWN_INTERVAL = 120; // Intervalo de reaparición en minutos (ajustar para pruebas)

    private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM HH:mm:ss");

    private static final AtomicBoolean isActive = new AtomicBoolean(false); // Variable para activar/desactivar el evento
    private static Spawn bossSpawn;

    public BossEvent()
    {
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] ✅ BossEvent cargado correctamente.");
    }

    public static void start()
    {
        if (isActive.get()) {
            System.out.println("[" + LocalDateTime.now().format(formatter) + "] ⚠ El evento de aparición de jefe ya está activo.");
            return;
        }

        isActive.set(true);
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] ✅ Iniciando evento de aparición de jefe...");
        scheduler.scheduleAtFixedRate(BossEvent::spawnBoss, 0, BOSS_RESPAWN_INTERVAL, TimeUnit.MINUTES);
    }

    public static void stop()
    {
        if (!isActive.get()) {
            System.out.println("[" + LocalDateTime.now().format(formatter) + "] ⚠ El evento de aparición de jefe ya está detenido.");
            return;
        }

        isActive.set(false);
        scheduler.shutdownNow();
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] ❌ Evento de aparición de jefe detenido.");
    }

    public static void setActive(boolean active)
    {
        isActive.set(active);
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] 🔄 Evento de aparición de jefe " + (active ? "activado" : "desactivado") + ".");
    }

    private static void spawnBoss()
    {
        if (!isActive.get())
        {
            System.out.println("[" + LocalDateTime.now().format(formatter) + "] 🚫 Evento de aparición de jefe está desactivado.");
            return;
        }

        String timestamp = LocalDateTime.now().format(formatter);
        System.out.println("[" + timestamp + "] 🔹 Ejecutando aparición de jefe...");

        try
        {
            if (bossSpawn != null && bossSpawn.getLastSpawn() != null && !bossSpawn.getLastSpawn().isDead())
            {
                System.out.println("[" + timestamp + "] ⚠ El jefe ya está vivo.");
                return;
            }

            int spawnIndex = ThreadLocalRandom.current().nextInt(SPAWN_POINTS.length);
            int[] spawnPoint = SPAWN_POINTS[spawnIndex];
            String cityName = CITY_NAMES[spawnIndex];

            int spawnX = spawnPoint[0];
            int spawnY = spawnPoint[1];
            int spawnZ = spawnPoint[2];

            bossSpawn = new Spawn(BOSS_NPC_ID);
            bossSpawn.setXYZ(spawnX, spawnY, spawnZ);
            bossSpawn.setAmount(1);
            bossSpawn.setHeading(0);
            bossSpawn.setRespawnDelay(0);
            bossSpawn.init();

            Npc boss = bossSpawn.getLastSpawn();
            if (boss != null)
            {
                String bossName = boss.getName();
                String message = "¡El jefe " + bossName + " ha aparecido en " + cityName + "! Dirígete al punto de aparición para enfrentarlo.";
                System.out.println("[" + timestamp + "] ➡ Jefe " + bossName + " ha aparecido en " + cityName + ".");
               

                Broadcast.toAllOnlinePlayers(message);
            }
            else
            {
                System.out.println("[" + timestamp + "] ❌ No se pudo obtener el jefe después de la aparición.");
            }
        }
        catch (Exception e)
        {
            System.out.println("[" + timestamp + "] ❌ Error al intentar hacer aparecer al jefe: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
=============================================================================
package custom.events;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class BossEventLoader
{
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM HH:mm:ss");

    // Método para cargar el evento
    public static void load()
    {
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] BossEventLoader cargado correctamente.");
        BossEvent.start();  // Inicia el evento
    }

    // Método para detener y limpiar el evento
    public static void stop()
    {
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] Deteniendo evento de aparición de jefe...");
        BossEvent.stop();  // Detiene el evento correctamente
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] Evento de aparición de jefe cancelado.");
    }
}

=================================================================================
package custom.events;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class BossEventLoader
{
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM HH:mm:ss");


    public static void load()
    {
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] BossEventLoader cargado correctamente.");
        BossEvent.start();  // Inicia el evento
    }


    public static void stop()
    {
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] Deteniendo evento de aparición de jefe...");
        BossEvent.stop();  // Detiene el evento correctamente
        System.out.println("[" + LocalDateTime.now().format(formatter) + "] Evento de aparición de jefe cancelado.");
    }
}



Online Naker

  • Count
  • *****
    • Posts: 451
  • Coding Dreams
I guess for icons on the strings and also are in spanish that this code is chatGPT or DeepSeek xD


Offline mafias

  • Vassal
  • *
    • Posts: 7
Do the servers in South America speak Spanish? Or did you not know that?


I guess for icons on the strings and also are in spanish that this code is chatGPT or DeepSeek xD


Online BazookaRpm

  • Count
  • *****
    • Posts: 449
  • Lineage II - lover - Heirophant
I'll try to adapt it to Interlude.

Now it works and is bug-free, but if not, it needs fixing.
Atte BazooKa.RPM

Lineage II Lovers