Author Topic: High Five [GUIDE] Connect Npc's with Community Board  (Read 407 times)

Offline Invoke

  • Heir
  • **
  • Posts: 15
[GUIDE] Connect Npc's with Community Board
« on: March 30, 2020, 11:41:11 AM »
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 versions but let me know if it does not.

1) So 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

It also can be configurable if you want.

Code: [Select]
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");
}

}