Vote NPC Problem.

08/26/2012 18:32 Novakhan#1
Well, I've been trying to make that npc works perfectly for hours but it doesn't.. If you click on Sure! it goes directly on Sorry but you already voted. Please wait 12 hours! without giving CPs neither opening the site. If someone can tell me what's wrong in the code, That'd help me^^

Thanks =)

Code:
                #region Vote npc
                case 4466:
                    {
                        switch (npcRequest.OptionID)
                        {
                            case 0:
                                {
                                    dialog.Text("Hi " + client.Entity.Name + "do you want to vote?");
                                    dialog.Option("Sure!", 1);
                                    dialog.Option("Maybe later", 255);
                                    dialog.Avatar(95);
                                    dialog.Send();
                                    break;
                                }
                            case 1:
                                {
                                    if (DateTime.Now.Hour == 12 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00 || DateTime.Now.Hour == 24 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00)
                                    {
                                        client.Entity.ConquerPoints += 100000;
                                        client.Send(new Conquer_Online_Server.Network.GamePackets.Message("http://www.xtremetop100.com/in.php?site=1132310025", System.Drawing.Color.Yellow, 2105));
                                        Conquer_Online_Server.ServerBase.Kernel.SendWorldMessage(new Message("Congratulations! " + client.Entity.Name + " voted for BeastyCoV2 and got 100.000 CPs!", System.Drawing.Color.White, Message.Center), Conquer_Online_Server.ServerBase.Kernel.GamePool.Values);
                                        dialog.Text("Thanks for voting!");
                                        dialog.Option("You're welcome!", 255);
                                        dialog.Send();
                                        break;
                                    }
                                    else
                                    {
                                        dialog.Text("Sorry you already voted. Please wait 12 hours!");
                                        dialog.Option("My bad..", 255);

                                        dialog.Send();
                                    }
                                    break;
                                }
                        }
                        break;
                    }
                #endregion
08/26/2012 23:11 U2_Caparzo#2
u are checking if the time is exactly 12:00 with 0 seconds or 24:00 with 0 seconds, u got it? when u use the npc, and voted succesfully u save the DateTime in your database, so when u talk to the npc, the check must be
Code:
if(client.Entity.LastVote.AddHours(12) <= DateTime.Now)
{
      client.Send(new Conquer_Online_Server.Network.GamePackets.Message("http://www.xtremetop100.com/in.php?site=1132310025", System.Drawing.Color.Yellow, 2105));
      client.Entity.LastVote = DateTime.Now;
}
being LastVote a DateTime with the set and get properties
Code:
DateTime _LastVote
public DateTime LastVote
{
       get{return _LastVote;}
       set{Database.SaveVote(this);}
}
SaveVote voids to update the MySql database with "Entity" as param, and ofc reading the lastvote when loading the entity
that is the way i would do it at least
08/26/2012 23:16 diedwarrior#3
Code:
DateTime.Now.Hour == 12 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00 || DateTime.Now.Hour == 24 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00
Is totally wrong, this means you MUST vote/click npc at 12 pm/am
Just make a datetime variable like lastvote, not so hard.