L2JMobius

Free Users => Shares/Contributions => Topic started by: Invoke on March 30, 2020, 11:41:11 AM

Title: [GUIDE] Connect Npc's with Community Board
Post by: Invoke 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");
}

}
Title: Re: [GUIDE] Connect Npc's with Community Board
Post by: l2retro on June 13, 2022, 08:59:20 PM
More detailed guide please? Should I just create CBnpcs.java in eclipse and recompile for the link to work or there are other things to change too? I already got a custom community board, only buffer wont work, which I'd like to connect to scheme buffer...
Title: Re: [GUIDE] Connect Npc's with Community Board
Post by: tomalko on November 02, 2022, 07:59:47 AM
I adapted it. But the NPC can't install 36621 36622.
How do I create an NPC?

Code: [Select]
package custom.CommunityNpcs;

import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.handler.CommunityBoardHandler;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.quest.Quest;
import org.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(Npc npc, PlayerInstance 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");
}

}