Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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