Adding/Removing Item command
Add this in your commands
PHP Code:
} else if (splitted[0].equalsIgnoreCase("playeritem")) {
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
victim.playerGain(Integer.parseInt(splitted[2]),Integer.parseInt(splitted[3]));
player.dropMessage("You have given " + victim.getName() + " the item " + splitted[2] + "");
victim.dropMessage("You have gained an " + splitted[2] + " from " + player.getName() + "");
} else if (splitted[0].equalsIgnoreCase("playerequip")) {
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
victim.playerEquip(Integer.parseInt(splitted[2]),Integer.parseInt(splitted[3]));
victim.dropMessage("" + player.getName() + " has taken " + splitted[3] + " of " + splitted[2] + " from you.");
} else if (splitted[0].equalsIgnoreCase("playeruse")) {
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
victim.playerUse(Integer.parseInt(splitted[2]),Integer.parseInt(splitted[3]));
victim.dropMessage("" + player.getName() + " has taken " + splitted[3] + " of " + splitted[2] + " from you.");
} else if (splitted[0].equalsIgnoreCase("playercash")) {
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
victim.playerCash(Integer.parseInt(splitted[2]),Integer.parseInt(splitted[3]));
victim.dropMessage("" + player.getName() + " has taken " + splitted[3] + " of " + splitted[2] + " from you.");
} else if (splitted[0].equalsIgnoreCase("playeretc")) {
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
victim.playerEtc(Integer.parseInt(splitted[2]),Integer.parseInt(splitted[3]));
victim.dropMessage("" + player.getName() + " has taken " + splitted[3] + " of " + splitted[2] + " from you.");
} else if (splitted[0].equalsIgnoreCase("playersetup")) {
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
victim.playerSetup(Integer.parseInt(splitted[2]),Integer.parseInt(splitted[3]));
victim.dropMessage("" + player.getName() + " has taken " + splitted[3] + " of " + splitted[2] + " from you.");
Add this in MapleCharacter
PHP Code:
public void playerGain(int item, int amount) {
if (MapleInventoryManipulator.addById(client, item, (short) amount, null, -1)) {
} else {
try {
client.getPlayer().getClient().getChannelServer().getWorldInterface().broadcastMessage(null, MaplePacketCreator.serverNotice(1, " " + client.getPlayer().getName() + " has not recieved their item " + item + "").getBytes());
} catch (RemoteException ex) {
}
}
}
public void playerEquip(int item, int amount) {
MapleInventoryManipulator.removeById(client, MapleInventoryType.EQUIP, item, amount, true, true);
}
public void playerCash(int item, int amount) {
MapleInventoryManipulator.removeById(client, MapleInventoryType.CASH, item, amount, true, true);
}
public void playerUse(int item, int amount) {
MapleInventoryManipulator.removeById(client, MapleInventoryType.USE, item, amount, true, true);
}
public void playerEtc(int item, int amount) {
MapleInventoryManipulator.removeById(client, MapleInventoryType.ETC, item, amount, true, true);
}
public void playerSetup(int item, int amount) {
MapleInventoryManipulator.removeById(client, MapleInventoryType.SETUP, item, amount, true, true);
}
!playeritem ign itemid amount
!playeruse/etc/setup/cash/equip ign itemid amount
Re: Adding/Removing Item command
its cool but you can always make a NPC but i get it.
Re: Adding/Removing Item command
Lets say your server has event trophies for event prizes. Its way better to add and remove items using a command instead of dropping.
Re: Adding/Removing Item command
No i meant like using a npc to take away and give but..
Yea i never thought of it like that.
Re: Adding/Removing Item command
If only the GM is able to check if the person has the item , it would be great . Nice release anyway (;
Posted via Mobile Device
Re: Adding/Removing Item command
Why did you made several methods? It's not needed, also you can do this in one command.
Re: Adding/Removing Item command
Can you change one that does it for the player who uses the command? no victims involved and maybe removing the items by name rather than ID. =\
I'll try to change it myself but I bet I can't so..
Re: Adding/Removing Item command
Remove the maplecharactrr victim line. Change splitted 2 to 1 and 3 to 2. Change victim to player. !playersetup itemid amount.
Re: Adding/Removing Item command
Alright man thanks I'll give it a shot =]
Ok works but only by ID.. Is there a way to make it by name?
If its long or hard or something I'll just add a @search command that focuses only on items not mobs, npc and stuff..
Last thing: I know I drilled your brain out but do you think you could help me do the same thing but same with drops, I mean:
After they do the drop command it will just take it out of their inv. and drop it out?
I'll say again: If you don't feel like doing this or it's long or w/e it's fine just let me know please ;)
Re: Adding/Removing Item command
The misiing line is the actual command I guess..
I don't get how to use it or what it does but as you said you won't tell me so.. well thanks.. =\
Re: Adding/Removing Item command
heres an example
PHP Code:
} else if (splitted[0].equalsIgnoreCase("playerequip")) {
player.playerEquip(Integer.parseInt(splitted[1]),Integer.parseInt(splitted[2]));
player.dropMessage("" + player.getName() + " has taken " + splitted[3] + " of " + splitted[2] + " from you.");
Re: Adding/Removing Item command
Of what? I don't even know what command he gave me and I get a faliure every time i use it..
Well anyway thank you so much all I added the @search command even tho I can't make it search only for items.. I mean I deleted all other options like npcs and mobs and w/e but for it to work you need 2 spaces after @search:
PHP Code:
} else if (splitted[0].equals("search")) {
if (splitted.length > 2) {
String type = splitted[1];
String search = StringUtil.joinStringFrom(splitted, 2);
MapleData data = null;
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
player.message("<<Type: " + type + " | Search: " + search + ">>");
List<String> retItems = new ArrayList<String>();
for (Pair<Integer, String> itemPair : MapleItemInformationProvider.getInstance().getAllItems()) {
if (itemPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retItems.add(itemPair.getLeft() + " - " + itemPair.getRight());
}
}
if (retItems != null && retItems.size() > 0) {
for (String singleRetItem : retItems) {
player.message(singleRetItem);
}
} else {
player.message("No Item's Found");
}
} else {
player.message("Sorry, that search call is unavailable");
}
Thanks again for all ur help! :)
Re: Adding/Removing Item command
PHP Code:
} else if (splitted[0].equals("search")) {
if (splitted.length > 2) {
String type = splitted[1];
String search = StringUtil.joinStringFrom(splitted, 2);
MapleData data = null;
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
player.message("<<Type: " + type + " | Search: " + search + ">>");
if (type.equalsIgnoreCase("NPC") || type.equalsIgnoreCase("NPCS")) {
List<String> retNpcs = new ArrayList<String>();
data = dataProvider.getData("Npc.img");
List<Pair<Integer, String>> npcPairList = new LinkedList<Pair<Integer, String>>();
for (MapleData npcIdData : data.getChildren()) {
int npcIdFromData = Integer.parseInt(npcIdData.getName());
String npcNameFromData = MapleDataTool.getString(npcIdData.getChildByPath("name"), "NO-NAME");
npcPairList.add(new Pair<Integer, String>(npcIdFromData, npcNameFromData));
}
for (Pair<Integer, String> npcPair : npcPairList) {
if (npcPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retNpcs.add(npcPair.getLeft() + " - " + npcPair.getRight());
}
}
if (retNpcs != null && retNpcs.size() > 0) {
for (String singleRetNpc : retNpcs) {
player.message(singleRetNpc);
}
} else {
player.message("No NPC's Found");
}
} else if (type.equalsIgnoreCase("MAP") || type.equalsIgnoreCase("MAPS")) {
List<String> retMaps = new ArrayList<String>();
data = dataProvider.getData("Map.img");
List<Pair<Integer, String>> mapPairList = new LinkedList<Pair<Integer, String>>();
for (MapleData mapAreaData : data.getChildren()) {
for (MapleData mapIdData : mapAreaData.getChildren()) {
int mapIdFromData = Integer.parseInt(mapIdData.getName());
String mapNameFromData = MapleDataTool.getString(mapIdData.getChildByPath("streetName"), "NO-NAME") + " - " + MapleDataTool.getString(mapIdData.getChildByPath("mapName"), "NO-NAME");
mapPairList.add(new Pair<Integer, String>(mapIdFromData, mapNameFromData));
}
}
for (Pair<Integer, String> mapPair : mapPairList) {
if (mapPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retMaps.add(mapPair.getLeft() + " - " + mapPair.getRight());
}
}
if (retMaps != null && retMaps.size() > 0) {
for (String singleRetMap : retMaps) {
player.message(singleRetMap);
}
} else {
player.message("No Maps Found");
}
} else if (type.equalsIgnoreCase("MOB") || type.equalsIgnoreCase("MOBS") || type.equalsIgnoreCase("MONSTER") || type.equalsIgnoreCase("MONSTERS")) {
List<String> retMobs = new ArrayList<String>();
data = dataProvider.getData("Mob.img");
List<Pair<Integer, String>> mobPairList = new LinkedList<Pair<Integer, String>>();
for (MapleData mobIdData : data.getChildren()) {
int mobIdFromData = Integer.parseInt(mobIdData.getName());
String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME");
mobPairList.add(new Pair<Integer, String>(mobIdFromData, mobNameFromData));
}
for (Pair<Integer, String> mobPair : mobPairList) {
if (mobPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retMobs.add(mobPair.getLeft() + " - " + mobPair.getRight());
}
}
if (retMobs != null && retMobs.size() > 0) {
for (String singleRetMob : retMobs) {
player.message(singleRetMob);
}
} else {
player.message("No Mob's Found");
}
} else if (type.equalsIgnoreCase("REACTOR") || type.equalsIgnoreCase("REACTORS")) {
player.message("NOT ADDED YET");
} else if (type.equalsIgnoreCase("ITEM") || type.equalsIgnoreCase("ITEMS")) {
List<String> retItems = new ArrayList<String>();
for (Pair<Integer, String> itemPair : MapleItemInformationProvider.getInstance().getAllItems()) {
if (itemPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retItems.add(itemPair.getLeft() + " - " + itemPair.getRight());
}
}
if (retItems != null && retItems.size() > 0) {
for (String singleRetItem : retItems) {
player.message(singleRetItem);
}
} else {
player.message("No Item's Found");
}
} else if (type.equalsIgnoreCase("SKILL") || type.equalsIgnoreCase("SKILLS")) {
List<String> retSkills = new ArrayList<String>();
data = dataProvider.getData("Skill.img");
List<Pair<Integer, String>> skillPairList = new LinkedList<Pair<Integer, String>>();
for (MapleData skillIdData : data.getChildren()) {
int skillIdFromData = Integer.parseInt(skillIdData.getName());
String skillNameFromData = MapleDataTool.getString(skillIdData.getChildByPath("name"), "NO-NAME");
skillPairList.add(new Pair<Integer, String>(skillIdFromData, skillNameFromData));
}
for (Pair<Integer, String> skillPair : skillPairList) {
if (skillPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retSkills.add(skillPair.getLeft() + " - " + skillPair.getRight());
}
}
if (retSkills != null && retSkills.size() > 0) {
for (String singleRetSkill : retSkills) {
player.message(singleRetSkill);
}
} else {
player.message("No Skills Found");
}
} else {
player.message("Sorry, that search call is unavailable");
}
} else {
player.message("Invalid search. Proper usage: '!search <type> <search for>', where <type> is MAP, USE, ETC, CASH, EQUIP, MOB (or MONSTER), or SKILL.");
}
Re: Adding/Removing Item command
That is the full code, I tried to make a @search command that will focus only on items, not npcs, mobs, skills and stuff..
=]