Jump to content
  • 0

[Help] How to create an instance :S


Question

Posted

hi people i need some help to create an instance.

i try to made it taking the script of kamaloca and editing it but a lot of errors appear in the console :S

i need a instance like this

you talk with an npc and you enter to the instance with the party of 9 members.

every 5 seconds 20 moobs appear around the map of the instance and the moobs will attack you and your party for 1 hour.

is a instance to lvl up faster than go chimeras or go monastery.

i need some help with the codes, thanx :D

3 answers to this question

Recommended Posts

  • 0
Posted

[...]

i need some help with the codes, thanx :D

Can we see what you have already made? We'll tell you whats wrong with your code. If you want whole job to be done for you, the marketplace is above.

  • 0
Posted

This is the code

i edit it from kamaloca.java

 

package instances.Mazmorra;

 

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Calendar;

import java.util.List;

import java.util.Map;

 

import com.l2jserver.gameserver.ai.CtrlIntention;

import com.l2jserver.gameserver.datatables.SkillTable;

import com.l2jserver.gameserver.instancemanager.InstanceManager;

import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;

import com.l2jserver.gameserver.model.L2Effect;

import com.l2jserver.gameserver.model.L2Object;

import com.l2jserver.gameserver.model.L2Party;

import com.l2jserver.gameserver.model.L2Skill;

import com.l2jserver.gameserver.model.L2Spawn;

import com.l2jserver.gameserver.model.L2World;

import com.l2jserver.gameserver.model.actor.L2Character;

import com.l2jserver.gameserver.model.actor.L2Npc;

import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;

import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;

import com.l2jserver.gameserver.model.entity.Instance;

import com.l2jserver.gameserver.model.quest.Quest;

import com.l2jserver.gameserver.model.quest.QuestState;

import com.l2jserver.gameserver.network.SystemMessageId;

import com.l2jserver.gameserver.network.serverpackets.SystemMessage;

import com.l2jserver.util.Rnd;

 

public class Kamaloka extends Quest

{

    private static String qn = "Mazmorra";

 

    /*

    * Reset time for all kamaloka

    * Default: 6:30AM on server time

    */

    private static final int RESET_HOUR = 6;

    private static final int RESET_MIN = 30;

 

    /*

    * Time after which instance without players will be destroyed

    * Default: 5 minutes

    */

    private static final int EMPTY_DESTROY_TIME = 5;

 

    /*

    * Time to destroy instance (and eject players away) after boss defeat

    * Default: 5 minutes

    */

    private static final int EXIT_TIME = 5;

 

    /*

    * Maximum level difference between players level and kamaloka level

    * Default: 5

    */

    private static final int MAX_LEVEL_DIFFERENCE = 5;

 

    /*

    * If true shaman in the first room will have same npcId as other mobs, making radar useless

    * Default: true (but not retail like)

    */

    private static final boolean STEALTH_SHAMAN = true;

 

    /*

    * Hardcoded instance ids for kamaloka

    */

    private static final int[] INSTANCE_IDS =

    { 120 };

 

    /*

    * Level of the kamaloka

    */

    private static final int[] LEVEL =

    { 84 };

 

    /*

    * Duration of the instance, minutes

    */

    private static final int[] DURATION =

    { 60 };

 

    /*

    * Maximum party size for the instance

    */

    private static final int[] MAX_PARTY_SIZE =

    {  9 };

 

    /*

    * List of buffs NOT removed on enter from player and pet

    * On retail only newbie guide buffs not removed

    * CAUTION: array must be sorted in ascension order !

    */

    private static final int[] BUFFS_WHITELIST =

    {  };

 

    /*

    * Teleport points into instances

    *

    * x, y, z

    */

    private static final int[][] TELEPORTS =

    {

        { -88429, -220629,  -7903 },

    };

 

    /*

    * Respawn delay for the mobs in the first room, seconds

    * Default: 25

    */

    private static final int FIRST_ROOM_RESPAWN_DELAY = 5;

 

    /*

    * First room information, null if room not spawned

    * Skill is casted on the boss when shaman is defeated and mobs respawn stopped

    * Default: 5699 (decrease pdef)

    *

    * shaman npcId, minions npcId, skillId, skillLvl

    */

    private static final int[][] FIRST_ROOM =

    {

        null, null,

        { 22485, 22486, 5699, 1 },

    };

 

    /*

    * First room spawns, null if room not spawned

    *

    * x, y, z

    */

    private static final int[][][] FIRST_ROOM_SPAWNS =

    {

        null, null,

        {

            { -12381, -174973, -10955 }, { -12413, -174905, -10955 },

            { -12377, -174838, -10953 }, { -12316, -174903, -10953 },

            { -12326, -174786, -10953 }, { -12330, -175024, -10953 },

            { -12211, -174900, -10955 }, { -12238, -174849, -10953 },

            { -12233, -174954, -10953 }

        },

    };

 

    /*

    * Second room information, null if room not spawned

    * Skill is casted on the boss when all mobs are defeated

    * Default: 5700 (decrease mdef)

    *

    * npcId, skillId, skillLvl

    */

    private static final int[][] SECOND_ROOM =

    {

        null, null,

        { 22487, 5700, 1 },

    };

 

    /*

    * Escape telepoters spawns, null if not spawned

    *

    * x, y, z

    */

    private static final int[][] TELEPORTERS =

    {

        null, null,

        { -10865, -174905, -10944 },

    };

 

    /*

    * Escape teleporter npcId

    */

    private static final int TELEPORTER = 32496;

 

    /*

    * Kamaloka captains (start npc's) npcIds.

    */

    private static final int[] CAPTAINS =

    { 888555 };

 

    private class KamaWorld extends InstanceWorld

    {

        public int index;                // 0-17 index of the kama type in arrays

        public int shaman = 0;            // objectId of the shaman

        public List<L2Spawn> firstRoom;    // list of the spawns in the first room (excluding shaman)

 

        public KamaWorld()

        {

            InstanceManager.getInstance().super();

        }

    }

 

    /**

    * Check if party with player as leader allowed to enter

    *

    * @param player party leader

    * @param index (0-17) index of the kamaloka in arrays

    *

    * @return true if party allowed to enter

    */

    private static final boolean checkConditions(L2PcInstance player, int index)

    {

        final L2Party party = player.getParty();

        // player must be in party

        if (party == null)

        {

            player.sendPacket(new SystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));

            return false;

        }

        // ...and be party leader

        if (party.getLeader() != player)

        {

            player.sendPacket(new SystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));

            return false;

        }

        // party must not exceed max size for selected instance

        if (party.getMemberCount() > MAX_PARTY_SIZE[index])

        {

            player.sendPacket(new SystemMessage(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER));

            return false;

        }

 

        // get level of the instance

        final int level = LEVEL[index];

        // and client name

        final String instanceName = InstanceManager.getInstance().getInstanceIdName(INSTANCE_IDS[index]);

 

        Map<Integer, Long> instanceTimes;

        // for each party member

        for (L2PcInstance partyMember : party.getPartyMembers())

        {

            // player level must be in range

            if (Math.abs(partyMember.getLevel() - level) > MAX_LEVEL_DIFFERENCE)

            {

                SystemMessage sm = new SystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);

                sm.addPcName(partyMember);

                player.sendPacket(sm);

                return false;

            }

            // player must be near party leader

            if (!partyMember.isInsideRadius(player, 1000, true, true))

            {

                SystemMessage sm = new SystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);

                sm.addPcName(partyMember);

                player.sendPacket(sm);

                return false;

            }

            // get instances reenter times for player

            instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(partyMember.getObjectId());

            if (instanceTimes != null)

            {

                for (int id : instanceTimes.keySet())

                {

                    // find instance with same name (kamaloka or labyrinth)

                    if (!instanceName.equals(InstanceManager.getInstance().getInstanceIdName(id)))

                        continue;

                    // if found instance still can't be reentered - exit

                    if (System.currentTimeMillis() < instanceTimes.get(id))

                    {

                        SystemMessage sm = new SystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);

                        sm.addPcName(partyMember);

                        player.sendPacket(sm);

                        return false;

                    }

                }

            }

        }

        return true;

    }

 

    /**

    * Removing all buffs from player and pet except BUFFS_WHITELIST

    *

    * @param ch player

    */

    private static final void removeBuffs(L2Character ch)

    {

        for (L2Effect e : ch.getAllEffects())

        {

            if (e == null)

                continue;

            L2Skill skill = e.getSkill();

            if (skill.isDebuff() || skill.isStayAfterDeath())

                continue;

            if (Arrays.binarySearch(BUFFS_WHITELIST, skill.getId()) >= 0)

                continue;

            e.exit();

        }

        if (ch.getPet() != null)

        {

            for (L2Effect e : ch.getPet().getAllEffects())

            {

                if (e == null)

                    continue;

                L2Skill skill = e.getSkill();

                if (skill.isDebuff() || skill.isStayAfterDeath())

                    continue;

                if (Arrays.binarySearch(BUFFS_WHITELIST, skill.getId()) >= 0)

                    continue;

                e.exit();

            }

        }

    }

 

    /**

    * Teleport player and pet to/from instance

    *

    * @param player

    * @param coords x,y,z

    * @param instanceId

    */

    private static final void teleportPlayer(L2PcInstance player, int[] coords, int instanceId)

    {

        player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);

        player.setInstanceId(instanceId);

        player.teleToLocation(coords[0], coords[1], coords[2], true);

    }

 

    /**

    * Handling enter of the players into kamaloka

    *

    * @param player party leader

    * @param index (0-17) kamaloka index in arrays

    */

    private final synchronized void enterInstance(L2PcInstance player, int index)

    {

        int templateId;

        try

        {

            templateId = INSTANCE_IDS[index];

        }

        catch (ArrayIndexOutOfBoundsException e)

        {

            return;

        }

       

        // check for existing instances for this player

        InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);

        // player already in the instance

        if (world != null)

        {

            // but not in kamaloka

            if (!(world instanceof KamaWorld)

                    || world.templateId != templateId)

            {

                player.sendPacket(new SystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));

                return;

            }

            // check for level difference again on reenter

            if (Math.abs(player.getLevel() - LEVEL[((KamaWorld)world).index]) > MAX_LEVEL_DIFFERENCE)

            {

                SystemMessage sm = new SystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);

                sm.addPcName(player);

                player.sendPacket(sm);

                return;

            }

            // check what instance still exist

            Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);

            if (inst != null)

            {

                removeBuffs(player);

                teleportPlayer(player, TELEPORTS[index], world.instanceId);

            }

            return;

        }

        // Creating new kamaloka instance

        else

        {

            if (!checkConditions(player, index))

                return;

 

            // Creating dynamic instance without template

            final int instanceId = InstanceManager.getInstance().createDynamicInstance(null);

            final Instance inst = InstanceManager.getInstance().getInstance(instanceId);

            // set name for the kamaloka

            inst.setName(InstanceManager.getInstance().getInstanceIdName(templateId));

            // set return location

            final int[] returnLoc = { player.getX(), player.getY(), player.getZ() };

            inst.setSpawnLoc(returnLoc);

            // disable summon friend into instance

            inst.setAllowSummon(false);

            // set duration and empty destroy time

            inst.setDuration(DURATION[index] * 60000);

            inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000);

 

            // Creating new instanceWorld, using our instanceId and templateId

            world = new KamaWorld();

            world.instanceId = instanceId;

            world.templateId = templateId;

            // set index for easy access to the arrays

            ((KamaWorld)world).index = index;

            InstanceManager.getInstance().addWorld(world);

            world.status = 0;

            // spawn npcs

            spawnKama((KamaWorld)world);

 

            // and finally teleport party into instance

            final L2Party party = player.getParty();

            for (L2PcInstance partyMember : party.getPartyMembers())

            {

                if (partyMember.getQuestState(qn) == null)

                    newQuestState(partyMember);

                world.allowed.add(partyMember.getObjectId());

 

                removeBuffs(partyMember);

                teleportPlayer(partyMember, TELEPORTS[index], instanceId);

            }

            return;

        }

    }

 

    /**

    * Called on instance finish and handles reenter time for instance

    * @param world instanceWorld

    */

    private static final void finishInstance(InstanceWorld world)

    {

        if (world instanceof KamaWorld)

        {

            Calendar reenter = Calendar.getInstance();

            reenter.set(Calendar.MINUTE, RESET_MIN);

            // if time is >= RESET_HOUR - roll to the next day

            if (reenter.get(Calendar.HOUR_OF_DAY) >= RESET_HOUR)

                reenter.add(Calendar.DATE, 1);

            reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);

 

            SystemMessage sm = new SystemMessage(SystemMessageId.INSTANT_ZONE_RESTRICTED);

            sm.addString(InstanceManager.getInstance().getInstanceIdName(world.templateId));

 

            // set instance reenter time for all allowed players

            for (int objectId : world.allowed)

            {

                L2Object obj = L2World.getInstance().findObject(objectId);

                if (obj instanceof L2PcInstance && ((L2PcInstance)obj).isOnline() > 0)

                {

                    InstanceManager.getInstance().setInstanceTime(objectId, world.templateId, reenter.getTimeInMillis());

                    ((L2PcInstance)obj).sendPacket(sm);

                }

            }

 

            // destroy instance after EXIT_TIME

            Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);

            inst.setDuration(EXIT_TIME * 60000);

            inst.setEmptyDestroyTime(0);

        }

    }

 

    /**

    * Spawn all NPCs in kamaloka

    * @param world instanceWorld

    */

    @SuppressWarnings("all")

    private final void spawnKama(KamaWorld world)

    {

        int[] npcs;

        int[][] spawns;

        L2Npc npc;

        final int index = world.index;

 

        // first room

        npcs = FIRST_ROOM[index];

        spawns = FIRST_ROOM_SPAWNS[index];

        if (npcs != null)

        {

            world.firstRoom = new ArrayList<L2Spawn>(spawns.length - 1);

            int shaman = Rnd.get(spawns.length); // random position for shaman

 

            for (int i = 0; i < spawns.length; i++)

            {

                if (i == shaman)

                {

                    // stealth shaman use same npcId as other mobs

                    npc = addSpawn(STEALTH_SHAMAN ? npcs[1] : npcs[0], spawns[0], spawns[1], spawns[2], 0, false, 0, false, world.instanceId);

                    world.shaman = npc.getObjectId();

                }

                else

                {

                    npc = addSpawn(npcs[1], spawns[0], spawns[1], spawns[2], 0, false, 0, false, world.instanceId);

                    L2Spawn spawn = npc.getSpawn();

                    spawn.setRespawnDelay(FIRST_ROOM_RESPAWN_DELAY);

                    spawn.setAmount(1);

                    spawn.startRespawn();

                    world.firstRoom.add(spawn); //store mobs spawns

                }

                npc.setIsNoRndWalk(true);

            }

        }

 

        // escape teleporter

        if (TELEPORTERS[index] != null)

            addSpawn(TELEPORTER, TELEPORTERS[index][0], TELEPORTERS[index][1], TELEPORTERS[index][2], 0, false, 0, false, world.instanceId);

 

    }

 

    /**

    * Handles only player's enter, single parameter - integer kamaloka index

    */

    @Override

    public final String onAdvEvent (String event, L2Npc npc, L2PcInstance player)

    {

        if (npc == null)

            return "";

 

        try

        {

            enterInstance(player, Integer.parseInt(event));

        }

        catch (Exception e)

        {

        }

        return "";

    }

 

    /**

    * Talk with captains and using of the escape teleporter

    */

    @Override

    public final String onTalk(L2Npc npc, L2PcInstance player)

    {

        QuestState st = player.getQuestState(qn);

        if (st == null)

            newQuestState(player);

        final int npcId = npc.getNpcId();

 

        if (npcId == TELEPORTER)

        {

            final L2Party party = player.getParty();

            // only party leader can talk with escape teleporter

            if (party != null && party.isLeader(player))

            {

                final InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());

                if (world instanceof KamaWorld)

                {

                    // party members must be in the instance

                    if (world.allowed.contains(player.getObjectId()))

                    {

                        Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);

 

                        // teleports entire party away

                        for (L2PcInstance partyMember : party.getPartyMembers())

                            if (partyMember != null && partyMember.getInstanceId() == world.instanceId)

                                teleportPlayer(partyMember, inst.getSpawnLoc(), 0);

                    }

                }

            }

        }

        else

            return npcId + ".htm";

 

        return "";

    }

 

    /**

    * Only escape teleporters first talk handled

    */

    @Override

    public final String onFirstTalk (L2Npc npc, L2PcInstance player)

    {

        if (npc.getNpcId() == TELEPORTER)

        {

            if (player.isInParty() && player.getParty().isLeader(player))

                return "32496.htm";

            else

                return "32496-no.htm";

        }

 

        return "";

    }

 

    @Override

    public final String onKill(L2Npc npc, L2PcInstance player, boolean isPet)

    {

        final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());

        if (tmpWorld instanceof KamaWorld)

        {

            final KamaWorld world = (KamaWorld)tmpWorld;

            final int objectId = npc.getObjectId();

 

            // first room was spawned ?

            if (world.firstRoom != null)

            {

                // is shaman killed ?

                if (world.shaman != 0 && world.shaman == objectId)

                {

                    world.shaman = 0;

                    // stop respawn of the minions

                    for (L2Spawn spawn : world.firstRoom)

                    {

                        if (spawn != null)

                            spawn.stopRespawn();

                    }

                    world.firstRoom.clear();

                    world.firstRoom = null;

 

                    if (world.boss != null)

                    {

                        final int skillId = FIRST_ROOM[world.index][2];

                        final int skillLvl = FIRST_ROOM[world.index][3];

                        if (skillId != 0 && skillLvl != 0)

                        {

                            final L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);

                            if (skill != null)

                                skill.getEffects(world.boss, world.boss);

                        }

                    }

 

                    return super.onKill(npc, player, isPet);

                }

            }

 

    public Kamaloka(int questId, String name, String descr)

    {

        super(questId, name, descr);

        addFirstTalkId(TELEPORTER);

        addTalkId(TELEPORTER);

        for (int cap : CAPTAINS)

        {

            addStartNpc(cap);

            addTalkId(cap);

        }

        for (int[] mob : FIRST_ROOM) //shaman

            if (mob != null)

                if (STEALTH_SHAMAN)

                    addKillId(mob[1]);

                else

                    addKillId(mob[0]);

        for (int[] mob : SECOND_ROOM)

            if (mob != null)

                addKillId(mob[0]);

        for (int[] mob : MINIBOSS)

            if (mob != null)

                addKillId(mob[0]);

        for (int[] mob : BOSS)

            addKillId(mob[0]);

    }

 

    public static void main(String[] args)

    {

        new Mazmorra(-1, qn, "instances");

    }   

}

 

i want only a room (first room) and in this room spawn 20 moobs every 5 seconds all around the center of the spawn locations of the players.

i dont want a boss, only moobs.

and, thanx :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock