[Add-On] Call GM Command

Newbie Spellweaver
Joined
Jun 3, 2008
Messages
84
Reaction score
13
So users in the server I program for were asking for a command to ask for help from a GM so I created this command. It will send a pop up message to all GMs that are online with what the user typed.

@callgm This is an example of how to use the command.

EDIT minimumTimeToWait to the time you want players to wait before sending another help message (In minutes!)

Add the following into Commands.java in the player commands method.
PHP:
else if (sub[0].equals("callgm")) {
            int minimumTimeToWait = 10;
            try{
                PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("Select * from characters where name = ?");
                ps.setString(1, chr.getName());
                ResultSet rs = ps.executeQuery();
                if(!rs.next()){
                    rs.close();
                    ps.close();
                } else {
                    long ts2 = rs.getLong("gmCallTime");
                    long ts1 = System.currentTimeMillis();
                    int timeDif = (int)(ts1-ts2)/60000;
                    if(timeDif >= minimumTimeToWait || timeDif < 0){
                        c.getChannelServer().broadcastGMPacket(MaplePacketCreator.serverNotice(1, chr.getName()+": " + StringUtil.joinStringFrom(sub, 1)));
                        ps = DatabaseConnection.getConnection().prepareStatement("update characters set gmCallTime = ? where name = ?");
                        ps.setLong(1, ts1);
                        ps.setString(2, chr.getName());
                        ps.executeUpdate();
                    } else {
                        c.announce(MaplePacketCreator.serverNotice(1, "You cannot call a GM for " + (minimumTimeToWait-timeDif) + " more minutes."));
                    }
                    rs.close();
                    ps.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
You also have to run this in mysql
PHP:
ALTER TABLE `moopledev`.`characters` ADD COLUMN `gmCallTime` BIGINT NOT NULL DEFAULT '0'

I understand that oh, there's a report button but that's for reporting someone so yeah. I've made it so you can only call a GM every hour.

RpViet - [Add-On] Call GM Command - RaGEZONE Forums

RpViet - [Add-On] Call GM Command - RaGEZONE Forums


Also, sorry if this command was created before delete this thread if there is one :)
 
Last edited:
Its good but its better not have it has a pop up message but rather to have
it as a message in the actual chat area.
 
Its good but its better not have it has a pop up message but rather to have
it as a message in the actual chat area.

Up to server admin preference. Also, if it's in chat you might just ignore it and think it's just a GM or Something. It's easier to notice something when it's right in your face than hidden in a corner, or a chatbox in this case.
 
This is just a longer way of @gm, Theres a simpler one released that does not use SQL. Nice job though

IMO, SQL is much better because it allows GMs to see if reports are actually being taken care of since you can compare the reports to accounts banned and see if they are legitimate.

@TS: You should also add a feature that numbers the reports, and then an ability for GMs to "close" reports with a command or something that saves to SQL.
 
@TS: You should also add a feature that numbers the reports, and then an ability for GMs to "close" reports with a command or something that saves to SQL.

I see what you mean, maybe I'll work on this command a little bit farther to make it save the help requests from users. Then if the GM wants, he can do for example

!showallrequests

and it'll show a list of every request
and then for players they'll have

@closehelp

so that it'll close the current problem they have :O sounds interesting! but it is currently 3 AM and I must sleep. I will work on improving this command when i have time.
 
I see what you mean, maybe I'll work on this command a little bit farther to make it save the help requests from users. Then if the GM wants, he can do for example

!showallrequests

and it'll show a list of every request
and then for players they'll have

@closehelp

so that it'll close the current problem they have :O sounds interesting! but it is currently 3 AM and I must sleep. I will work on improving this command when i have time.

Yea, like !listreports, and it'll list the first 20 that are open. Then !closereport <report #> to close it. That way the Admins have something to see as proof of GMs doing their job.
 
For now edited the command so that you can edit the value minimumTimeToWait to change the minimum time for users to wait to use the command. Also changed the code very slightly to make it less buggy.
 
The other release was more efficient.
This one runs a SQL query the second the command is typed, regardless of whether the player can actually use it or not. This can create unnecessary stress on the MySQL server when spammed by even a small number of people.

If they can use it, it goes on to run another query and create objects to compare the time difference - something obsolete if you're simply trying to compare time. Timestamp was a poor datatype choice for this; you could just use a medium/bigint datatype and save the currentTimeMillis() and compare numerical values instead of creating new objects. But, if you really want to know the exact time when someone used the command, it accomplishes the purpose (though it doesn't give optimum performance).

Well, I'm not necessarily saying that this release is bad because generally when more features are added, there is a trade-off for performance, but it can definitely be improved.
 
The other release was more efficient.
This one runs a SQL query the second the command is typed, regardless of whether the player can actually use it or not. This can create unnecessary stress on the MySQL server when spammed by even a small number of people.
Well the time is stored on the database so how else can I check if they use it or not?
If they can use it, it goes on to run another query and create objects to compare the time difference - something obsolete if you're simply trying to compare time. Timestamp was a poor datatype choice for this; you could just use a medium/bigint datatype and save the currentTimeMillis() and compare numerical values instead of creating new objects. But, if you really want to know the exact time when someone used the command, it accomplishes the purpose (though it doesn't give optimum performance).

I was actually going to change it to use currentTimeMillis like you said and use bigint but I figured some people already took what I had and I didn't want to change it for them :(

PHP:
else if (sub[0].equals("callgm")) {
            int minimumTimeToWait = 10;
            try{
                PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("Select * from characters where name = ?");
                ps.setString(1, chr.getName());
                ResultSet rs = ps.executeQuery();
                if(!rs.next()){
                    rs.close();
                    ps.close();
                } else {
                    long ts2 = rs.getLong("gmCallTime");
                    long ts1 = System.currentTimeMillis();
                    int timeDif = (int)(ts1-ts2)/60000;
                    if(timeDif >= minimumTimeToWait || timeDif < 0){
                        c.getChannelServer().broadcastGMPacket(MaplePacketCreator.serverNotice(1, chr.getName()+": " + StringUtil.joinStringFrom(sub, 1)));
                        ps = DatabaseConnection.getConnection().prepareStatement("update characters set gmCallTime = ? where name = ?");
                        ps.setLong(1, ts1);
                        ps.setString(2, chr.getName());
                        ps.executeUpdate();
                    } else {
                        c.announce(MaplePacketCreator.serverNotice(1, "You cannot call a GM for " + (minimumTimeToWait-timeDif) + " more minutes."));
                    }
                    rs.close();
                    ps.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

PHP:
ALTER TABLE `moopledev`.`characters` ADD COLUMN `gmCallTime` BIGINT NOT NULL DEFAULT '0'
 
Last edited:
Back