Jump to content

Connect Npc's with Community Board


Recommended Posts

Hey guys if you are doing a project from the scratch and looking for a way to connect community board with the htmls i think this is a good way to do it even though there are many ways!

 

I am just giving the idea here so please don't flame with better codes and stuff :)

 

I will do this in l2j mobious H5, i think it works mostly in all packs but let me know if it does not.

 

1) So you basically you are gonna create a new custom script that will extend Quest, in this case I named it CBnpcs.java (scripts/custom/CommunityNpcs/CBnpcs.java)

2)  Set the ids of our custom npcs

3) You have to add them on firsttalk , talk, startnpc each one separately just like bellow

4) Then the link where you have stored your htmls

5) So if you want to create more npcs connecting them to CB you can simply copy and paste the else ifs and set more ids

6) Some packs i think require the scripts to be registered on scripts.cfg so do that as well if you own such pack

 

package custom.CommunityNpcs;

import com.l2jmobius.gameserver.cache.HtmCache;
import com.l2jmobius.gameserver.handler.CommunityBoardHandler;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.quest.Quest;
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;

/**
 * @author -Invoke
 */
public class CBnpcs extends Quest
{	
	private static final int Merchant = 36621;
	private static final int Gatekeeper = 36622;

public CBnpcs(int questId)
	{
		super(questId);
		addFirstTalkId(Merchant);
		addFirstTalkId(Gatekeeper);
		//
		addTalkId(Merchant);
		addTalkId(Gatekeeper);
		//
		addStartNpc(Merchant);
		addStartNpc(Gatekeeper);
	}

@Override
	public String onFirstTalk(L2Npc npc, L2PcInstance player)
	{
		
		final int npcId = npc.getId();
		String mainhtml = HtmCache.getInstance().getHtm(player, "data/html/CommunityBoard/Custom/main.html");
	
		if (npcId == Merchant)
		{
			
			String html = HtmCache.getInstance().getHtm(player, "data/html/CommunityBoard/Custom/merchant/main.html");
			CommunityBoardHandler.separateAndSend(html, player);
		}
		else if (npcId == Gatekeeper)
		{
			
			String html = HtmCache.getInstance().getHtm(player, "data/html/CommunityBoard/Custom/gatekeeper/main.html");
			CommunityBoardHandler.separateAndSend(html, player);
		}
		CommunityBoardHandler.separateAndSend(mainhtml, player);
		return "";
	}
	
	public static void main(final String[] args)
	{
		new CBnpcs(-1);
		LOGGER.info("COMMYNITY NPCS LOADED");
	}

}

 

  • Like 2
  • Thanks 2
  • Upvote 5
Link to comment
Share on other sites

  • 1 month later...

Some clean/short of onFirstTalk method

public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
	String path = "data/html/CommunityBoard/Custom/main.html";
	switch(npc.getId())
	{
		case Merchant:
			 path = "data/html/CommunityBoard/Custom/merchant/main.html";
			break;
		case Gatekeeper:
			 path = "data/html/CommunityBoard/Custom/gatekeeper/main.html";
			break;
	}
	CommunityBoardHandler.separateAndSend(HtmCache.getInstance().getHtm(player, path), player);
	return null;
}
  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...
On 5/27/2020 at 10:59 PM, StinkyMadness said:

Some clean/short of onFirstTalk method


public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
	String path = "data/html/CommunityBoard/Custom/main.html";
	switch(npc.getId())
	{
		case Merchant:
			 path = "data/html/CommunityBoard/Custom/merchant/main.html";
			break;
		case Gatekeeper:
			 path = "data/html/CommunityBoard/Custom/gatekeeper/main.html";
			break;
	}
	CommunityBoardHandler.separateAndSend(HtmCache.getInstance().getHtm(player, path), player);
	return null;
}

yep ! good onee!

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

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
Reply to this topic...

×   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...