[Fix]QuizShow

12/07/2009 12:30 Arcо#1
I hear a lot of people saying how quiz show does not work.
Well I decided to go through the source and find out what the problem is.
It's really simple so here it is.
You're going to go to Database.cs and search for
Code:
public static void LoadQuestions()
Under that you should see this
Code:
{
            {
                string[] AllLines = System.IO.File.ReadAllLines("C:\\OldCODB\\QuizShow.txt");
                int questionscount = AllLines.Length;
                for (int x = 0; x < questionscount; x++)
                {
                    string[] Info = AllLines[x].Split('#');
                    string Question = Info[0];
                    Features.QuizShow.Answer[] Answers = new NewestCOServer.Features.QuizShow.Answer[4];
                    Answers[0] = new NewestCOServer.Features.QuizShow.Answer(Info[1].Split(':')[0], ushort.Parse(Info[1].Split(':')[1]));
                    Answers[1] = new NewestCOServer.Features.QuizShow.Answer(Info[2].Split(':')[0], ushort.Parse(Info[2].Split(':')[1]));
                    Answers[2] = new NewestCOServer.Features.QuizShow.Answer(Info[3].Split(':')[0], ushort.Parse(Info[3].Split(':')[1]));
                    Answers[3] = new NewestCOServer.Features.QuizShow.Answer(Info[4].Split(':')[0], ushort.Parse(Info[4].Split(':')[1]));
                    Features.QuizShow.Question Q = new NewestCOServer.Features.QuizShow.Question(Question, Answers);
                    Features.QuizShow.AllQuestions.Add((ushort)x, Q);
                }
            }
        }
Replace it with this.
Code:
{
            if (File.Exists(@"C:\OldCODB\QuizShow.txt"))
            {
                string[] AllLines = System.IO.File.ReadAllLines(@"C:\OldCODB\QuizShow.txt");
                int questionscount = AllLines.Length;
                for (int x = 0; x < questionscount; x++)
                {
                    string[] Info = AllLines[x].Split('#');
                    string Question = Info[0];
                    Features.QuizShow.Answer[] Answers = new NewestCOServer.Features.QuizShow.Answer[4];
                    Answers[0] = new NewestCOServer.Features.QuizShow.Answer(Info[1].Split(':')[0], ushort.Parse(Info[1].Split(':')[1]));
                    Answers[1] = new NewestCOServer.Features.QuizShow.Answer(Info[2].Split(':')[0], ushort.Parse(Info[2].Split(':')[1]));
                    Answers[2] = new NewestCOServer.Features.QuizShow.Answer(Info[3].Split(':')[0], ushort.Parse(Info[3].Split(':')[1]));
                    Answers[3] = new NewestCOServer.Features.QuizShow.Answer(Info[4].Split(':')[0], ushort.Parse(Info[4].Split(':')[1]));
                    Features.QuizShow.Question Q = new NewestCOServer.Features.QuizShow.Question(Question, Answers);
                    Features.QuizShow.AllQuestions.Add((ushort)x, Q);
                }
            }
        }
Hope this helps.
12/07/2009 13:20 the.Evil#2
nice work but is res on 4botters =) keep it up
12/07/2009 15:48 ~jochemke~#3
edit doesn't seem to work :s
12/07/2009 16:13 .Donavon#4
There is already source on 4botters that quizshow works.
12/07/2009 18:59 Hitsugaya Toshiro#5
When you add it it has many errors you might wanna fix this ><
12/08/2009 03:29 hunterman01#6
Wow people seriously its not that hard at all

Just add to make sure QuizShow.txt is there thats it -.-

if you do not know how to do that then just quit.

btw good release
12/08/2009 03:35 airborne.#7
Congratz bro. Going to test it now.
12/08/2009 13:33 Arcо#8
What problems are you guys getting?
Because I just extracted a fresh source to try it out and it works perfectly.
12/08/2009 15:06 sawickas#9
Quote:
Originally Posted by Tiku View Post
What problems are you guys getting?
Because I just extracted a fresh source to try it out and it works perfectly.
big thanks to yųo from my xD i trai add timer and ivents start in taime gw quz show dis city for now fail wen i finish it i will realais xD
12/08/2009 15:26 Arcо#10
Quote:
Originally Posted by .Donavon View Post
There is already source on 4botters that quizshow works.

Yeah but some people don't want to download an entire source just for one little thing.
12/08/2009 18:17 Hitsugaya Toshiro#11
Quote:
Originally Posted by Tiku View Post

Yeah but some people don't want to download an entire source just for one little thing.
Tiku this does not fix QuizShow at all you have to go to QuizShow.cs and fix a line
12/08/2009 19:34 minakaram#12
stil dnt work for me
its give a quizshow line 29 error
and
npcdialog line 3798
npcdialog
Code:
                            #region lantern npc
                            case 300003:
                                {
                                    if (Control == 0)
                                    {
                                        GC.AddSend(Packets.NPCSay("Do you want to Start Quiz Show I can do that but You need to pay me 10000 CPs."));
                                        GC.AddSend(Packets.NPCLink("Yeah.", 1));
                                        GC.AddSend(Packets.NPCLink("Just passing by", 255));
                                        GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                    if (Control == 1)
                                    {
                                        if (GC.MyChar.CPs >= 10000)
                                        {
                                            GC.MyChar.CPs -= 10000;
                                            Features.QuizShow.Start();
                                            GC.AddSend(Packets.NPCSay("Ther Hapy Now"));
                                            GC.AddSend(Packets.NPCLink("Ok then.", 255));
                                            GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            GC.AddSend(Packets.NPCFinish());
                                        }
                                        else
                                        {
                                            GC.AddSend(Packets.NPCSay("As i said... you need 10000 CPs. Why do i need to repeat myself?"));
                                            GC.AddSend(Packets.NPCLink("Alright alright.", 255));
                                            GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            GC.AddSend(Packets.NPCFinish());
                                        }
                                    }
                                    break;
                                }
                            #endregion
quizshow
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NewestCOServer.Features
{
    public class QuizShow
    {
        public static Dictionary<ushort, Question> AllQuestions = new Dictionary<ushort, Question>();
        public static Dictionary<ushort, Question> Questions = new Dictionary<ushort, Question>();
        static System.Timers.Timer Timer;
        public static ushort QuestionNO = 0;
        public static QuizShowScore[] Scores = new QuizShowScore[500];
        public static bool QuizON = false;
        public static bool QuizON1 = true;
        static List<int> Container;
        public static void Start()
        {
            QuizON = true;
            Random Rand = new Random();
            Container = new List<int>();
            for (int x = 0; x < 20; x++)
            {
            Again:
                int Gen = Rand.Next(0, 83);
                if (!Container.Contains(Gen))
                {
                    Question Q = (Question)AllQuestions[(ushort)Gen];
                    Answer[] RealAnswers = new Answer[4];
                    bool[] Set = new bool[4];
                    for (int i = 0; i < 4; i++)
                    {
                        int e = Rand.Next(0, 4);
                        while (Set[e])
                            e = Rand.Next(0, 4);
                        RealAnswers[i] = Q.Answers[e];
                        Set[e] = true;
                    }
                    Q.Answers = RealAnswers;
                    Questions.Add((ushort)x, Q);
                    Container.Add(Gen);
                }
                else
                    goto Again;
            }
            Timer = new System.Timers.Timer();
            Timer.Interval = 30000;
            Timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
            foreach (NewestCOServer.Game.Character Char in NewestCOServer.Game.World.H_Chars.Values)
            {
                Char.MyClient.AddSend(Packets.QuizShowStart((ushort)Questions.Count));
                Char.QuizShowInfo = new Info();
            }
            Scores = new QuizShowScore[500];
            for (int x = 0; x < 501; x++)
            { try { Scores[x] = new QuizShowScore(); } catch { continue; } }
            Program.MainQuizShowInfo = new MainInfo();
            Juststarted = true;
            QuestionNO = 0;
            Timer.Start();
            Timer.AutoReset = true;

        }
        public static void Stop()
        {
            Juststarted = false;
            QuizON = false;
            Timer.AutoReset = false;
        }
        static bool Juststarted = false;

        static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (Juststarted)
            {
                foreach (NewestCOServer.Game.Character Char in NewestCOServer.Game.World.H_Chars.Values)
                {
                    Char.MyClient.AddSend(Packets.QuizQuestion(0, 0, 0, 0, 1, Questions[0], Questions[0].Answers[0], Questions[0].Answers[1], Questions[0].Answers[2], Questions[0].Answers[3]));
                    Char.QuizShowInfo.LastAnswer = Environment.TickCount;

                }
                QuestionNO++;
                Juststarted = false;
            }
            else
            {
                if (Features.QuizShow.Questions.ContainsKey((ushort)(QuestionNO)))
                {
                    ushort nextq = QuestionNO;
                    nextq++;
                    foreach (Game.Character Chrr in Game.World.H_Chars.Values)
                    {
                        Main.GameClient GC = Chrr.MyClient;

                        GC.AddSend(Packets.QuizQuestion(GC.MyChar.QuizShowInfo.Score, GC.MyChar.QuizShowInfo.Time,
                            (ushort)(800 * GC.MyChar.QuizShowInfo.Score / 100), 1, nextq, Features.QuizShow.Questions[QuestionNO], Features.QuizShow.Questions[QuestionNO].Answers[0], Features.QuizShow.Questions[QuestionNO].Answers[1], Features.QuizShow.Questions[QuestionNO].Answers[2], Features.QuizShow.Questions[QuestionNO].Answers[3]));
                        GC.MyChar.QuizShowInfo.LastAnswer = Environment.TickCount;
                    }
                }
                else
                {
                    try
                    {
                        foreach (Game.Character Chr in Game.World.H_Chars.Values)
                        {
                            Chr.MyClient.AddSend(Packets.QuizShowEnd(Chr.Name, Chr.QuizShowInfo.Score, Chr.QuizShowInfo.Time, Chr.QuizShowInfo.Rank, (ushort)(800 * Chr.QuizShowInfo.Score / 100)));
                        }
                        Timer.Elapsed -= Timer_Elapsed;
                        Timer.Stop();
                        Timer.Dispose();
                    }
                    catch { }
                    QuizON = false;
                }
                QuestionNO++;
            }

        }
        public class QuizShowScore
        {
            public uint EntityID = 0;
            public uint Score = 0;
        }
        public class MainInfo
        {
            public string[] Name;
            public ushort[] Time;
            public ushort[] Score;
            public MainInfo()
            {
                Name = new string[3];
                Time = new ushort[3];
                Score = new ushort[3];
                Name[0] = "none";
                Name[1] = "none";
                Name[2] = "none";
                Time[0] = 0;
                Time[1] = 0;
                Time[2] = 0;
                Score[0] = 0;
                Score[1] = 0;
                Score[2] = 0;
            }
        }
        public class Info
        {
            public int LastAnswer;
            public ushort Time;
            public ushort Score;
            public ushort QNo;
            public byte[] Answers;
            public ushort Rank;
            public Info()
            {
                LastAnswer = 0;
                Time = 0;
                Score = 0;
                QNo = 1;
                Answers = new byte[Questions.Count];
                Rank = 0;
            }
        }
        public class Question
        {
            public string m_Question;
            public Answer[] Answers;
            public Question(string question, Answer[] answers)
            {
                m_Question = question;
                Answers = answers;
            }
            public static implicit operator string(Question q)
            {
                return q.m_Question;
            }
        }
        public class Answer
        {
            public string m_Answer;
            public ushort Points;
            public Answer(string answer, ushort points)
            {
                m_Answer = answer; Points = points;
            }
            public static implicit operator string(Answer q)
            {
                return q.m_Answer;
            }
        }
    }
}
and the void
Code:
        public static void LoadQuestions()
        {
            {
                if (File.Exists(@"C:\OldCODB\QuizShow.txt"))
                {
                    string[] AllLines = System.IO.File.ReadAllLines(@"C:\OldCODB\QuizShow.txt");
                    int questionscount = AllLines.Length;
                    for (int x = 0; x < questionscount; x++)
                    {
                        string[] Info = AllLines[x].Split('#');
                        string Question = Info[0];
                        Features.QuizShow.Answer[] Answers = new NewestCOServer.Features.QuizShow.Answer[4];
                        Answers[0] = new NewestCOServer.Features.QuizShow.Answer(Info[1].Split(':')[0], ushort.Parse(Info[1].Split(':')[1]));
                        Answers[1] = new NewestCOServer.Features.QuizShow.Answer(Info[2].Split(':')[0], ushort.Parse(Info[2].Split(':')[1]));
                        Answers[2] = new NewestCOServer.Features.QuizShow.Answer(Info[3].Split(':')[0], ushort.Parse(Info[3].Split(':')[1]));
                        Answers[3] = new NewestCOServer.Features.QuizShow.Answer(Info[4].Split(':')[0], ushort.Parse(Info[4].Split(':')[1]));
                        Features.QuizShow.Question Q = new NewestCOServer.Features.QuizShow.Question(Question, Answers);
                        Features.QuizShow.AllQuestions.Add((ushort)x, Q);
                    }
                }
            }
        }
12/08/2009 19:52 Hitsugaya Toshiro#13

Code:
Questions.Add((ushort)x, Q);
That code needx fix and quiz will work
01/22/2010 01:00 NoFatChicks#14
Quote:
Originally Posted by Hepatitis C View Post

Hope this helps.

Got no errors but the when i " /quiz " nothing happens.
Thanks for help.
01/22/2010 04:40 TheLeGend209#15
Quote:
Originally Posted by Hitsugaya Toshiro View Post

Code:
Questions.Add((ushort)x, Q);
That code needx fix and quiz will work
Maybe you should release that fix? :P



and Awesome Post Thanks Bro ++