- Joined
- Apr 9, 2012
- Messages
- 117
- Reaction score
- 28
Information
• Tested on Helisium Development v117.
This system is built in order to function has a public chat.
When you will talk with the NPC, you will have several options depending on your GM level:
• The only thing that normal players have to do is enter the chat and write message in it.
• Admin/GM's have some more options like: Delete a message, Change a message, Clean the chat, Mute a player, UnMute a player.
In short, the goal of this system is global chat within players could talk with each other from every where and ask questions, sell stuff, search for PQ members and more.
Extra Features:
• The chat will be cleaned once per 12 hours in order to keep the chat clean and organized.
• When a player send a message on the public chat, all the players that are playing will receive a small message that informs them about the message that were sent in the public chat (for players who doesn't want to get the message, they can turn it on/off with a command).
• Every player has a different chat color (like on whatsapp). When the character is created he receive a random color that will be his color for ever.
• Admin/GM's can ban/unban players from using the chat (If they curse or spam or whatever).
Add-On
MapleCharacter.java:
PHP:
public String getPepeChat() throws SQLException {
StringBuilder angrypepe = new StringBuilder();
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("SELECT chatid, name, message, time FROM pepechat ORDER BY time");
ResultSet angry = pepe.executeQuery();
try {
while (angry.next()) {
angrypepe.append(getColor(angry.getString("name"))).append(angry.getInt("chatid")).append(".").append(angry.getString("name")).append("(").append(angry.getString("time")).append(")").append(":").append(angry.getString("message")).append("\r\n");
}
} catch (SQLException ex) {
Logger.getLogger(NPCConversationManager.class.getName()).log(Level.SEVERE, null, ex);
}
pepe.close();
angry.close();
return angrypepe.toString();
}
public void deletePepeChat(int chatid) throws SQLException {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("DELETE FROM pepechat WHERE chatid = ?");
pepe.setInt(1, chatid);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR deleting pepechat"+pepe);
}
}
public void cleanPepeChat() throws SQLException {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("DELETE FROM pepechat");
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR deleting pepechat"+pepe);
}
}
public void changePepeChat(int chatid, String message) throws SQLException {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("UPDATE pepechat SET message = ? WHERE chatid = ?");
pepe.setString(1, message);
pepe.setInt(2, chatid);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR change message"+pepe);
}
}
public void writePepeChat(String message) throws SQLException {
globalPepeChat(client.getPlayer().getName());
String time = Calendar.HOUR +":"+ Calendar.MINUTE;
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pepechat (name, message, time) VALUES (?,?,?)");
pepe.setString(1, client.getPlayer().getName());
pepe.setString(2, message);
pepe.setString(3, time);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR writing pepechat"+pepe);
}
}
public String getColor(String name) throws SQLException {
String color = "";
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("SELECT pepecolor FROM characters WHERE name = ?");
pepe.setString(1, name);
ResultSet angry = pepe.executeQuery();
if (angry.next()) {
color = angry.getString("pepecolor");
}
pepe.close();
angry.close();
} catch (SQLException ex) {
Logger.getLogger(NPCConversationManager.class.getName()).log(Level.SEVERE, null, ex);
}
return color;
}
public static String changeColor() {
char pepecolor = 'n';
String pepecolor2;
int rand = (int) (Math.floor(Math.random()*6)+1);
switch (rand) {
case 1: pepecolor = 'b'; break;
case 2: pepecolor = 'r'; break;
case 3: pepecolor = 'd'; break;
case 4: pepecolor = 'g'; break;
case 5: pepecolor = 'k'; break;
case 6: pepecolor = 'e'; break;
case 7: pepecolor = 'n'; break;
}
pepecolor2 = "#"+pepecolor;
return pepecolor2;
}
public void globalPepeChat(String name) {
ChannelServer cserv = getClient().getChannelServer();
for (MapleCharacter pepe : cserv.getPlayerStorage().getAllCharacters()) {
if(pepe.isPepeChat()) {
pepe.dropMessage(5, name + " has sent a message on the public chat");
}
}
}
public boolean isPepeChat() {
boolean angrypepe = true;
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("SELECT pepeChatON FROM characters WHERE name = ?");
pepe.setString(1, getName());
ResultSet angry = pepe.executeQuery();
if (angry.next()) {
angrypepe = angry.getBoolean("pepeChatON");
}
pepe.close();
angry.close();
} catch (SQLException e) {
dropMessage(0, "Failed to execute SQL command.");
}
return angrypepe;
}
public boolean isPepeMute() {
boolean angrypepe = true;
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("SELECT canUsePepeChat FROM characters WHERE name = ?");
pepe.setString(1, getName());
ResultSet angry = pepe.executeQuery();
if (angry.next()) {
angrypepe = angry.getBoolean("canUsePepeChat");
}
pepe.close();
angry.close();
} catch (SQLException e) {
dropMessage(0, "Failed to execute SQL command.");
}
return angrypepe;
}
public void mutePepeChat(String name) {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET canUsePepeChat = ? WHERE name = ?");
pepe.setBoolean(1, false);
pepe.setString(2, name);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR change message"+pepe);
}
}
public void unMutePepeChat(String name) {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET canUsePepeChat = ? WHERE name = ?");
pepe.setBoolean(1, true);
pepe.setString(2, name);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR change message"+pepe);
}
}
Method saveNewCharToDB (it's in MapleCharacter.java):
Search for:
PHP:
subcategory,
Add after it:
PHP:
pepecolor,
Afterwards, search for:
PHP:
ps.setInt(24, chr.getAccountID());
ps.setString(25, chr.name);
ps.setByte(26, chr.world);
Change it to:
PHP:
ps.setString(24, changeColor());
ps.setInt(25, chr.getAccountID());
ps.setString(26, chr.name);
ps.setByte(27, chr.world);
ChannelServer.java:
PHP:
public void cleanAll() throws SQLException {
for (MapleCharacter chr : players.getAllCharacters()) {
chr.cleanPepeChat();
break;
}
}
PlayerCommand.java:
Don't forget to change XXX to the ID of the NPC!
PHP:
public static class PepeChat extends CommandExecute {
@Override
public int execute(MapleClient c, String[] splitted) {
NPCScriptManager.getInstance().start(c, XXX, null);
return 1;
}
}
PHP:
public static class ChatStatus extends CommandExecute {
@Override
public int execute(MapleClient c, String[] splitted) {
if(c.getPlayer().isPepeChat()) {
try {
java.sql.PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET pepeChatON = ? WHERE name = ?");
pepe.setBoolean(1, false);
pepe.setString(2, c.getPlayer().getName());
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR chane status"+pepe);
}
} else {
try {
java.sql.PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET pepeChatON = ? WHERE name = ?");
pepe.setBoolean(1, true);
pepe.setString(2, c.getPlayer().getName());
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR chane status"+pepe);
}
}
return 1;
}
}
SQL:
PHP:
DROP TABLE IF EXISTS `pepechat`;
CREATE TABLE `pepechat` (
`chatid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`message` varchar(100) NOT NULL,
`time` varchar(5) NOT NULL,
PRIMARY KEY (`chatid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
PHP:
ALTER TABLE `characters` ADD COLUMN `pepecolor` NOT NULL DEFAULT '#n';
ALTER TABLE `characters` ADD COLUMN `pepeChatON` boolean NOT NULL DEFAULT true;
ALTER TABLE `characters` ADD COLUMN `canUsePepeChat` boolean NOT NULL DEFAULT true;
AutoPepe.js:
Make a file called AutoPepe.js put it on scripts\event. Afterwards put this code in it:
PHP:
var setupTask;
function init() {
scheduleNew();
}
function scheduleNew() {
var cal = java.util.Calendar.getInstance();
cal.set(java.util.Calendar.HOUR, 12);
cal.set(java.util.Calendar.MINUTE, 0);
cal.set(java.util.Calendar.SECOND, 0);
var nextTime = cal.getTimeInMillis();
while (nextTime <= java.lang.System.currentTimeMillis())
nextTime += 12*60*60*1000;
setupTask = em.scheduleAtTimestamp("start", nextTime);
}
function cancelSchedule() {
setupTask.cancel(true);
}
function start() {
scheduleNew();
em.getChannelServer().cleanAll();
}
worldGMS.prop:
Search for:
PHP:
# active event scripts
net.sf.odinms.channel.events=PinkZakumEntrance,PVP,CygnusBattle,ScarTarBattle,VonLeonBattle,Ghost,OrbisPQ,Romeo,Juliet,Pirate,Amoria,Ellin,CWKPQ,DollHouse,BossBalrog_EASY,BossBalrog_NORMAL,HorntailBattle,Nibergen,PinkBeanBattle,ZakumBattle,NamelessMagicMonster,Dunas,Dunas2,2095_tokyo,ZakumPQ,LudiPQ,KerningPQ,ProtectTylus,WitchTower_EASY,WitchTower_Med,WitchTower_Hard,Vergamot,ChaosHorntail,ChaosZakum,CoreBlaze,BossQuestEASY,BossQuestMed,BossQuestHARD,BossQuestHELL,Ravana_EASY,Ravana_HARD,Ravana_MED,GuildQuest,Aufhaven,Dragonica,Rex,MonsterPark,KentaPQ
Add AutoPepe.js to the active event scripts.
NPC:
PHP:
var message;
var s;
var id;
var color;
var player;
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
} else {
if (status == 1 && mode == 0 ) {
cm.dispose();
return;
}
if (mode == 1)
status++;
else
status--;
if(cm.getPlayer().isGM()) {
if (status == 0) {
cm.sendSimple("Hello GM/Admin, What would you like to do? \r\n #L0# Enter the chat window #l \r\n #L1# Delete a message #l \r\n #L2# Change a message #l \r\n #L3# Clean the chat #l \r\n #L4# Mute a player #l \r\n #L5# UnMute a player #l");
} else if (status == 1) {
if(selection == 0) {
s = selection;
cm.sendGetText(cm.getPlayer().getPepeChat());
} else if(selection == 1) {
s = selection;
cm.sendGetText("Enter the chat ID");
} else if(selection == 2) {
s = selection;
cm.sendGetText("Enter the chat ID");
} else if(selection == 3) {
s = selection;
cm.getPlayer().cleanPepeChat();
cm.dispose();
} else if(selection == 4) {
s = selection;
cm.sendGetText("Enter player's name:");
} else if(selection == 5) {
s = selection;
cm.sendGetText("Enter player's name:");
}
} else if (status == 2) {
if(s == 0) {
message = cm.getText();
cm.getPlayer().writePepeChat(message);
cm.dispose();
} else if(s== 1) {
id = cm.getText();
cm.getPlayer().deletePepeChat(id);
cm.dispose();
} else if(s==2) {
id = cm.getText();
cm.sendGetText("Enter the new message");
} else if(s==4) {
player = cm.getText();
cm.getPlayer().mutePepeChat(player);
cm.dispose();
} else if(s==5) {
player = cm.getText();
cm.getPlayer().unMutePepeChat(player);
cm.dispose();
}
} else if (status == 3) {
message = cm.getText();
cm.getPlayer().changePepeChat(id, message);
cm.dispose();
}
} else {
if(cm.getPlayer().isPepeMute()) {
if(status ==0) {
cm.sendSimple("Hello #h #, What would you like to do? \r\n #L0# Enter the chat window #l");
} else if (status == 1) {
if(selection == 0) {
s = selection;
cm.sendGetText(cm.getPlayer().getPepeChat());
}
} else if (status == 2) {
if(s == 0) {
message = cm.getText();
cm.getPlayer().writePepeChat(message);
cm.dispose();
}
}
} else {
cm.sendOk("You are not allowed to use the chat!");
cm.dispose();
}
}
}
}
Open chat command:
PHP:
@pepechat
Receive message ON/OFF command:
PHP:
@chatstatus
Picture
Normal player window:
To view the content, you need to sign in or register
Admin/GM window:
To view the content, you need to sign in or register
Public chat window:
To view the content, you need to sign in or register
~ FLAME SHIELD ON ~


