跳转到帖子
Facebook Instagram Twitter Youtube

【L2J】改名脚本Rename.java


杀气丶

已推荐帖子

  • VIP
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package custom.RenameNPC;

import com.l2jse.gameserver.communitybbs.Manager.RegionBBSManager;
import com.l2jse.gameserver.datatables.CharNameTable;
import com.l2jse.gameserver.datatables.ItemTable;
import com.l2jse.gameserver.instancemanager.QuestManager;
import com.l2jse.gameserver.model.L2World;
import com.l2jse.gameserver.model.actor.L2Npc;
import com.l2jse.gameserver.model.actor.instance.L2PcInstance;
import com.l2jse.gameserver.model.quest.Quest;
import com.l2jse.gameserver.model.quest.QuestState;
import com.l2jse.gameserver.network.serverpackets.PartySmallWindowAll;
import com.l2jse.gameserver.network.serverpackets.PartySmallWindowDeleteAll;
import com.l2jse.gameserver.util.Util;

/**
* @author L0ngh0rn
* @since 2009-10-25
*/
public class RenameNPC extends Quest
{
        private final static int NPC = 50024;
        private final static String RENAME_NPC_FEE = "57,2500000;5575,250000";
        private final static int RENAME_NPC_MIN_LEVEL = 40;

        public RenameNPC(int questId, String name, String descr)
        {
                super(questId, name, descr);
                addFirstTalkId(NPC);
                addStartNpc(NPC);
                addTalkId(NPC);
        }

        @Override
        public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
        {
                String htmltext = "New Name:<br1><edit var="newname" width=70 height=10>";
                String eventSplit[] = event.split(" ");
                QuestState st = player.getQuestState(getName());

                if (eventSplit[0].equalsIgnoreCase("rename"))
                {
                        st.getPlayer().setTarget(st.getPlayer());
                        if (eventSplit.length != 2)
                                htmltext = "Enter a new name or remove the space between the names.";
                        else if (st.getPlayer().getLevel() < RENAME_NPC_MIN_LEVEL)
                                htmltext = "Minimum Level is: " + String.valueOf(RENAME_NPC_MIN_LEVEL);
                        else if (validItemFee(st))
                                htmltext = "You do not have enough items for exchange.";
                        else if (eventSplit[1].length() < 1 || eventSplit[1].length() > 16)
                                htmltext = "Maximum number of characters: 16";
                        else if (!Util.isAlphaNumeric(eventSplit[1]))
                                htmltext = "The name must only contain alpha-numeric characters.";
                        else if (CharNameTable.getInstance().doesCharNameExist(eventSplit[1]))
                                htmltext = "The name chosen is already in use. Choose another name.";
                        else
                        {
                                try
                                {
                                        L2World.getInstance().removeFromAllPlayers(player);
                                        player.setName(eventSplit[1]);
                                        player.store();
                                        L2World.getInstance().addToAllPlayers(player);
                                        htmltext = "Its name was changed successfully.";
                                        player.broadcastUserInfo();

                                        String itemFeeSplit[] = RENAME_NPC_FEE.split("\\;");
                                        for (int i = 0; i < itemFeeSplit.length; i++)
                                        {
                                                String item[] = itemFeeSplit[i].split("\\,");
                                                st.takeItems(Integer.parseInt(item[0]), Integer.parseInt(item[1]));
                                        }

                                        if (player.isInParty())
                                        {
                                                player.getParty().broadcastToPartyMembers(player, new PartySmallWindowDeleteAll());
                                                for (L2PcInstance member : player.getParty().getPartyMembers())
                                                {
                                                        if (member != player)
                                                                member.sendPacket(new PartySmallWindowAll(member, player.getParty()));
                                                }
                                        }
                                        if (player.getClan() != null)
                                                player.getClan().broadcastClanStatus();
                                        RegionBBSManager.getInstance().changeCommunityBoard();
                                }
                                catch (StringIndexOutOfBoundsException e)
                                {
                                        htmltext = "Service unavailable!";
                                }
                        }
                        return (page(htmltext, 1));
                }
                return (page(htmltext, 0));
        }

        @Override
        public String onFirstTalk(L2Npc npc, L2PcInstance player)
        {
                String htmltext = "";
                QuestState st = player.getQuestState(getName());
                if (st == null)
                {
                        Quest q = QuestManager.getInstance().getQuest(getName());
                        st = q.newQuestState(player);
                }
                htmltext = page("New Name:<br1><edit var="newname" width=70 height=10>", 0);
                return htmltext;
        }

        public String page(String msg, int t)
        {
                String htmltext = "";
                htmltext += htmlPage("Title");
                htmltext += "Hello I'm here to help you change your name.<br>" + "Enter your new name, but make sure you have items for exchange:<br1>";
                String itemFeeSplit[] = RENAME_NPC_FEE.split("\\;");
                for (int i = 0; i < itemFeeSplit.length; i++)
                {
                        String item[] = itemFeeSplit[i].split("\\,");
                        htmltext += "<font color="LEVEL">" + item[1] + " " + ItemTable.getInstance().getTemplate(Integer.parseInt(item[0])).getName() + "</font><br1>";
                }
                if (t == 0)
                {
                        htmltext += "<br><font color="339966">" + msg + "</font>";
                        htmltext += "<br><center>" + button("Renomear", "rename $newname", 70, 23) + "</center>";
                }
                else
                {
                        htmltext += "<br><font color="FF0000">" + msg + "</font>";
                        htmltext += "<br><center>" + button("Back", "begin", 70, 23) + "</center>";
                }
                htmltext += htmlPage("Footer");
                return htmltext;
        }

        public Boolean validItemFee(QuestState st)
        {
                String itemFeeSplit[] = RENAME_NPC_FEE.split("\\;");
                for (int i = 0; i < itemFeeSplit.length; i++)
                {
                        String item[] = itemFeeSplit[i].split("\\,");
                        if (st.getQuestItemsCount(Integer.parseInt(item[0])) < Integer.parseInt(item[1]))
                                return true;
                }
                return false;
        }

        public String htmlPage(String op)
        {
                String texto = "";
                if (op == "Title")
                {
                        texto += "<html><body><title>Rename Manager</title><center><br>" + "<b><font color=ffcc00>Rename Manager Information</font></b>"
                                        + "<br><img src="L2UI_CH3.herotower_deco" width="256" height="32"><br></center>";
                }
                else if (op == "Footer")
                {
                        texto += "<br><center><img src="L2UI_CH3.herotower_deco" width="256" height="32"><br>" + "<br><font color="303030">---</font></center></body></html>";
                }
                else
                {
                        texto = "Not Found!";
                }
                return texto;
        }

        public String button(String name, String event, int w, int h)
        {
                return "<button value="" + name + "" action="bypass -h Quest RenameNPC " + event + "" " + "width="" + Integer.toString(w) + "" height="" + Integer.toString(h) + "" "
                                + "back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">";
        }

        public String link(String name, String event, String color)
        {
                return "<a action="bypass -h Quest RenameNPC " + event + "">" + "<font color="" + color + "">" + name + "</font></a>";
        }

        public static void main(String[] args)
        {
                new RenameNPC(-1, "RenameNPC", "custom");
        }
}

这是从l2jse的端里找出来的玩家改名脚本

 

如果大家想用,需要手动修改一些地方!!

 

感兴趣的拿走!~

意见的链接
分享到其他站点

参与讨论

你可以现在发布并稍后注册。 如果你有帐户,现在就登录发布帖子。

游客
回帖…

×   粘贴为富文本.   粘贴为纯文本来代替

  只允许使用75个表情符号.

×   你的链接已自动嵌入.   显示为链接来代替

×   你之前的帖子已恢复.   清除编辑器

×   你无法直接粘贴图像。要从网址上传或插入图像。

天堂2中文开源社区L2FATER.CN

专注于玩家游戏体验的交流社区.

血玫瑰社区bbs.l2fater.cn

关于血玫瑰社区

Important Links

×
×
  • 创建新的...