How To Add A Reputation System!
Thanks for the positive comments/feedback
Description: How to make a reputation system.
Difficulty: 2-10
Class/files modified: Client.java
Tested server: my own, 0nlyscape.no-ip.org / 317 server. (silab)
*PROCEDURE*
add this command and declear some ints.
command first:
Code:
if (command.startsWith("rep")) {
String nam = command.substring(4);
client is = (client) PlayerHandler.players[PlayerHandler.getPlayerID(nam)];
String connect = is.connectedFrom;
if (connectedFrom.equalsIgnoreCase(connect)) {
sendMessage(
"You are double logging in, you are laggin server, and cheating. -5 rep.");
reputation -= 5;
} else if (Reptimer >= 1) {
sendMessage(
"You have already gaven a rep point please wait 1 hour");
} else if (Reptimer == 0 && reputation >= 1
|| playerRights >= 2 && Reptimer == 0) {
sendMessage("You just gave " + nam + ", a reputation point.");
is.reputation += 1;
is.sendMessage("You recieved rep from " + playerName);
Reptimer = 3600;
}
BufferedWriter bw = null;
try {
String name = command.substring(4);
client c = (client) PlayerHandler.players[PlayerHandler.getPlayerID(name)];
bw = new BufferedWriter(new FileWriter("logs/repLogs.txt", true));
bw.write(
"[---" + name + " was given rep by " + playerName
+ "---]");
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException ioe2) {
sendMessage("Error reporting user.");
}
}
}
}
and declear this:
Code:
public int reputation = 0;
and the timer:
Code:
public int Reptimer = 0;
then search for this:
Code:
case 1:
if (token.equals("character-fighttype")) {
FightType = Integer.parseInt(token2);
and add this below any of em:
Code:
} else if (token.equals("character-reputation")) {
reputation = Integer.parseInt(token2);
And search for this:
Code:
characterfile.newLine();
And add this below any of em:
Code:
characterfile.newLine();
characterfile.write("character-reputation = ", 0, 23);
characterfile.write(Integer.toString(reputation), 0,
Integer.toString(reputation).length());
+ rep is apriciated also :)
send back errors, and other stuff and tell me if it worked or didnt. and if you did something wrong ill help you! :) have fun...
CREDITS: me and those others who had this same code in their server.