This release allows a GM to pose a question to the server. Players can then answer using a command (@vote <option number>, or whatever you are coding it as). Poll results will be broadcast every one minute until the poll is closed.
DO NOTE: I have no idea which source I coded it on. I doubt it's lithium-based. But, I'm referring to lithium to re-create the tutorial. And copy-pasting the old non-lithium code.
TL;DR version: Would work on lithium with minor edits, e.g. variable renaming etc.
Idiot version: Do not use this release.
Step 1
Head to ChannelServer.java, adding this chunk of code in:
Step 2
Add the following player command:
@vote
Step 3
Add the following GM commands:
!spquestion
!spoption
!spclear
!startpoll
!endpoll
How to use (If I remember correctly)
"Features" to note:
Uses:
Enjoy, if you can get it to work :P
DO NOTE: I have no idea which source I coded it on. I doubt it's lithium-based. But, I'm referring to lithium to re-create the tutorial. And copy-pasting the old non-lithium code.
TL;DR version: Would work on lithium with minor edits, e.g. variable renaming etc.
Idiot version: Do not use this release.
Step 1
Head to ChannelServer.java, adding this chunk of code in:
PHP Code:
private static String voteQuestion = "";
private static List<String> voteOptions = new ArrayList<>();
private static List<Integer> voteCounts = new ArrayList<>();
private static List<String> voters = new ArrayList<>();
private static boolean voteStarted = false;
public boolean setVoteQuestion(String vQuestion) {
if (voteStarted) {
return false;
}
voteQuestion = vQuestion;
return true;
}
public String getVoteQuestion() {
return voteQuestion;
}
public boolean addVoteOption(String newVOption) {
if (voteStarted) {
return false;
}
voteOptions.add(newVOption);
voteCounts.add(o);
return true;
}
public boolean clearVoteOptions() {
if (voteStarted) {
return false;
}
voteOptions.clear();
voteCounts.clear();
return true;
}
public String[] getAllVoteOptions() {
return voteOptions.toArray(new String[voteOptions.size()]);
}
public int[] getAllVoteCounts() {
int result[] = new int[voteCounts.size()];
for (int i = 0; i < voteCounts.size(); i++) {
result[i] = voteCounts.get(i);
}
return result;
}
public boolean vote(int optionNumber, MapleCharacter thisVoter) {
if (!voteStarted) {
return false;
}
if (voters.contains(thisVoter.getName())) {
thisVoter.dropMessage("You have already placed your vote!");
return false;
}
optionNumber -= 1;
if (optionNumber >= voteCounts.size()) {
thisVoter.dropMessage("There are only " + String.valueOf(voteCounts.size()) + " option" + (voteCounts.size() == 1 ? "" : "s") + " for this
poll.");
for (int i = 0; i < voteOptions.size(); i++) {
thisVoter.dropMessage("[OPTION " + String.valueOf(i + 1) + "] " + voteOptions.get(i));
}
return false;
}
voteCounts.set(optionNumber, voteCounts.get(optionNumber) + 1);
return true;
}
public boolean isVoteStarted() {
return voteStarted;
}
public void startVote(int updateInterval) {
if (voteStarted) {
return;
}
voteStarted = true;
for (MapleCharacter chr : players.getAllCharacters()) {
chr.dropMessage("[POLL] " + voteQuestion);
for (int i = 0; i < voteOptions.size(); i++) {
chr.dropMessage("[OPTION " + String.valueOf(i + 1) + "] " + voteOptions.get(i));
}
chr.dropMessage("Use the command @vote <option number> to place your votes.");
}
/*TimerManager.getInstance().schedule(new Runnable() {
[MENTION=2000004426]Override[/MENTION]
public void run() {
voteStarted = false;
}
}, updateInterval);*/
updateVote(updateInterval);
}
public void startVote() {
startVote(60 * 1000);
}
private void updateVote(final int updateInterval) {
TimerManager.getInstance().schedule(new Runnable() {
[MENTION=2000004426]Override[/MENTION]
public void run() {
if (voteStarted == false) {
return;
}
for (MapleCharacter chr : players.getAllCharacters()) {
chr.dropMessage("[POLL] " + voteQuestion);
for (int i = 0; i < voteOptions.size(); i++) {
chr.dropMessage("[OPTION " + String.valueOf(i + 1) + "] " + voteOptions.get(i) + " - Voted: " + voteCounts.get(i));
}
chr.dropMessage("Use the command @vote <option number> to place your votes.");
}
updateVote();
}
}, updateInterval);
}
public void endVote() {
for (MapleCharacter chr : players.getAllCharacters()) {
chr.dropMessage("[POLL] The poll has ended. The following are the results to the question: + voteQuestion");
for (int i = 0; i < voteOptions.size(); i++) {
chr.dropMessage("[OPTION " + String.valueOf(i + 1) + "] " + voteOptions.get(i) + " - Voted: " + voteCounts.get(i));
}
}
}
public void clearVoting() {
voteQuestion = "";
voteOptions = new ArrayList<>();
voteCounts = new ArrayList<>();
voters = new ArrayList<>();
voteStarted = false;
}
Add the following player command:
@vote
PHP Code:
int option = Integer.parseInt(sub[1]);
ChannelServer.vote(option, chr);
Add the following GM commands:
!spquestion
PHP Code:
String newQuestion = joinStringFrom(sub, 1);
if (ChannelServer.setVoteQuestion(newQuestion)) {
player.dropMessage("Vote question successfully changed to " + newQuestion + "'");
} else {
player.dropMessage("Voting in progress. Unable to change vote question.");
}
PHP Code:
String newOption = joinStringFrom(sub, 1);
if (ChannelServer.addVoteOption(newOption)) {
player.dropMessage("Vote option successfully added.");
for (int i = 0; i < ChannelServer.getAllVoteOptions().length; i++) {
player.dropMessage("Option " + String.valueOf(i + 1) + ": " + ChannelServer.getAllVoteOptions()[i]);
}
} else {
player.dropMessage("Voting in progress. Unable to change vote options.");
}
PHP Code:
if (ChannelServer.isVoteStarted()) {
player.dropMessage("Voting in progress. Unable to clear vote settings.");
} else {
ChannelServer.clearVoting();
}
PHP Code:
if (ChannelServer.isVoteStarted()) {
player.dropMessage("Voting in progress. Unable to start a new vote");
} else {
if (sub.length > 1) {
ChannelServer.startVote(Integer.parseInt(sub[1]));
} else {
ChannelServer.startVote();
}
}
PHP Code:
if (ChannelServer.isVoteStarted()) {
ChannelServer.endVote();
} else {
player.dropMessage("There is no voting in progress");
}
Spoiler:
"Features" to note:
- Polling settings keep between polls. Meaning if the previous poll messed up, a simple !startvote will let you do it again without having to set all the options again. But this also means that if you create a new poll without using !spclear, you may end up with the previous poll's options in your poll.
- The polling questions are public to all GMs. This means that anyone can change the question and the options anytime. If two or more people try to set up a poll at once, the results will be fairly disastrous, and not to mention seriously hilarious.
- Interval between the notices can be changed. Or taken away entirely to make it a secret poll
- There are no commands to update the GM on the poll results, though that can be easily arranged.
- Starting/ending the poll is manual, so if the response is poor, you can always end the poll early, or leave it on longer for more people to vote. I leave it to you.
Uses:
- Event hosting
- Vote for a winner of a beauty/popularity contest
- Polling for major decisions on the server
- Spamming players with useless attention-whoring polls that have no use whatsoever other than to advertise the polling GM's presence and sense of obnoxious "popularity"
Enjoy, if you can get it to work :P