• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Adding expiration date to SQL database?

Newbie Spellweaver
Joined
Jun 2, 2014
Messages
29
Reaction score
2
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:
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)
 
Last edited:
Elite Diviner
Joined
Aug 29, 2011
Messages
404
Reaction score
8
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:
} 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);
            }
 
Upvote 0
Newbie Spellweaver
Joined
Jun 2, 2014
Messages
29
Reaction score
2
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:
} 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:
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!!
 
Upvote 0
Back
Top