![]() |
| | #1 (permalink) |
| WZ & Java Guru Join Date: Nov 2006 Location: Keller
Posts: 639
Rep Power: 8 | [Release] buy() method Code: public void buy(int itemid, int quantity, int price)
{
long totalPrice = price * quantity;
long mesosNeeded = totalPrice - this.getMeso();
int amtOfAeros = this.getItemQuantity(4000313, false);
if(totalPrice <= Integer.MAX_VALUE){
if(this.getMeso() >= totalPrice)
{
this.gainMeso((int)-totalPrice, true);
MapleInventoryManipulator.addById(this.getClient(), itemid, (short)quantity);
}else{
mc.dropMessage("You do not have enough mesos. You need "+mesosNeeded+" more mesos.");
return;
}
}else{
int aerosNeeded = (int)(totalPrice / Integer.MAX_VALUE);
int extraMesos = (int)(totalPrice - (aerosNeeded * Integer.MAX_VALUE));
if(amtOfAeros < aerosNeeded)
{
mc.dropMessage("The total price for this purchase is above the max Meso value, We checked for Aeros to see if you could use those to pay, but you did have enough of those either.");
}else{
this.gainItem(4000313, (short)-aerosNeeded, false);
this.gainMeso(-extraMesos, true);
MapleInventoryManipulator.addById(this.getClient(), itemid, (short)quantity);
mc.dropMessage("You used "+aerosNeeded+" Aeros and "+extraMesos+" Mesos to pay for this/these item(s).");
}
}
} Golden Maple Leafs are usually worth 2 Billion mesos in most servers. (We call them Aeros in AeroStory) Command to test it- Code: else if(splitted[0].equalsIgnoreCase("!buy"))
{
if(splitted.length == 4){
int itemid = 0;
short quantity = 0;
int price = 0;
try{
itemid = Integer.parseInt(splitted[1]);
quantity = (short)(Integer.parseInt(splitted[2]));
price = Integer.parseInt(splitted[3]);
}catch(Exception e){
mc.dropMessage("Error parsing integers.");
return;
}
try{
player.buy(itemid, quantity, price);
}catch(Exception e){
mc.dropMessage("ERROR");
mc.dropMessage(""+e);
}
}else{
mc.dropMessage("<syntax> !buy <itemid> <quantity> <price>");
return;
}
} You can use this in maybe an npc script- Code: cm.getChar().buy(itemid, quantity, priceforeach); |
| | |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |