Devlin Posted March 15, 2014 Posted March 15, 2014 Hello guys. I made a clan manager for a guy. I decided to share it with you. What that manager does? You can change your clan's level, your clan's reputation score and add clan skills. Code is untested, I would be greatful if someone test it. The code: http://pastebin.com/n4kY3kbJ Thanks in advance. All credits are mine.
xdem Posted March 15, 2014 Posted March 15, 2014 (edited) + public int itemId = 57; + public int itemCountLevelUp = 10000; + public int itemCountReputationPoints = 100000; + public int itemCountClanSkills = 100000000; + public int clanLevel = 1; + public int clanReputationScore = 1000; + public int[] clanSkills = { + { + 370, + 371, + 372, + 373, + 374, + 375, + 376, + 377, + 378, + 379, + 380, + 381, + 382, + 383, + 384, + 385, + 386, + 387, + 388, + 389, + 390, + 391 + all these should be private static final + if (player.getClan() != null) + { + player.sendMessage("You don't have a clan."); + return; + } this is wrong + for (int s : clanSkills) + { + L2Skill clanSkill = SkillTable.getInstance().getInfo(s, SkillTable.getInstance().getMaxLevel(s)); + player.getClan().addNewSkill(clanSkill); + player.getClan().broadcastClanStatus(); + player.getInventory().destroyItemByItemId("Init.", itemId, itemCountClanSkills, player, player); + player.sendMessage("Your clan has learned all clan skills."); + } this should be + for (int s : clanSkills) + { + L2Skill clanSkill = SkillTable.getInstance().getInfo(s, SkillTable.getInstance().getMaxLevel(s)); + player.getClan().addNewSkill(clanSkill); + //if clan already owns this skill; continue; + if (!player.getInventory().destroyItemByItemId("ClanSkill", itemId, itemCountClanSkills, player, player)) + { + player.sendMessage("you dont have enough materials for this clan skill); + break; + } + player.sendMessage("Your clan has learned all clan skills."); + } + player.getClan().broadcastClanStatus(); Edited March 15, 2014 by xdem
SweeTs Posted March 15, 2014 Posted March 15, 2014 (edited) Haha this one is the best :happyforever: Surely you wanted to write == :P + if (player.getClan() != null) + { + player.sendMessage("You don't have a clan."); + return; + } Edited March 15, 2014 by SweeTs
Tryskell Posted March 16, 2014 Posted March 16, 2014 There's a lot of improvements to do : * all commands use the same checks so you can reduce amount of produced code (using for example if (command.startsWith("clan")) * the skills array is from 370 to 391 so you can use old school for loop to avoid to store anything (not needed to store stuff which can be easily guessed). * as said SweeTs the clan check makes the whole code broken. * as said xdem you should check if you can destroy the item before trying to "reward" for the given action, otherwise it's a big exploit. xdem code got also a problem btw.
Devlin Posted March 16, 2014 Author Posted March 16, 2014 There's a lot of improvements to do : * all commands use the same checks so you can reduce amount of produced code (using for example if (command.startsWith("clan")) * the skills array is from 370 to 391 so you can use old school for loop to avoid to store anything (not needed to store stuff which can be easily guessed). * as said SweeTs the clan check makes the whole code broken. * as said xdem you should check if you can destroy the item before trying to "reward" for the given action, otherwise it's a big exploit. xdem code got also a problem btw. Yeah thanks for that suggestions. I was in hurry about posting the code so I didn't notice that kind of typos.
xdem Posted March 16, 2014 Posted March 16, 2014 There's a lot of improvements to do : * all commands use the same checks so you can reduce amount of produced code (using for example if (command.startsWith("clan")) * the skills array is from 370 to 391 so you can use old school for loop to avoid to store anything (not needed to store stuff which can be easily guessed). * as said SweeTs the clan check makes the whole code broken. * as said xdem you should check if you can destroy the item before trying to "reward" for the given action, otherwise it's a big exploit. xdem code got also a problem btw. yes, I made that mistake cause I used his code, I gave the skill and then I asked for the price, what a dumb
Thug!! Posted June 1, 2014 Posted June 1, 2014 327Rev> not tested ( i just fix the build error about -import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate; with that +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate; and that - public L2ClanManagerInstance(int objectId, L2NpcTemplate template) with that + public L2ClanManagerInstance(int objectId, NpcTemplate template) /* * 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 net.sf.l2j.gameserver.model.actor.instance; import net.sf.l2j.gameserver.datatables.SkillTable; import net.sf.l2j.gameserver.model.L2Skill; import net.sf.l2j.gameserver.network.serverpackets.ActionFailed; import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.model.actor.template.NpcTemplate; /** * @author Devlin * */ public class L2ClanManagerInstance extends L2NpcInstance { public L2ClanManagerInstance(int objectId, NpcTemplate template) { super(objectId, template); } @Override public void showChatWindow(L2PcInstance player, int val) { player.sendPacket(ActionFailed.STATIC_PACKET); String filename = "data/html/mods/clanManager.htm"; NpcHtmlMessage html = new NpcHtmlMessage(getObjectId()); html.setFile(filename); html.replace("%objectId%", String.valueOf(getObjectId())); player.sendPacket(html); } public int itemId = 57; public int itemCountLevelUp = 15; public int itemCountReputationPoints = 15; public int itemCountClanSkills = 20; public int clanLevel = 8; public int clanReputationScore = 30000; public int[] clanSkills = { 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391 }; @Override public void onBypassFeedback(L2PcInstance player, String command) { if (command.equals("clanLevelUp")) { if (player.getClan() != null) { player.sendMessage("You don't have a clan."); return; } if (!player.isClanLeader()) { player.sendMessage("You aren't the leader of your clan."); return; } if (player.getInventory().getItemByItemId(itemId).getCount() > itemCountLevelUp) { player.sendMessage("You don't have enough items."); return; } player.getClan().changeLevel(player.getClan().getLevel() + clanLevel); player.getClan().broadcastClanStatus(); player.getInventory().destroyItemByItemId("Init.", itemId, itemCountLevelUp, player, player); player.sendMessage("Your clan's level has been changed to "+player.getClan().getLevel()); } else if (command.equals("clanReputationPoints")) { if (player.getClan() != null) { player.sendMessage("You don't have a clan."); return; } if (!player.isClanLeader()) { player.sendMessage("You aren't the leader of your clan."); return; } if (player.getInventory().getItemByItemId(itemId).getCount() > itemCountReputationPoints) { player.sendMessage("You don't have enough items."); return; } player.getClan().addReputationScore(clanReputationScore); player.getClan().broadcastClanStatus(); player.getInventory().destroyItemByItemId("Init.", itemId, itemCountReputationPoints, player, player); player.sendMessage("Your clan's reputation score has been changed to "+player.getClan().getReputationScore()); } else if (command.equals("clanSkills")) { if (player.getClan() != null) { player.sendMessage("You don't have a clan."); return; } if (!player.isClanLeader()) { player.sendMessage("You aren't the leader of your clan."); return; } if (player.getInventory().getItemByItemId(itemId).getCount() > itemCountClanSkills) { player.sendMessage("You don't have enough items."); return; } for (int s : clanSkills) { L2Skill clanSkill = SkillTable.getInstance().getInfo(s, SkillTable.getInstance().getMaxLevel(s)); player.getClan().addNewSkill(clanSkill); player.getClan().broadcastClanStatus(); player.getInventory().destroyItemByItemId("Init.", itemId, itemCountClanSkills, player, player); player.sendMessage("Your clan has learned all clan skills."); } } } }
WolfGiaS3na Posted June 1, 2014 Posted June 1, 2014 (edited) Haha this one is the best :happyforever: Surely you wanted to write == :P + if (player.getClan() != null) + { + player.sendMessage("You don't have a clan."); + return; + } he want to say if clan is different than Nothing then you don't have a clan he is right <3 xD Edited June 1, 2014 by WolfGiaS3na
Devlin Posted June 1, 2014 Author Posted June 1, 2014 This code is pretty old, there is a new version of it. I will update it right now.
Recommended Posts