Thread: Lol, doesnt make any sense... [PI]

Results 1 to 10 of 10
  1. #1 Lol, doesnt make any sense... [PI] 
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    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);
    			}
    		}
    	}
    Reply With Quote  
     

  2. #2  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    have the bot values held in a class which doesn't have an instance for every player
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Harlan View Post
    have the bot values held in a class which doesn't have an instance for every player
    which class would that be?

    edit: i made this its own class btw

    still need
    Last edited by Austin_; 11-02-2011 at 10:54 PM.
    Reply With Quote  
     

  4. #4  
    Registered Member Aintaro.'s Avatar
    Join Date
    Sep 2010
    Posts
    998
    Thanks given
    188
    Thanks received
    213
    Rep Power
    37
    I have to agree with you, that code doesn't make any sense.
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Oct 2011
    Posts
    388
    Thanks given
    33
    Thanks received
    45
    Rep Power
    0
    That code is messed up, one second.
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Aintaro. View Post
    I have to agree with you, that code doesn't make any sense.
    it doesnt make sense to you cause you didnt make it and dont know what the variables mean
    Reply With Quote  
     

  7. #7  
    arrowzftw
    Guest
    Your doing it all wrong. Dont make the player execute the method.


    Add something like TriviaBot.java

    Somthing like this:

    Code:
    public String Question;
    public String Answer;
    public String[][] QandA = { {"What is this site", "Rune Server"}, {"Death of sound", "Silencer"} };
    Make a event execute on startUp every 5 Minutes or so?


    Code:
    public void event() { //Execute 5 Minutes
    
    Question = QandA[Misc.random(QandA.length)][0]; 
    Answer = QandA[Misc.random(QandA.length)][1];
    Server.sendAllMessage(Question);
    }
    Then in your commands of yell.

    Code:
    if(yellMessage.contains(TriviaBot.Answer)) { //Has to be static but i cba
    TriviaBot.getRight(c); //Answer = null and Question = null
    }
    Hope i helped.
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by arrowzftw View Post
    Your doing it all wrong. Dont make the player execute the method.


    Add something like TriviaBot.java

    Somthing like this:

    Code:
    public String Question;
    public String Answer;
    public String[][] QandA = { {"What is this site", "Rune Server"}, {"Death of sound", "Silencer"} };
    Make a event execute on startUp every 5 Minutes or so?


    Code:
    public void event() { //Execute 5 Minutes
    
    Question = QandA[Misc.random(QandA.length)][0]; 
    Answer = QandA[Misc.random(QandA.length)][1];
    Server.sendAllMessage(Question);
    }
    Then in your commands of yell.

    Code:
    if(yellMessage.contains(TriviaBot.Answer)) { //Has to be static but i cba
    TriviaBot.getRight(c); //Answer = null and Question = null
    }
    Hope i helped.
    believe it or not thats exactly what i have (well most of it)

    except the part about the server executing the message, how would i go about that again?
    Reply With Quote  
     

  9. #9  
    arrowzftw
    Guest
    Quote Originally Posted by relex lawl View Post
    believe it or not thats exactly what i have (well most of it)

    except the part about the server executing the message, how would i go about that again?

    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.
    Reply With Quote  
     

  10. Thankful user:


  11. #10  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    thx think i got it now

    basically i was using Client c, which i wasnt supposed to, duh
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. This Doesn't Make Sense...
    By Ecstacy Pkz in forum Help
    Replies: 2
    Last Post: 03-03-2011, 07:06 PM
  2. This Doesn't Make Sense...
    By Ecstacy Pkz in forum Help
    Replies: 5
    Last Post: 03-03-2011, 07:21 AM
  3. This error doesnt make sense...
    By Moarte in forum Help
    Replies: 5
    Last Post: 11-01-2009, 02:36 PM
  4. Make sense of these:
    By Vastiko in forum Help
    Replies: 5
    Last Post: 05-11-2009, 08:14 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •