[Release] Character Limit ( Using NX )

Junior Spellweaver
Joined
Jan 21, 2009
Messages
162
Reaction score
1
MapleClient.javur
Code:
public static int countCharacters(int aid) {
        Connection con = DatabaseConnection.getConnection();
        int ret = 0;
        try {
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE accountid = ?");
            ps.setInt(1, aid);
            ResultSet rs = ps.executeQuery();
            rs.last(); // Last Row now
            ret = rs.getRow(); // ID of last row = amount of rows.
            ps.close();
        } catch(SQLException sqle) {}
        return ret;
    }

MapleCharacter.javur
Code:
public static void increaseCharacterLimit(int aid, int inc) {
        Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET charlimit = charlimit + ? WHERE id = ?");
            ps.setInt(1, inc);
            ps.setInt(2, aid);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException s) {}
    }

    public static int getCharacterLimit(int aid, boolean SQL) {
        int ret = 0;
        if (SQL) {
            Connection con = DatabaseConnection.getConnection();
            try {
                PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
                ps.setInt(1, aid);
                ResultSet rs = ps.executeQuery();
                ret = rs.getInt("charlimit");
                ps.close();
            } catch (SQLException sqle) {}
        } else {
            // TODO Make a List.
        }
        if (ret > 6)
            return 6; // 6 is max.
        return ret;
    }

CreateCharHandler.javur
Code:
        if (MapleCharacter.getCharacterLimit(c.getAccID(), true) <= c.countCharacters(c.getAccID())) {
            charok = false;
        }

UseCashItemHandler.javur
Code:
            else if (itemType == 543) {
                c.getPlayer().increaseCharacterLimit(c.getAccID(), 1);
                MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5430000, 1, true, false);
            }

Make an SQL Query to add the field "charlimit" to `accounts`
 
Code:
else if (action == 8) { //Buy Extra Character Slot Coupon
            slea.skip(1);
            int useNX = slea.readInt();
            int snCS = slea.readInt();
            CashItemInfo item = CashItemFactory.getItem(snCS);
            if (c.getPlayer().getCSPoints(useNX) >= item.getPrice()) {
                c.getPlayer().modifyCSPoints(useNX, -item.getPrice());
            } else {
                c.getSession().write(MaplePacketCreator.enableActions());
                return;
            }
            MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
            c.getSession().write(MaplePacketCreator.showBoughtCSItem(item.getId()));
            c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.enableCSUse0());
            c.getSession().write(MaplePacketCreator.enableCSUse1(c));
            c.getSession().write(MaplePacketCreator.enableCSUse2());
            c.getSession().write(MaplePacketCreator.enableActions());
        }
 
Last edited:
I don't know how you increase your slots in GMS but it's not working by double clicking and it also sends no packet if you double click it. I guess you will have to go to a NPC with the ticket?

Here's my solution:
BuyCSItemHandler.java
Code:
 else if (action == 8) { //Buy Extra Character Slot Coupon?
            slea.skip(1);
            int useNX = slea.readInt();
            int snCS = slea.readInt();
            CashItemInfo item = CashItemFactory.getItem(snCS);
            if (c.getPlayer().getCSPoints(useNX) >= item.getPrice()) {
                if (c.getCSlots() < 6) {
                    c.getPlayer().modifyCSPoints(useNX, -item.getPrice());
                    c.gainCSlot();
                    c.getPlayer().dropMessage(1, "Your character slots have been increased to " + c.getCSlots() + ".");
                } else {
                    c.getPlayer().dropMessage(1, "You can not have more than 6 character slots.");
                }
            } else {
                c.getSession().write(MaplePacketCreator.enableActions());
                return;
            }
            //MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
            c.getSession().write(MaplePacketCreator.showBoughtCSItem(item.getId()));
            c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.enableCSUse0());
            c.getSession().write(MaplePacketCreator.enableCSUse1(c));
            c.getSession().write(MaplePacketCreator.enableCSUse2());
            c.getSession().write(MaplePacketCreator.enableActions());
        }
MapleClient.java
Code:
private int charslots = 3;
Code:
public int getCSlots() {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM character_slots WHERE accid = ?");
            ps.setInt(1, accId);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                charslots = rs.getInt("charslots");
                rs.close();
            } else {
                ps = con.prepareStatement("INSERT INTO character_slots (accid, worldid, charslots) VALUES (?, ?, ?)");
                ps.setInt(1, accId);
                ps.setInt(2, world);
                ps.setInt(3, charslots);
                ps.execute();
            }
            ps.close();
        } catch (SQLException sqlE) {
            System.out.print("Could not load Character Slots : " + sqlE);
        }

        return charslots;
    }

    public void gainCSlot() {
        charslots += 1;

        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE character_slots SET charslots = ? WHERE worldid = ? AND accid = ?");
            ps.setInt(1, charslots);
            ps.setInt(2, world);
            ps.setInt(3, accId);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException sqlE) {
            System.out.print("Could not save Character Slots : " + sqlE);
        }
    }
SQL
Code:
--
-- Definition of table `character_slots`
--

DROP TABLE IF EXISTS `character_slots`;
CREATE TABLE `character_slots` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `accid` int(11) NOT NULL DEFAULT '0',
  `worldid` int(11) NOT NULL DEFAULT '0',
  `charslots` int(11) NOT NULL DEFAULT '3',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `character_slots`
--

/*!40000 ALTER TABLE `character_slots` DISABLE KEYS */;
/*!40000 ALTER TABLE `character_slots` ENABLE KEYS */;

This is world based like it is in GMS as far as I know.
 
Last edited:
The problem was I didn't know how the purchase works.
To fix it(For mine) is to change the code you put, and replace MapleInventoryManipulator w/ c.getPlayer().ncreaseCharacterLimit(c.getAccID(), 1) {
 
I don't know how you increase your slots in GMS with this but it's not working by double clicking and it also sends now packet if you double click it. I guess you will have to go to a NPC with the ticket?

Here's my solution:
BuyCSItemHandler.java
Code:
 else if (action == 8) { //Buy Extra Character Slot Coupon?
            slea.skip(1);
            int useNX = slea.readInt();
            int snCS = slea.readInt();
            CashItemInfo item = CashItemFactory.getItem(snCS);
            if (c.getPlayer().getCSPoints(useNX) >= item.getPrice()) {
                if (c.getCSlots() < 6) {
                    c.getPlayer().modifyCSPoints(useNX, -item.getPrice());
                    c.gainCSlot();
                    c.getPlayer().dropMessage(1, "Your character slots have been increased to " + c.getCSlots() + ".");
                } else {
                    c.getPlayer().dropMessage(1, "You can not have more than 6 character slots.");
                }
            } else {
                c.getSession().write(MaplePacketCreator.enableActions());
                return;
            }
            //MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
            c.getSession().write(MaplePacketCreator.showBoughtCSItem(item.getId()));
            c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.enableCSUse0());
            c.getSession().write(MaplePacketCreator.enableCSUse1(c));
            c.getSession().write(MaplePacketCreator.enableCSUse2());
            c.getSession().write(MaplePacketCreator.enableActions());
        }
MapleClient.java
Code:
private int charslots = 3;
Code:
public int getCSlots() {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM character_slots WHERE accid = ?");
            ps.setInt(1, accId);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                charslots = rs.getInt("charslots");
                rs.close();
            } else {
                ps = con.prepareStatement("INSERT INTO character_slots (accid, worldid, charslots) VALUES (?, ?, ?)");
                ps.setInt(1, accId);
                ps.setInt(2, world);
                ps.setInt(3, charslots);
                ps.execute();
            }
            ps.close();
        } catch (SQLException sqlE) {
            System.out.print("Could not load Character Slots : " + sqlE);
        }

        return charslots;
    }

    public void gainCSlot() {
        charslots += 1;

        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE character_slots SET charslots = ? WHERE worldid = ? AND accid = ?");
            ps.setInt(1, charslots);
            ps.setInt(2, world);
            ps.setInt(3, accId);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException sqlE) {
            System.out.print("Could not save Character Slots : " + sqlE);
        }
    }
SQL
Code:
--
-- Definition of table `character_slots`
--

DROP TABLE IF EXISTS `character_slots`;
CREATE TABLE `character_slots` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `accid` int(11) NOT NULL DEFAULT '0',
  `worldid` int(11) NOT NULL DEFAULT '0',
  `charslots` int(11) NOT NULL DEFAULT '3',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `character_slots`
--

/*!40000 ALTER TABLE `character_slots` DISABLE KEYS */;
/*!40000 ALTER TABLE `character_slots` ENABLE KEYS */;

This is world based like it is in GMS as far as I know.
ty! i was lookin for complete, ty
 
Back