Adding expiration date to SQL database?

Results 1 to 4 of 4
  1. #1
    Enthusiast istreety is offline
    MemberRank
    Jun 2014 Join Date
    29Posts

    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(citemIdquantityplayer.getName(), petid, -1);
                     break;
                            } 
    I know it looks disgustingly messy (i'll try and clean it up)
    Last edited by istreety; 07-03-18 at 03:05 AM.


  2. #2
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    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(citem, (short1""expiry);
                } else if (!
    ii.itemExists(item)) {
                    
    c.getPlayer().dropMessage(5item " does not exist.");
                } else {
                    
    MapleInventoryManipulator.addById(citem, (short1expiry);
                } 

  3. #3
    Enthusiast istreety is offline
    MemberRank
    Jun 2014 Join Date
    29Posts

    Re: Adding expiration date to SQL database?

    Quote Originally Posted by TacoBell View Post
    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(citem, (short1""expiry);
                } else if (!
    ii.itemExists(item)) {
                    
    c.getPlayer().dropMessage(5item " does not exist.");
                } else {
                    
    MapleInventoryManipulator.addById(citem, (short1expiry);
                } 
    You're a life saver
    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(citemIdquantityplayer.getName(), petidexpiration);
                                            break;
                                    } else {
                                            
    player.yellowMessage("Pet Syntax: !item <itemid> <expiration>");
                                            break;        
                                    }
                            } 
    Thank you!!

  4. #4
    I'm overrated. Fraysa is offline
    MemberRank
    Apr 2008 Join Date
    4,891Posts

    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.



Advertisement