Adding expiration date to SQL database?
I'm trying to edit my @item command to give the player a pet properly.
With this code, it successfully adds to the "pets" table and the "inventoryitems" table in my database. The problem is that I need it to also add an expiration value in the "inventoryitems" table as well. What can I add to make it do this?
Also, is there a way to make it always set the expiry date 3 months from the time it was spawned? Or even permanent?
Script:
PHP Code:
try {
quantity = Short.parseShort(sub[2]);
} catch (Exception e) {
}
if (sub[0].equals("item")) {
int petid = -1;
if (ItemConstants.isPet(itemId)) {
petid = MaplePet.createPet(itemId);
}
MapleInventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, -1);
break;
}
I know it looks disgustingly messy (i'll try and clean it up)
Re: Adding expiration date to SQL database?
You can add an expire field. You can use this command and modify it to your needs. You will have to restrict it to ONLY being able to create pets and if you want a static number of '90' days = 3 months, you will have to set that in the "long expiry" field in the command below.
PHP Code:
} else if (sub[0].equalsIgnoreCase("expiringitem")) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (sub.length < 2) {
return false;
}
int item;
long days = Integer.parseInt(sub[2]);
long expiry = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
try {
item = Integer.parseInt(sub[1]);
} catch (NumberFormatException e) {
c.getPlayer().oakMessage("Error while making item.");
e.printStackTrace();
return false;
}
if (ii.getInventoryType(item).equals(MapleInventoryType.ETC)) {
c.getPlayer().dropMessage(1, "You can't create ETCs with this command.");
return false;
}
if (ii.getInventoryType(item).equals(MapleInventoryType.EQUIP)) {
MapleInventoryManipulator.addById(c, item, (short) 1, "", expiry);
} else if (!ii.itemExists(item)) {
c.getPlayer().dropMessage(5, item + " does not exist.");
} else {
MapleInventoryManipulator.addById(c, item, (short) 1, expiry);
}
Re: Adding expiration date to SQL database?
Quote:
Originally Posted by
TacoBell
You can add an expire field. You can use this command and modify it to your needs. You will have to restrict it to ONLY being able to create pets and if you want a static number of '90' days = 3 months, you will have to set that in the "long expiry" field in the command below.
PHP Code:
} else if (sub[0].equalsIgnoreCase("expiringitem")) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (sub.length < 2) {
return false;
}
int item;
long days = Integer.parseInt(sub[2]);
long expiry = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
try {
item = Integer.parseInt(sub[1]);
} catch (NumberFormatException e) {
c.getPlayer().oakMessage("Error while making item.");
e.printStackTrace();
return false;
}
if (ii.getInventoryType(item).equals(MapleInventoryType.ETC)) {
c.getPlayer().dropMessage(1, "You can't create ETCs with this command.");
return false;
}
if (ii.getInventoryType(item).equals(MapleInventoryType.EQUIP)) {
MapleInventoryManipulator.addById(c, item, (short) 1, "", expiry);
} else if (!ii.itemExists(item)) {
c.getPlayer().dropMessage(5, item + " does not exist.");
} else {
MapleInventoryManipulator.addById(c, item, (short) 1, expiry);
}
You're a life saver :w00t:
I ended up modifying it like you said and added this to my @item command and its working perfectly.
PHP Code:
if (ItemConstants.isPet(itemId)) {
if (sub.length >=3){
quantity = 1;
long days = Integer.parseInt(sub[2]);
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
int petid = -1;
petid = Integer.parseInt(sub[1]);
petid = MaplePet.createPet(itemId);
MapleInventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration);
break;
} else {
player.yellowMessage("Pet Syntax: !item <itemid> <expiration>");
break;
}
}
Thank you!!
Re: Adding expiration date to SQL database?
I honestly don't see why you guys keep using long for timestamps, you can easily use an actual date time format and convert it to regular file time.