Jump to content
  • 0

NPC displaying HTML from java


Question

Posted (edited)

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

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

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
  • Like 1
  • 0
Posted
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.

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
Answer this question...

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