Page 4 of 4 FirstFirst ... 234
Results 31 to 40 of 40
  1. #31
    Senior Member
    Join Date
    Dec 2013
    Location
    Sydney, Australia
    Posts
    496
    Quote Originally Posted by PapaCharlie9 View Post
    But what happens when I get to the bottom of my bag of magic tricks?
    Don't worry, I'm sure myself or others will always find something for you to teach us.

  2. #32
    In that case, how about posting your working code for other people to learn (steal) from?
    Don't send me private messages (PMs) unless you really need privacy, like your game server password. If you just have a question or need help, post in one of the threads. It's extra work for me to answer questions and give help in private messages and no one else gets the benefit of the answer.

  3. #33
    Senior Member
    Join Date
    Dec 2013
    Location
    Sydney, Australia
    Posts
    496
    Quote Originally Posted by PapaCharlie9 View Post
    In that case, how about posting your working code for other people to learn (steal) from?
    I will be posting it, but I'm actually (trying) to modify it so that it can handle multiple message blocks with different delays , targets, number of lines and handle yells with that too, e.g.:
    Message block 1:
    • Delay = 3 seconds
    • Target = All players
    • Messages = 7 Lines of text
    • Yell = Yell message text
    • Yell Duration = 5


    Message block 2:
    • Delay = 12 seconds
    • Target = Specific player
    • Messages = 2 Lines of text
    • Yell = None
    • Yell Duration = 0


    Message block 3:
    • Delay = 7 seconds
    • Target = Specific team
    • Messages = 5 Lines of text
    • Yell = Yell message text
    • Yell Duration = 8
    etc. It does make the thread more complicated, however it will be better.

  4. #34
    Quote Originally Posted by LCARSx64 View Post
    I will be posting it, but I'm actually (trying) to modify it so that it can handle multiple message blocks with different delays , targets, number of lines and handle yells with that too, e.g.:

    etc. It does make the thread more complicated, however it will be better.
    Right, that's why I mentioned you have to change the while condition to take into account that a command has been pulled off the queue, but its still counting down. Actually, you could probably change it to an if:

    Code:
    List <Dictionary<String,String>> timers = new List<Dictionary<String,String>>();
    while (flagStillEnabled) { // exit thread if no longer needed
        Dictionary<String,String> command = null;
        lock (myQueue) {
    	if (timers.Count == 0 && myQueue.Count == 0) { // Wait only if there are no timers counting down
    	    Monitor.Wait(myQueue); // Wait until someone puts something in the queue
    	    if (!flagStillEnabled) return;
    	}
            if (myQueue.Count > 0)
    	    command = myQueue.Dequeue(); // pull the next command off the head of the queue
        }
    
        if (command != null) { // Add a new timer to the list
            timers.Add(command);
        }
    
        List <Dictionary<String,String>> survivors  = new List<Dictionary<String,String>>();
        // Can't delete items from the list in a foreach, so instead add survivors
        foreach (Dictionary<String,String> timer in timers) {
             String strDelay = null;
             if (timer.TryGetValue("delay", out strDelay)) {
                  int delay = Convert.ToInt32(strDelay);
                  delay = delay - 1;
                  if (delay <= 0) {
                      // Fire off whatever command you need to do ...
                      // ...
                      // Since not added to survivors, command is implicitly removed
                  } else {
                      timer["delay"] = delay.ToString();
                      survivors.Add(timer);
                  }
             }
        }
        timers = survivors; // update the list, only timers with non-zero delays still on the list
    
        Thread.Sleep(1*1000); // sleep for 1 second every time we go around the loop
         if (!flagStillEnabled) return;
    }
    Last edited by PapaCharlie9; 03-08-2014 at 03:30.
    Don't send me private messages (PMs) unless you really need privacy, like your game server password. If you just have a question or need help, post in one of the threads. It's extra work for me to answer questions and give help in private messages and no one else gets the benefit of the answer.

  5. #35
    Senior Member
    Join Date
    Dec 2013
    Location
    Sydney, Australia
    Posts
    496
    Quote Originally Posted by PapaCharlie9 View Post
    Right, that's why I mentioned you have to change the while condition to take into account that a command has been pulled off the queue, but its still counting down.
    Very nice Papa. This is similar to what I was doing but I think I messed something up, so I'll test using this code as a template. I was decrementing the delay too but I had my Thread.Sleep higher in the code, before I decremented, that way I ensure that at least 1 second has elapsed before reducing.

  6. #36
    Quote Originally Posted by LCARSx64 View Post
    Very nice Papa. This is similar to what I was doing but I think I messed something up, so I'll test using this code as a template. I was decrementing the delay too but I had my Thread.Sleep higher in the code, before I decremented, that way I ensure that at least 1 second has elapsed before reducing.
    Doh, your way is correct, mine is wrong. Mine would have been ok if the test was specifically delay < 0. Also the delay should be conditional on their being timers, e.g.,

    Code:
    if (timers.Count > 0)
        Thread.Sleep(1*1000);
    Don't send me private messages (PMs) unless you really need privacy, like your game server password. If you just have a question or need help, post in one of the threads. It's extra work for me to answer questions and give help in private messages and no one else gets the benefit of the answer.

  7. #37
    Senior Member
    Join Date
    Dec 2013
    Location
    Sydney, Australia
    Posts
    496
    Quote Originally Posted by PapaCharlie9 View Post
    Doh, your way is correct, mine is wrong. Mine would have been ok if the test was specifically delay < 0. Also the delay should be conditional on their being timers, e.g.,

    Code:
    if (timers.Count > 0)
        Thread.Sleep(1*1000);
    Oh I never considered making the delay conditional, thanks Papa.

  8. #38
    Hello

    code
    // Delayed Skip Round

    Thread ender = new Thread(
    new ThreadStart(
    delegate
    {
    try
    {
    int iDelay = 13; // Delay in seconds
    Thread.Sleep(iDelay * 1000);
    plugin.ServerCommand("mapList.runNextRound");
    }
    catch (Exception e)
    {
    plugin.ConsoleException(e.ToString());
    }
    }
    )
    );

    ender.Name = "RoundEnder";
    ender.Start();

    return false;

    Does not work, That for me not correctly ?

  9. #39
    Is it possible to modify the code to activate at the number of players ? .

    He gives an example .

    10 players and then activated the codu .

    Thank you very much for your answer

  10. #40
    Quote Originally Posted by ZbieraczTP View Post
    Is it possible to modify the code to activate at the number of players ? .

    He gives an example .

    10 players and then activated the codu .



    Thank you very much for your answer
    OnRoundOver

    First check; Expression (server.PlayerCount >= 6)

    Second check; Code /////

    // Delayed Skip Round

    Thread ender = new Thread(
    new ThreadStart(
    delegate
    {
    try
    {
    int iDelay = 30; // Delay in seconds
    Thread.Sleep(iDelay * 1000);
    plugin.ServerCommand("mapList.runNextRound");
    }
    catch (Exception e)
    {
    plugin.ConsoleException(e.ToString());
    }
    }
    )
    );

    ender.Name = "RoundEnder";
    ender.Start();

    return false;


    This will prevent the server from going into a Map Loop Cycle when first 4 players join the round.
    Last edited by Gopostal456; 22-01-2017 at 23:13.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •