Page 1 of 1

Custom Instance problem

Posted: Fri Jul 04, 2014 1:59 pm
by Gries
I've created recently my first custom instance, there aren't errors in eclipse but it is not loading, could you check into it?

Code: Select all

package instances.Training; import java.util.Calendar; import com.l2jserver.gameserver.instancemanager.InstanceManager;import com.l2jserver.gameserver.model.L2World;import com.l2jserver.gameserver.model.Location;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.instancezone.InstanceWorld;import com.l2jserver.gameserver.model.quest.Quest;import com.l2jserver.gameserver.network.SystemMessageId;import com.l2jserver.gameserver.network.serverpackets.SystemMessage; public class TrainingGround extends Quest{    private static final int INSTANCE_ID = 999;    // NPC    private static final int ENTER_NPC = 150;    private static final int EXIT_NPC = 151;    private static final int BOSS_NPC = 152;    // Item    private static final int PASS = 3470; // item entrance ID        // Initialization at 6:30 am everyday    private static final int RESET_HOUR = 6;    private static final int RESET_MIN = 30;        private static final Location ENTER_TELEPORT = new Location(-76435, -185543, -11008, 0);    private static final Location EXIT_TELEPORT = new Location(42781, -48086, 796, 0);        protected class TrainingWorld extends InstanceWorld    {        public L2Npc enter_npc;        public L2Npc exit_npc;        public L2MonsterInstance boss_npc;    }        public TrainingGround(int questId, String name, String descr)    {        super(questId, name, descr);        addFirstTalkId(ENTER_NPC, EXIT_NPC);        addSpawnId(BOSS_NPC);        addKillId(BOSS_NPC);        addAttackId(BOSS_NPC);    }        @Override    public String onTalk(L2Npc npc, L2PcInstance player)    {        String htmltext = null;        if (npc.getId() == ENTER_NPC)        {            htmltext = checkConditions(player);                        if (htmltext == null)            {                enterInstance(player, "TrainingGround.xml");            }        }        else if (npc.getId() == EXIT_NPC)        {            InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());            if ((world != null) && (world.getInstanceId() == INSTANCE_ID))            {                world.removeAllowed(player.getObjectId());                teleportPlayer(player, EXIT_TELEPORT, 0);            }        }        return htmltext;    }        /**     * @param player     * @return     */    private String checkConditions(L2PcInstance player)    {        if (player.getInventory().getInventoryItemCount(PASS, -1, false) <= 1)        {            return "no-item.htm";        }        return null;    }        @Override    public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)    {        int instanceId = npc.getInstanceId();        if (instanceId > 0)        {            Instance inst = InstanceManager.getInstance().getInstance(instanceId);            InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());            inst.setSpawnLoc(EXIT_TELEPORT);                        // Terminate instance in 5 min            if ((inst.getInstanceEndTime() - System.currentTimeMillis()) > 300000)            {                inst.setDuration(300000);            }                        inst.setEmptyDestroyTime(0);                        if ((world != null) && (world.getInstanceId() == INSTANCE_ID))            {                setReenterTime(world);            }            addSpawn(EXIT_NPC, -22144, 278744, -8239, 0, false, 0, false, instanceId);                        return super.onKill(npc, killer, isSummon);        }        return null;    }        private boolean checkTeleport(L2PcInstance player)    {        Long reentertime = InstanceManager.getInstance().getInstanceTime(player.getObjectId(), INSTANCE_ID);        if (System.currentTimeMillis() < reentertime)        {            SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);            player.broadcastPacket(sm);            return false;        }        return true;    }        private int enterInstance(L2PcInstance player, String template)    {        int instanceId = 0;        // check for existing instances for this player        InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);        // existing instance        if (world != null)        {            if ((world.getInstanceId() != INSTANCE_ID))            {                player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);                return 0;            }            teleportPlayer(player, ENTER_TELEPORT, world.getInstanceId());            return world.getInstanceId();        }                if (!checkTeleport(player))        {            return 0;        }        instanceId = InstanceManager.getInstance().createDynamicInstance(template);        world = new InstanceWorld();        world.setInstanceId(instanceId);        world.setTemplateId(INSTANCE_ID);        world.setStatus(0);        InstanceManager.getInstance().addWorld(world);        _log.info("Tower of Infinitum - Demon Prince floor started " + template + " Instance: " + instanceId + " created by player: " + player.getName());                for (L2PcInstance partyMember : player.getParty().getMembers())        {            teleportPlayer(partyMember, ENTER_TELEPORT, instanceId);            player.destroyItemByItemId("Quest", PASS, 1, null, true);            world.addAllowed(player.getObjectId());        }        return instanceId;    }        public void setReenterTime(InstanceWorld world)    {        if (world.getInstanceId() == INSTANCE_ID)        {            // Reenter time should be cleared every Wed and Sat at 6:30 AM, so we set next suitable            Calendar reenter;            Calendar now = Calendar.getInstance();            Calendar reenterPointWed = (Calendar) now.clone();            reenterPointWed.set(Calendar.AM_PM, Calendar.AM);            reenterPointWed.set(Calendar.MINUTE, RESET_MIN);            reenterPointWed.set(Calendar.HOUR_OF_DAY, RESET_HOUR);            reenterPointWed.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);            Calendar reenterPointSat = (Calendar) reenterPointWed.clone();            reenterPointSat.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);                        if (now.after(reenterPointSat))            {                reenterPointWed.add(Calendar.WEEK_OF_MONTH, 1);                reenter = (Calendar) reenterPointWed.clone();            }            else            {                reenter = (Calendar) reenterPointSat.clone();            }                        SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);            sm.addInstanceName(world.getTemplateId());            // set instance reenter time for all allowed players            for (int objectId : world.getAllowed())            {                L2PcInstance player = L2World.getInstance().getPlayer(objectId);                if ((player != null) && player.isOnline())                {                    InstanceManager.getInstance().setInstanceTime(objectId, world.getTemplateId(), reenter.getTimeInMillis());                    player.sendPacket(sm);                }            }        }    }         
}

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 2:02 pm
by Zealar
Do you register it inside "scripts.cfg" ?

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 2:19 pm
by Gries
Zealar wrote:Do you register it inside "scripts.cfg" ?
Of course :D

