Advertisement
Guest User

Npchat

a guest
Oct 28th, 2010
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MasterHandler.java
  2.  
  3.                  AdminCommandHandler.getInstance().registerAdminCommandHandler(new AdminZone());
  4.                  AdminCommandHandler.getInstance().registerAdminCommandHandler(new AdminTownWar());
  5. +                AdminCommandHandler.getInstance().registerAdminCommandHandler(new AdminNpcChat());
  6.                  _log.config("Loaded " + AdminCommandHandler.getInstance().size() + "  AdminCommandHandlers");
  7.          }
  8.  
  9. admin_command_access_rights.sql
  10.  
  11.  
  12.  
  13. ('admin_townwar_end','1'),
  14. +
  15. +-- Npchat
  16. +('admin_npchat_menu','1'),
  17. +('admin_npchat','1');
  18.  
  19.  
  20. AdminNpcChat.java
  21.  
  22.  
  23. /*
  24.  * This program is free software: you can redistribute it and/or modify it under
  25.  * the terms of the GNU General Public License as published by the Free Software
  26.  * Foundation, either version 3 of the License, or (at your option) any later
  27.  * version.
  28.  *
  29.  * This program is distributed in the hope that it will be useful, but WITHOUT
  30.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  31.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  32.  * details.
  33.  *
  34.  * You should have received a copy of the GNU General Public License along with
  35.  * this program. If not, see <http://www.gnu.org/licenses/>.
  36.  *
  37.  * @author Flash
  38.  */
  39.  
  40.  
  41.  
  42.  
  43. package handlers.admincommandhandlers;
  44.  
  45. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  46. import com.l2jserver.gameserver.model.L2Object;
  47. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  48. import com.l2jserver.gameserver.network.SystemMessageId;
  49. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  50. import com.l2jserver.gameserver.model.actor.L2Npc;
  51. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  52. public class AdminNpcChat implements IAdminCommandHandler
  53. {
  54.    
  55.     private static final String[] ADMIN_COMMANDS =
  56.     {
  57.         "admin_npchat",
  58.         "admin_npchat_menu"
  59.     };
  60.    
  61.     public boolean useAdminCommand(String command, L2PcInstance activeChar)
  62.     {
  63.         if (command.startsWith("admin_npchat"))
  64.             handleNPChat(command, activeChar);
  65.         if (command.startsWith("admin_npchat_menu"))
  66.             AdminHelpPage.showHelpPage(activeChar, "Npchat_menu.htm");
  67.         return true;
  68.     }
  69.        
  70.            public String[] getAdminCommandList()
  71.     {
  72.         return ADMIN_COMMANDS;
  73.     }
  74.    
  75.     /**
  76.      * @param command
  77.      * @param activeChar
  78.      */
  79.     private void handleNPChat(String command, L2PcInstance activeChar)
  80.     {
  81.         try
  82.         {
  83.         L2Object target = activeChar.getTarget();
  84.         L2Npc npc = null;
  85.         if (target instanceof L2Npc)
  86.         {
  87.                         int offset = 0;
  88.             npc = (L2Npc) target;
  89.                         int npcId = npc.getNpcId();
  90.                 int npcObjId = npc.getObjectId();
  91.                         String text;
  92.             if (command.startsWith("admin_npchat_menu"))
  93.                 offset = 18;
  94.             else
  95.                 offset = 13;
  96.             text = command.substring(offset);
  97.  
  98.  
  99.             npc.broadcastPacket(new NpcSay(npcObjId, 0, npcId, text));
  100.         }
  101.         else
  102.         {
  103.             activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  104.             return;
  105.         }
  106.            
  107.         }
  108.         catch (StringIndexOutOfBoundsException e)
  109.         {
  110.             // empty message.. ignore
  111.         }
  112.     }
  113. }
  114.  
  115.  
  116.  
  117. Npchat_menu.htm
  118.  
  119. <html>
  120. <title>NPC Says</title><body>
  121. Instructions:<br>
  122. Target the NPC and write whatever you want to make the NPC say.
  123. <br>
  124. <center>Text:<multiedit var="texto" width=250 height=50></center>
  125. <table width="160">
  126. <tr>
  127. <td><center><button value="Say" action="bypass -h admin_npchat_menu $texto" width=80 height=21 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df"></center></td>
  128. </tr></table><br><br><br>
  129. </body>
  130. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement