Cheat Engine

The Underground Site of Cheat Engine


    [Release] Random Cash Code

    Share

    Admin
    Admin

    Posts : 43
    Join date : 2009-05-18

    [Release] Random Cash Code

    Post  Admin on Mon May 18, 2009 11:54 am

    This is a function to create a random Cash Code (Maple Points in this case).

    Code:
        public String createCashCode(int amount) {
            String code = "";
            String[] letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

            for (int i = 0; i < 7; i++) { //7 * 2 = 14 digit :o
                code += letters[rand(0, 25)] + rand(1, 9);
            }

            try {
                Connection con = DatabaseConnection.getConnection();
                PreparedStatement ps = con.prepareStatement("SELECT * FROM nxcode WHERE code = ?");
                ps.setString(1, code);
                ResultSet rs = ps.executeQuery();

                if (!rs.next()) {
                    ps = con.prepareStatement("INSERT INTO nxcode(code, type, item) VALUES(?, ?, ?)");
                    ps.setString(1, code);
                    ps.setInt(2, 2); //Maple Points
                    ps.setInt(3, amount);
                    ps.executeUpdate();
                    rs.close();
                    ps.close();

                    return code;
                } else {
                    rs.close();
                    ps.close();

                    return createCashCode(amount);
                }
            } catch (SQLException sqlE) {
                System.out.print(sqlE);
                return null;
            }
        }

        private int rand(int lbound, int ubound) {
            return (int) ((Math.random() * (ubound - lbound + 1)) + lbound);
        }

    And here is a command for it.
    Code:
            if (command.equalsIgnoreCase("!cashcode")) {
                if (splitted.length < 2) {
                    player.dropMessage(5, "The !cashcode command has the following syntax : !cashcode Amount");
                } else {
                    int amount = Integer.parseInt(splitted[1]);

                    if (amount < 1) {
                        player.dropMessage(5, "The amount of a Cash Code cannot be smaller than 1.");
                    } else if ((double) amount > Integer.MAX_VALUE) {
                        player.dropMessage(5, "The amount of a Cash Code cannot be bigger than " + Integer.MAX_VALUE + ".");
                    } else {
                        String code = createCashCode(amount);

                        if (code != null) {
                            player.dropMessage("You have created a Cash Code with an amount of " + amount + " : " + code + ".");
                        } else {
                            player.dropMessage(5, "An error occured while creating the Cash Code, please try again.");
                        }
                    }
                }
            }

      Current date/time is Tue Dec 11, 2018 6:15 pm