Skip to content

NPC displaying HTML from java

Featured Replies

Hi, I have a pvp ranking code and it runs with the .pvp command. I would like an NPC to call this command. How should I proceed?

 

Quote
package com.l2jserver.datapack.handlers.voicedcommandhandlers;


import java.sql.Connection;
import java.sql.PreparedStatement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;

import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jserver.commons.database.ConnectionFactory;
import com.l2jserver.gameserver.GameServer;
/**
 * This class trades Gold Bars for Adena and vice versa.
 * @author Ahmed
 */
public class RankedEvent implements IVoicedCommandHandler {
	private static final String[] _voicedCommands = {
		"pvp"
	};
	
	private static final Logger LOG = LoggerFactory.getLogger(GameServer.class);
	
	@Override
	public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
		if (command.equals("pvp")) {
			NpcHtmlMessage html = new NpcHtmlMessage(1);
			StringBuilder tb = new StringBuilder();
			tb.append("<html>");
			tb.append("<title>Ranked Event</title>");
			tb.append("<body>");
			tb.append("<center>");
			tb.append("<br><font color=\"ffffff\">______________________________________</font>");
			Connection con = null;
			try {
				con = ConnectionFactory.getInstance().getConnection();
				PreparedStatement statement = con.prepareStatement("SELECT char_name, pvpkillsevent FROM characters WHERE accesslevel=0 order by pvpkillsevent desc limit 10");
				var rs = statement.executeQuery();
				int pos = 0;
				while (rs.next()) {
					String pvp = rs.getString("pvpkillsevent");
					String name = rs.getString("char_name");
					pos += 1;
					int x = pos - 1;
					tb.append("<br1><font color=\"B2222"+x+"\">" + pos + " - Player: "+name+" = "+pvp+"</font>");
				}
			}
			catch (Exception e) {
				LOG.warn("Could not select pvpkillsevent data: " + e.getMessage(), e);
			}
			finally {
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			tb.append("<br1><font color=\"ffffff\">______________________________________</font>");
			tb.append("<br1><font color=\"ffffff\">REWARD IN NEXT WEEK</font>");
			tb.append("</center></body>");
			tb.append("</html>");
			html.setHtml(tb.toString());
			activeChar.sendPacket(html);
		}
		return true;
	}
	
	@Override
	public String[] getVoicedCommandList() {
		return _voicedCommands;
	}
}

 

 

Edited by Vision

create a class on -> model.actor.instance that extends Folk / L2Npc / Npc (depend the source u using)  based on ur code instead using the voice command , use it on the

onBypassFeedback

 

and call ur code and appends to show the NpcHtmlWindow with onAction to Player/PlayerInstance/L2PcInstance etc 

create an npc afterwards as type "name of your class instance" 

Edited by Kishin

1 - Use a Map to store content, ppl can flood your server simply pushing one button (put command in macro and voila, ask your clan to do that). Db should be used only to load/save at start/stop, or eventually for important stuff (character/inventories). Tbh, characters got no reason to store that info it should be a specific table (or even better, PlayerMemo).
2 - Make a new Npc instance or, even better, a new script with onFirstTalk event.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.