have the bot values held in a class which doesn't have an instance for every player
|
i was making a triviabot for a friend, since the other one he had was complete shit and when i tested it with 1 player it worked fine, with 2 it worked just as well, but when i tried with 3+ it got all messed up
when 3 players+ are on the messages and answers get all messed up and gives everyone diff messages and crap, heres the code
Code:public static void askQuestion(final Client c) { for (final Player p : Server.playerHandler.players) { final Client person = (Client) p; if (p != null && p != c) { final Client otherPlayers = (Client) p; EventManager.getSingleton().addEvent(new Event() { int tTime = 30; public void execute(EventContainer trivia) { if (tTime == 30) { //triviaGame = true; getAllInfo(); canAnswer = true; otherPlayers.sendMessage(triviaBotName + questionSentence); c.sendMessage(triviaBotName + questionSentence); } if (answeredCorrect) { otherPlayers.sendMessage(triviaBotName + playerNameWhoAnswered + " got it!"); c.sendMessage(triviaBotName + playerNameWhoAnswered + " got it!"); tTime = 31; canAnswer = false; answeredCorrect = false; } if (tTime > 0) tTime--; if (cancelTrivia) trivia.stop(); if (tTime <= 0) { otherPlayers.sendMessage(triviaBotName2 + "Time is up! The correct answer was " + answer); c.sendMessage(triviaBotName2 + "Time is up! The correct answer was " + answer); doingTrivia = false; tTime = 60; answeredCorrect = false; } } }, 1000); } } }
have the bot values held in a class which doesn't have an instance for every player
I have to agree with you, that code doesn't make any sense.
That code is messed up, one second.
Your doing it all wrong. Dont make the player execute the method.
Add something like TriviaBot.java
Somthing like this:
Make a event execute on startUp every 5 Minutes or so?Code:public String Question; public String Answer; public String[][] QandA = { {"What is this site", "Rune Server"}, {"Death of sound", "Silencer"} };
Then in your commands of yell.Code:public void event() { //Execute 5 Minutes Question = QandA[Misc.random(QandA.length)][0]; Answer = QandA[Misc.random(QandA.length)][1]; Server.sendAllMessage(Question); }
Hope i helped.Code:if(yellMessage.contains(TriviaBot.Answer)) { //Has to be static but i cba TriviaBot.getRight(c); //Answer = null and Question = null }
Instead of making a player call the method. Make it global. so make the Event execute from via server startup (were the handlers load). and make sure there is no Client c crap called in the Event it's not needed. Event 5 minutes or so Make the event so that questions and answer changes and the server yells.
You can use this..
for(int i = 0; i < Server.playerHandler.players.length; i++) {
if(Server.playerHandler.players[i] != null) {
Server.playerHandler.players[i].sendMessage(Question);
}
}
Ill make a trivia bot tomo if you still do not get it.
thx think i got it now
basically i was using Client c, which i wasnt supposed to, duh
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |