Script aCis 382 Spawn/Despawn Monster when Boss is Alive

Статус
В этой теме нельзя размещать новые ответы.

AntiVirus

Путник
Пользователь
Сообщения
14
Розыгрыши
0
Решения
1
Репутация
0
Реакции
0
Баллы
83
Хроники
  1. Interlude
Исходники
Присутствуют
Сборка
l2replica
Hello everyone guys, i am newbie in java at all... :D i am try to write a script for my server, i want 5 monstersIDs to get control from boss. if the boss is alive then all monsters can get spawn and respawn normally but when raid boss is dead then monsters will stop get respawn until raidboss get back alive again. i am try to make this code mostly from chatgpt .

i know what i have wrapper to return null but its because i dont know how i need to write it correct in my project aCis
382.
Java:
package net.sf.l2j.gameserver.scripting.scripts.custom;

import java.util.ArrayList;
import java.util.List;

import net.sf.l2j.gameserver.model.World;
import net.sf.l2j.gameserver.model.actor.Npc;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.scripting.Quest;

public class FafurionGhostEvent extends Quest
{
    private static final int BOSS_ID = 210;
    private static final int[] GHOST_IDS = {207, 208, 209, 211, 212};

    // Ghost spawn coordinates: x, y, z, heading
    private static final int[][] GHOST_LOCS = {
            {212000, 120000, -3700, 0},
            {213000, 119500, -3650, 0},
            {211500, 118800, -3720, 0},
            {212500, 119000, -3680, 0},
            {213200, 118500, -3660, 0}
    };

    private final List<Npc> spawnedGhosts = new ArrayList<>();

    public FafurionGhostEvent()
    {
        super(-1, "custom");

        addSpawnId(BOSS_ID);
        addKillId(BOSS_ID);
    }
    private Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean unused1, int unused2)
    {
        addSpawn(npcId, x, y, z, heading);


        return null;
    }

    private void addSpawn(int npcId, int x, int y, int z, int heading) {
    }

    @Override
    public String onSpawn(Npc npc)
    {
        if (npc.getNpcId() == BOSS_ID)
        {
            for (int i = 0; i < GHOST_IDS.length; i++)
            {
                int ghostId = GHOST_IDS[i];
                int[] loc = GHOST_LOCS[i % GHOST_LOCS.length];

                Npc ghost = addSpawn(ghostId, loc[0], loc[1], loc[2], loc[3], false, 0);
                if (ghost != null)
                {
                    spawnedGhosts.add(ghost);
                }
            }
            System.out.println("FafurionGhostEvent: Spawned ghosts because boss spawned.");
        }
        return null;
    }



    
    public String onKill(Npc npc, Player killer, boolean isPet)
    {
        if (npc.getNpcId() == BOSS_ID)
        {
            for (Object obj : World.getInstance().getObjects())
            {
                if (obj instanceof Npc)
                {
                    Npc ghost = (Npc) obj;
                    int id = ghost.getNpcId();
                    if (id == 207 || id == 208 || id == 209 || id == 211 || id == 212)
                        ghost.deleteMe();
                }
            }
            System.out.println("FafurionGhostEvent: Despawned ghosts because boss died.");
        }
        return null;
    }



    public static void main(String[] args)
    {
        new FafurionGhostEvent();
    }
}
image.webp

thanks in advance guys peace <3 !!!
 
Решение
Java:
package net.sf.l2j.gameserver.scripting.scripts.custom;

import java.util.ArrayList;
import java.util.List;

import net.sf.l2j.gameserver.model.World;
import net.sf.l2j.gameserver.model.actor.Creature;
import net.sf.l2j.gameserver.model.actor.Npc;
import net.sf.l2j.gameserver.scripting.Quest;

public class FafurionGhostEvent extends Quest
{
    private static final int BOSS_ID = 210;
    private static final int[] GHOST_IDS = {207, 208, 209, 211, 212};

    // Ghost spawn coordinates: x, y, z, heading
    private static final int[][] GHOST_LOCS = {
            {-83096, -42536, -10760, 0},
            {-83196, -42436, -10760, 0},
            {-83296, -42586, -10760, 0},
            {-83146, -42456, -10760, 0},
            {-83196...
Если Вы самостоятельно решили проблему, то опишите суть ее решения. У других людей может быть такая же проблема
solved huge thanks to onepav
 
Java:
package net.sf.l2j.gameserver.scripting.scripts.custom;

import java.util.ArrayList;
import java.util.List;

import net.sf.l2j.gameserver.model.World;
import net.sf.l2j.gameserver.model.actor.Creature;
import net.sf.l2j.gameserver.model.actor.Npc;
import net.sf.l2j.gameserver.scripting.Quest;

public class FafurionGhostEvent extends Quest
{
    private static final int BOSS_ID = 210;
    private static final int[] GHOST_IDS = {207, 208, 209, 211, 212};

    // Ghost spawn coordinates: x, y, z, heading
    private static final int[][] GHOST_LOCS = {
            {-83096, -42536, -10760, 0},
            {-83196, -42436, -10760, 0},
            {-83296, -42586, -10760, 0},
            {-83146, -42456, -10760, 0},
            {-83196, -42236, -10760, 0}
    };

    private final List<Npc> _spawnedGhosts = new ArrayList<>();

    public FafurionGhostEvent()
    {
        super(-1, "custom");

        addSpawnId(BOSS_ID);
        addKillId(BOSS_ID);


        for (int i = 0; i < GHOST_IDS.length; i++)
        {
            int ghostId = GHOST_IDS[i];
            int[] loc = GHOST_LOCS[i % GHOST_LOCS.length];

            Npc ghost = this.addSpawn(ghostId, loc[0], loc[1], loc[2], loc[3], false, 0, false);
            _spawnedGhosts.add(ghost);
            ghost.getSpawn().setRespawnDelay(30);
        }
    }

    @Override
    public String onSpawn(Npc npc)
    {
        if (npc.getNpcId() == BOSS_ID)
        {
            spawnGhosts();
            World.announceToOnlinePlayers("FafurionGhostEvent: Beware! The leader of the ghost's has appeared in Fafurion Island!" , false);
            System.out.println("FafurionGhostEvent: Spawned ghosts because boss spawned.");
        }
        return super.onSpawn(npc);
    }


    @Override
    public String onKill(Npc npc, Creature killer)
    {
        if (npc.getNpcId() == BOSS_ID)
        {
            despawnGhosts();
            World.announceToOnlinePlayers("FafurionGhostEvent: The leader of the ghost's has been defeated! Peace returns in Fafurion Island for now." , false);
            System.out.println("FafurionGhostEvent: Despawned ghosts because boss died.");
        }
        return super.onKill(npc, killer);
    }

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


    private void spawnGhosts()
    {
        for (Npc npc : _spawnedGhosts)
        {
            npc.getSpawn().setRespawnState(true);
            npc.getSpawn().doSpawn(false);
        }
    }

    private void despawnGhosts()
    {
        for (Npc npc : _spawnedGhosts)
        {
            npc.getSpawn().setRespawnState(false);
            npc.deleteMe();
        }
    }
}
if someone want to test it dont forget put in gameserver/data/xmls/scripts.xml
+ <script path="scripts.custom.FafurionGhostEvent"/>
 
Решение
Статус
В этой теме нельзя размещать новые ответы.

Похожие темы

Назад
Сверху