• 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.

Guild Points aren't updating

Elite Diviner
Joined
Aug 29, 2011
Messages
404
Reaction score
8
have you tried setting the last part of the function to gaingp()) + 5); as well?
Might be dumb but im still learning as well.
 
Upvote 0
That one pokemon thing
Loyal Member
Joined
Apr 3, 2010
Messages
1,766
Reaction score
621
If I do this, then it will set the 'gp' value in the guilds table to whatever number I set it to (in this case, +5). What that piece of code should be doing is getting the current amount of GP, and then adding 5 to that.
So if I had 3 points before I clicked the npc, I would have 8 after clicking it. But at the moment, I have 5 after clicking the npc.

Even though I assume you already did this. Check the getGP method. It could be coded as a set instead of a get.
 
Upvote 0
Junior Spellweaver
Joined
Oct 6, 2009
Messages
150
Reaction score
35
Alright, so let me get this straight: You open the npc, but instead of setting your GP to (current GP + 5), it just sets it to 5?

Alright, this is definitely a problem with your getGP method. Even though what you posted should be correct, there's obviously a problem with the gp int because it's always returning zero. Take a look around, make sure GP gets committed to the database, and while you're at it, could you post your gainGP method, and say what source you use? That could be helpful.
 
Upvote 0
Junior Spellweaver
Joined
Oct 6, 2009
Messages
150
Reaction score
35
I believe it's MapleBlade based.
Here are my methods in MapleCharacter.java (also found setGP, which doesn't seem to work either...):
PHP:
    public void setGP(int amount) {
        gp = gp + amount;
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = null;
        try {
            ps = con.prepareStatement("UPDATE guilds SET `GP` = ? WHERE guildid = ?");
            ps.setInt(1, gp);
            ps.setInt(2, guildid);
            ps.executeUpdate();
        } catch (SQLException e) {
        } finally {
            try {
                if (ps != null && !ps.isClosed()) {
                    ps.close();
                }
            } catch (SQLException e) {
            }
        }
    }

    public int getGP() {
        return gp;
    }

    public void gainGP(int amount) {
        this.gp += amount;
    }

Well, for one, your setGP() method is coded to do the same thing as a gain method, and your GainGP method doesn't commit to the database. Does your MapleGuild.java have a WriteToDB method in it? If it does, I recommend you use that in your gain method you use that. Here's what I have (Credit to kevintjuh for MoopleDev being awesome):

PHP:
    public void gainGP(int amount) {
        this.gp += amount;
        this.writeToDB(false);
        this.guildMessage(MaplePacketCreator.updateGP(this.id, this.gp));
    }

Also, be sure the change your setGP method so instead of doing gp = gp + amount, it's just gp = amount, like a proper set function.


And here's the WriteToDB method if you want it (Again, credit to Kevintjuh for making this, and making it awesome):

PHP:
    public void writeToDB(boolean bDisband) {
        try {
            Connection con = DatabaseConnection.getConnection();
            if (!bDisband) {
                StringBuilder builder = new StringBuilder();
                builder.append("UPDATE guilds SET GP = ?, logo = ?, logoColor = ?, logoBG = ?, logoBGColor = ?, ");
                for (int i = 0; i < 5; i++) {
                    builder.append("rank").append(i + 1).append("title = ?, ");
                }
                builder.append("capacity = ?, notice = ? WHERE guildid = ?");
                try (PreparedStatement ps = con.prepareStatement(builder.toString())) {
                    ps.setInt(1, gp);
                    ps.setInt(2, logo);
                    ps.setInt(3, logoColor);
                    ps.setInt(4, logoBG);
                    ps.setInt(5, logoBGColor);
                    for (int i = 6; i < 11; i++) {
                        ps.setString(i, rankTitles[i - 6]);
                    }
                    ps.setInt(11, capacity);
                    ps.setString(12, notice);
                    ps.setInt(13, this.id);
                    ps.execute();
                }
            } else {
                PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = 0, guildrank = 5 WHERE guildid = ?");
                ps.setInt(1, this.id);
                ps.execute();
                ps.close();
                ps = con.prepareStatement("DELETE FROM guilds WHERE guildid = ?");
                ps.setInt(1, this.id);
                ps.execute();
                ps.close();
                this.broadcast(MaplePacketCreator.guildDisband(this.id));
            }
        } catch (SQLException se) {
        }
    }


As a final note, I'm not sure if ps.executeUpdate() does anything differently from ps.execute(), but I've never seen it used before.
 
Upvote 0
Back
Top