Jump to content
  • 0

[HELP] Custom Instance


Question

Posted

I'm making a Custom Instance in Java, and i'm testing different possibilities. But I have a little error when in mi Instance I want to open/close door by java script (when you complete a condition for example).

The Instance runs perfectly. When I kill the two MOBs of the first room, spawns the next condition and spawns three aditional MOBs in the other room. The problem is only with doors.

 

 

Here is the full code:

 

package instances.InstanceTest;

import javolution.util.FastList;
import javolution.util.FastMap;


import com.l2jserver.gameserver.ai.CtrlIntention;
import com.l2jserver.gameserver.instancemanager.InstanceManager;
import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
import com.l2jserver.gameserver.model.L2Party;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
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;

public class InstanceTest extends Quest
{

//NPCs
private static int ENTER       = 40000; //Exit Instance Test
private static int EXIT     = 40001; //Exit Instance Test

//Mobs
private static int[] MOBTEST = {40002,40003,40004}; //Test MOB for Instance

//Doors/Walls
private static int DOOR1 = 24230001; //Starting Room
private static int DOOR2 = 24230002; //Exit Room

//Items
private static int REWARD = 57; //Adena

// Instance reenter time
// default: 86400000ms(24h)
private static final int INSTANCEPENALTY = 60000;

public InstanceTest(int questId, String name, String descr)
{

	super(questId, name, descr);

	addStartNpc(ENTER);
	addTalkId(ENTER);
	addFirstTalkId(EXIT);
	addTalkId(EXIT);

	for (int mob : MOBTEST)
		addAttackId(mob);
	for (int mob : MOBTEST)
		addKillId(mob);
}

private static class ITestNpc
{
	public L2Npc npc;
	public boolean isDead = false;
}

private static class ITestRoom
{
	public FastList<ITestNpc> npcList = new FastList<ITestNpc>();
}

private class ITestWorld extends InstanceWorld
{
	public FastMap<String,ITestRoom> rooms = new FastMap<String,ITestRoom>();
	public ITestWorld()
	{
	}
}

private static boolean debug = false;
private static boolean noRndWalk = true;

private static String qn = "InstanceTest";
private static final int INSTANCEID = 1000;

private static class teleCoord {int instanceId; int x; int y; int z;}

private boolean checkConditions(L2PcInstance player)
{
	if (debug)
		return true;
	else
	{
		L2Party party = player.getParty();
		if (party == null)
		{
			player.sendMessage("No estas en Party, por lo tanto no puedes entrar.");
			return false;
		}
		if (party.getLeader() != player)
		{
			player.sendMessage("Solo el lider de Party puede decidir entrar en la Instance.");
			return false;
		}
		if (party.getMemberCount() > 2)
		{
			player.sendMessage("No hay suficientes miembros en la Party para entrar. Lo minimo son dos personas.");
			return false;
		}
		for (L2PcInstance partyMember : party.getPartyMembers())
		{
			if (partyMember.getLevel() < 78)
			{
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
				sm.addPcName(partyMember);
				player.sendPacket(sm);
				return false;
			}
			if (!partyMember.isInsideRadius(player, 1000, true, true))
			{
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
				sm.addPcName(partyMember);
				player.sendPacket(sm);
				return false;
			}
			Long reentertime = InstanceManager.getInstance().getInstanceTime(partyMember.getObjectId(), INSTANCEID);
			if (System.currentTimeMillis() < reentertime)
			{
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
				sm.addPcName(partyMember);
				party.broadcastToPartyMembers(sm);
				return false;
			}
		}

		return true;
	}
}


private void teleportplayer(L2PcInstance player, teleCoord teleto)
{
	player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
	player.setInstanceId(teleto.instanceId);
	player.teleToLocation(teleto.x, teleto.y, teleto.z);
	return;
}

protected int enterInstance(L2PcInstance player, String template, teleCoord teleto)
{
	int instanceId = 0;
	//check for existing instances for this player
	InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
	//existing instance
	if (world != null)
	{
		if (!(world instanceof ITestWorld))
		{
			player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
			return 0;
		}
		teleto.instanceId = world.instanceId;
		teleportplayer(player,teleto);
		return instanceId;
	}
	//New instance
	else
	{
		if (!checkConditions(player))
			return 0;
		L2Party party = player.getParty();
		instanceId = InstanceManager.getInstance().createDynamicInstance(template);
		world = new ITestWorld();
		world.instanceId = instanceId;
		world.templateId = INSTANCEID;
		InstanceManager.getInstance().addWorld(world);
		_log.info("Instance Test: started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
		runStartRoomInstanceTest((ITestWorld)world);
		// teleport players
		teleto.instanceId = instanceId;
		if (debug && party == null)
		{
			InstanceManager.getInstance().setInstanceTime(player.getObjectId(), INSTANCEID, ((System.currentTimeMillis() + INSTANCEPENALTY)));
			world.allowed.add(player.getObjectId());
			teleportplayer(player,teleto);
		}
		else
		{
			for (L2PcInstance partyMember : party.getPartyMembers())
			{
				if (partyMember.getQuestState(qn) == null)
					newQuestState(partyMember);
				InstanceManager.getInstance().setInstanceTime(partyMember.getObjectId(), INSTANCEID, ((System.currentTimeMillis() + INSTANCEPENALTY)));
				teleportplayer(partyMember,teleto);
				world.allowed.add(partyMember.getObjectId());

			}
		}

		return instanceId;
	}
}

protected void exitInstance(L2PcInstance player, teleCoord tele)
{
	player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
	player.setInstanceId(0);
	player.teleToLocation(tele.x, tele.y, tele.z);
}


protected void runStartRoomInstanceTest(ITestWorld world)
{

	world.status = 0;
	ITestRoom StartRoomTest = new ITestRoom();
	ITestNpc thisnpc;

	thisnpc = new ITestNpc();
	thisnpc.npc = addSpawn(MOBTEST[0],146817,180335,-6117,0,false,0,false, world.instanceId);
	StartRoomTest.npcList.add(thisnpc);
	if (noRndWalk)
		thisnpc.npc.setIsNoRndWalk(true);

	thisnpc = new ITestNpc();
	thisnpc.npc = addSpawn(MOBTEST[1],146741,180589,-6117,0,false,0,false, world.instanceId);
	StartRoomTest.npcList.add(thisnpc);
	if (noRndWalk)
		thisnpc.npc.setIsNoRndWalk(true);
	world.rooms.put("StartRoomTest", StartRoomTest);
	if (debug)
		_log.info("Instance Test: primera sala iniciada " + world.instanceId);
}

protected void runHallInstanceTest(ITestWorld world)
{
	spawnHallInstanceTest(world);
	world.status = 1;
	InstanceManager.getInstance().getInstance(world.instanceId).getDoor(DOOR1).openMe();
}

protected void spawnHallInstanceTest(ITestWorld world)
{
	ITestRoom HallTest = new ITestRoom();
	ITestNpc thisnpc;
	world.rooms.remove("HallTest");		//remove room instance to avoid adding mob every time

	thisnpc = new ITestNpc();
	thisnpc.npc = addSpawn(MOBTEST[0],147217,180112,-6117,0,false,0,false, world.instanceId);
	if (noRndWalk)
		thisnpc.npc.setIsNoRndWalk(true);
	HallTest.npcList.add(thisnpc);

	thisnpc = new ITestNpc();
	thisnpc.npc = addSpawn(MOBTEST[1],147217,180209,-6117,0,false,0,false, world.instanceId);
	if (noRndWalk)
		thisnpc.npc.setIsNoRndWalk(true);
	HallTest.npcList.add(thisnpc);

	thisnpc = new ITestNpc();
	thisnpc.npc = addSpawn(MOBTEST[2],148521,180112,-6117,0,false,0,false, world.instanceId);
	if (noRndWalk)
		thisnpc.npc.setIsNoRndWalk(true);
	HallTest.npcList.add(thisnpc);


	world.rooms.put("HallTest", HallTest);
	if (debug)
		_log.info("Instance Test: Hall Test spawned");
}

protected void endInstanceTest(ITestWorld world)
{
	world.status = 2;
	addSpawn(EXIT,147813,179654,-6117,16383,false,0,false,world.instanceId);
	world.rooms.clear();
	if (debug)
		_log.info("Instance Test: acabada");
}

protected boolean checkKillProgress(L2Npc npc, ITestRoom room)
{
	boolean cont = true;
	for (ITestNpc npcobj : room.npcList)
	{
		if (npcobj.npc == npc)
			npcobj.isDead = true;
		if (npcobj.isDead == false)
			cont = false;
	}

	return cont;
}

@Override
public String onKill( L2Npc npc, L2PcInstance player, boolean isPet)
{
	InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
	ITestWorld world;
	if (tmpworld instanceof ITestWorld)
	{
		world = (ITestWorld)tmpworld;
		if (world.status==0)
		{
			if (checkKillProgress(npc, world.rooms.get("StartRoomTest")))
				runHallInstanceTest(world);
		}
		if (world.status==1)
		{
			if (checkKillProgress(npc,world.rooms.get("HallTest")))
				endInstanceTest(world);
		}

	}

	return "";
}

@Override
public String onFirstTalk (L2Npc npc, L2PcInstance player)
{
	InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
	ITestWorld world;
	if (tmpworld instanceof ITestWorld)
	{
		world = (ITestWorld)tmpworld;

		if (npc.getNpcId() == EXIT && world.status == 2)
		{
			npc.showChatWindow(player);
			QuestState st = player.getQuestState(qn);
			if (st == null)
				st = newQuestState(player);

			if (st.getQuestItemsCount(REWARD) > 1)
				st.giveItems(REWARD,7777);
		}
	}

	return "";
}

@Override
public String onTalk (L2Npc npc, L2PcInstance player)
{
	int npcId = npc.getNpcId();
	if (npcId == ENTER)
	{
		teleCoord tele = new teleCoord();
		tele.x = 146534;
		tele.y = 180464;
		tele.z = -6117;
		enterInstance(player, "InstanceTest.xml", tele);
	}
	else
	{
		InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
		ITestWorld world;
		if (tmpworld instanceof ITestWorld)
			world = (ITestWorld)tmpworld;
		else
			return "";

		if (npcId == EXIT)
		{
			teleCoord tele = new teleCoord();
			tele.x = 139968;
			tele.y = 150367;
			tele.z = -3111;
			if (world.allowed.contains(player.getObjectId()))
			{
				if (debug)
					_log.info("Instance Test - id " + player.getObjectId() + " removed from allowed player in this Instances.");
				world.allowed.remove(world.allowed.indexOf(player.getObjectId()));
			}
			exitInstance(player,tele);
			int instanceId = npc.getInstanceId();
			Instance instance = InstanceManager.getInstance().getInstance(instanceId);
			if (instance.getPlayers().isEmpty())
				InstanceManager.getInstance().destroyInstance(instanceId);

			return "";
		}
	}

	return "";
}

public static void main(String[] args)
{
	// now call the constructor (starts up the)
	new InstanceTest(-1,"InstanceTest",qn);
}
}

 

 

And here is the error:

 

C:\Server\gameserver\data\scripts\instances\InstanceTest\InstanceTest.java
java.lang.NullPointerException
at instances.InstanceTest.InstanceTest.openDoor(InstanceTest.java:87)
at instances.InstanceTest.InstanceTest.runHallInstanceTest(InstanceTest.
java:244)
at instances.InstanceTest.InstanceTest.onKill(InstanceTest.java:312)
at com.l2jserver.gameserver.model.quest.Quest.notifyKill(Quest.java:476)

at com.l2jserver.gameserver.model.actor.L2Attackable$OnKillNotifyTask.ru
n(L2Attackable.java:572)
at com.l2jserver.gameserver.ThreadPoolManager$RunnableWrapper.run(Thread
PoolManager.java:86)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

java.lang.NullPointerException
at instances.InstanceTest.InstanceTest.openDoor(InstanceTest.java:87)
at instances.InstanceTest.InstanceTest.runHallInstanceTest(InstanceTest.
java:244)
at instances.InstanceTest.InstanceTest.onKill(InstanceTest.java:312)
at com.l2jserver.gameserver.model.quest.Quest.notifyKill(Quest.java:476)

at com.l2jserver.gameserver.model.actor.L2Attackable$OnKillNotifyTask.ru
n(L2Attackable.java:572)
at com.l2jserver.gameserver.ThreadPoolManager$RunnableWrapper.run(Thread
PoolManager.java:86)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

 

 

Can someone help me to fix this error?

3 answers to this question

Recommended Posts

  • 0
Posted

openDoor() is let null. You must initialize it somehow (surely with door DOOR1).

 

See how others instances are made on this side (use of openDoor( method).

 

 

  • 0
Posted

All the Instance that I see in L2j have the method openDoor(). For example, in Dark Cloud Mansion or Crystal Caverns. I've just copied the method and I don't know why I have this error if the method identical.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • You might also take https://github.com/vercel-labs/agent-skills into consideration
    • Hay Algun datapack de L1 OFF ? 
    • pone los link para descargarlos por fa   
    • Greetings, everyone. I am sharing a configuration designed for any code editor/console with AI agents. This setup allows for expanded context and highly specific skills depending on your project requirements. It also comes with reusable skills ready for immediate use. Current configuration covers: WEB, L2j server datapacks, and L2j dev (including skills for handling decompiled Java datapacks, etc.). I have left a LINK to the original video on which this specific configuration is based. It also contains brief guides on how to implement new skills. You can simply ask your AI agent to review the guide to get started.   https://github.com/zambo420/Supercharge-your-AI-assistant-for-WEB-and-L2-DATAPACKS-dev.-.git   # 🤖 AI Skills Starter Kit - Forum Quick Start > **Supercharge your AI assistant (Claude, Gemini, Copilot)** ## ⚡ Installation in 2 Minutes   ### 1. Download and copy Copy the `Supercharge-your-AI-assistant-for-WEB-and-L2-DATAPACKS-dev.-/` folder to your project root.   ### 2. Rename and structure ``` your-project/ ├── skills/                      # Rename skills_reutilizables → skills │   ├── skill-creator/ │   ├── react-19/               # Copy the ones you need │   ├── typescript/ │   └── setup.ps1               # Copy from templates/ ├── AGENTS.md                    # Copy from templates/AGENTS.md.template └── src/                         # Your code ```   ### 3. Edit AGENTS.md Customize with your skills:   ```markdown   ## Available Skills | Skill | Description | File | |-------|-------------|------| | `react-19` | React 19 patterns | [SKILL.md](skills/react-19/SKILL.md) |   ## Auto-invoke Skills | Action | Skill | |--------|-------| | Working with React components | `react-19` | ```   ### 4. Sync ```powershell .\skills\setup.ps1 ```   ### 5. Done! Restart your AI assistant and start working.   ---   ## 📦 Included Skills (56 Total) ### Frontend - `react-19` - React 19, hooks, RSC - `typescript` - TypeScript patterns - `tailwind-4` - TailwindCSS v4 - `vite` - Build configuration - `zustand-5` - State management - `nextjs-15` - Next.js 15 - `i18next` - Internationalization - `react-router` - React Router v7 ### Backend - `zod-4` - Validation schemas - `ioredis` - Redis caching - `jwt` - JWT authentication - `django-drf` - Django REST Framework ### Testing & AI - `playwright` - E2E testing - `pytest` - Python testing - `ai-sdk-5` - Vercel AI SDK ### Utilities - `skill-creator` - Create new skills - `java-ant-build` - Apache Ant build system - `jira-epic` - Create Jira epics - `jira-task` - Create Jira tasks ### L2J/Game Server (33 skills) - `gameserver-data` - XMLs, multisells, spawns, NPCs - `gameserver-config` - Server configuration files - `authserver-config` - Login server configuration - `client-files` - Client textures, L2Text, system - `lucera2-core` - L2J core patterns, base classes - `lucera2-handlers` - Admin/user commands, bypass - `lucera2-services` - Community Board, ACP, Buffer - `lucera2-scripts` - Quests, NPCs, bosses, events - `lucera2-network` - Network packets - `lucera2-geodata` - Pathfinding, line of sight - `lucera2-ai` - NPC AI, monster behavior - `lucera2-zones` - Zone scripts, restrictions - `lucera2-achievements` - Achievement system - `lucera2-phantoms` - Fake players (bots) - `lucera2-data` - XML/SQL parsers, holders - `lucera2-authserver` - Login server Java code - `lucera2-olympiad` - Olympiad, heroes, nobles - `lucera2-residences` - Castles, clan halls, siege - `lucera2-skills-effects` - Skill effects, conditions - `lucera2-telegram` - Telegram bot integration - `lucera2-events-pvp` - TvT, GvG, CTF events - `lucera2-seasonal-events` - Holiday events - `lucera2-npc-instances` - Custom NPC types - `lucera2-items-inventory` - Items, inventory - `lucera2-clans-alliances` - Clans, wars - `lucera2-voting-ranking` - Voting rewards - `lucera2-siege-duel` - Siege, duel mechanics - `lucera2-pets-summons` - Pets, servitors - `lucera2-promo-rewards` - Promo codes, daily rewards - `lucera2-item-handlers` - Item handlers - `lucera2-instances-dungeons` - Instance dungeons - `lucera2-minigames` - Lottery, Fishing - `lucera2-autofarm` - AutoFarm bot system - `lucera2-party-matching` - Party finder - `lucera2-cursed-weapons` - Zariche, Akamanah - `lucera2-vip-premium` - VIP/premium accounts - `lucera2-extjar-projects` - Creating .ext.jar projects ---   ## 🎯 The Magic Trick The **Auto-invoke** table is the key:   ```markdown ## Auto-invoke Skills   | Action | Skill | |--------|-------| | Creating React components | `react-19` | | Adding TypeScript types | `typescript` | | Writing E2E tests | `playwright` | ```   **Without this table, AI ignores skills.** With it, they load automatically.   ---   ## 📁 Important Files | File | Purpose | |------|---------| | `AGENTS.md` | Main agent configuration | | `skills/setup.ps1` | Syncs to .claude/.gemini/.github | | `skills/*/SKILL.md` | Each skill definition |   ---   ## 💡 Tips 1. **One place only**: Keep all skills in `skills/` 2. **Auto-invoke**: Without this table, it won't work 3. **setup.ps1**: Run after every change 4. **Restart**: AI needs restart to load changes   ---   ## 🔧 Create Your Own Skill   ```markdown --- name: my-skill description: My skill description ---   ## When to Use - When to use this skill   ## Key Patterns - Important patterns   ## Code Examples \`\`\`typescript // Code example \`\`\` ```   Add to AGENTS.md and run `.\skills\setup.ps1`.   ---   ## 🤝 Compatibility - ✅ Claude Code (Antigravity) - ✅ Gemini CLI - ✅ GitHub Copilot - ✅ Cursor - ✅ Any AI that supports AGENTS.md   ---   ## 📚 More Info See `README.md` on github for complete guide and detailed documentation.    
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..

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