Sheol Posted January 7, 2023 Posted January 7, 2023 (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 January 10, 2023 by Vision Quote
0 Acacia Posted January 8, 2023 Posted January 8, 2023 (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 January 8, 2023 by Kishin 1 Quote
0 Tryskell Posted January 9, 2023 Posted January 9, 2023 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. Quote
Question
Sheol
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?
2 answers to this question
Recommended Posts
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.