That's the error log file:
no main method in instances.Training.TrainingGround

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 2:28 pm
by St3eT
You forgot add that:

Code: Select all

addStartNpc(ENTER_NPC, EXIT_NPC);addTalkId(ENTER_NPC, EXIT_NPC);

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 2:38 pm
by Zealar

Code: Select all

    public static void main(String[] args)    {        new TrainingGround(12345, "Training Ground", "Train your dragon");    }

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 3:53 pm
by Gries
Done that and now script is loading normally, at start NPC was not showing any page but solved with:

Code: Select all

        for (int i = ENTER_NPC; i <= EXIT_NPC; i++)        {            addStartNpc(i);            addTalkId(i);        }
Now page is showing up but when i press enter button i get default noquest text even if i have enough pass.

This is the bypass i am using to try to enter in the htm:

Code: Select all

bypass -h npc_%objectId%_Quest TrainingGround
EDIT: Solved with

Code: Select all

    public static void main(String[] args)    {        new TrainingGround(-1, TrainingGround.class.getSimpleName(), "instances");    }
:D

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 4:00 pm
by Zealar
Provide full patch for instance im to lazy to do missing party needed for testing by hand also is very possible problem to be hidden in them.

Re: Custom Instance problem

Posted: Fri Jul 04, 2014 4:26 pm
by Gries
Zealar wrote:Provide full patch for instance im to lazy to do missing party needed for testing by hand also is very possible problem to be hidden in them.
Solved it, thank you anyway.

Uploaded file for whoever wants to use it. Just need to create HTML to use it with bypass -h npc_%objectId%_Quest TrainingGround to enter and instance XML file.

Re: Custom Instance problem

Posted: Sun Jul 06, 2014 10:32 pm
by Gries
One more little problem:
Image

Do i have to register the instance ID somewhere or it is client-related?

Re: Custom Instance problem

Posted: Sun Jul 06, 2014 10:37 pm
by St3eT
Look here: http://svn.l2jdp.com/branches/unstable/ ... enames.xml
Same ID/name have client.