Question about a code (5165)

08/23/2010 06:50 copz1337#1
SERVER 5165 LOTF
Well, what this npc is suppose to do in order is: Check if you have 50k cps or more, check if you are level 130 or more, check if you are level 137 or less (so check if your between level 130-137 and also checks if you have 50k or more cps). If true, the npc takes away 50k cps from your inventory, and adds a level and broadcasts that you bought a lvl. Otherwise, it gives an error message.

But I'm getting 2 errors on the line where "else" is which are "Invalid Expression term 'else'" and "';' expected. How do I fix this ? I don't get it. Here's the code.

Code:
                            #region Leveler 137
                            case 88955:
                                {
                                    if (Control == 0)
                                    {
                                        GC.AddSend(Packets.NPCSay("Hello, I'm the hoe that you want to talk to if you want to buy levels from 130-137. Want to buy a lvl for 50,000 cps each?"));
                                        GC.AddSend(Packets.NPCLink("Buy a level.", 1));
                                        GC.AddSend(Packets.NPCLink("Just passing by.", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                    if (Control == 1)
                                    {
                                        if (GC.MyChar.CPs >= 50000) & (GC.MyChar.Level >= 130) & (GC.MyChar.Level <= 137);
                                        {
                                            GC.MyChar.CPs -= 50000;
                                            GC.MyChar.Level += 1;
                                            Broadcast("Congratulations," + GC.MyChar.Name + "has just bought a level! He/she is now level" + GC.MyChar.Level+"!");
                                            GC.AddSend(Packets.NPCSay("You have leveled up! You are now level" + GC.MyChar.Level+". Thank you for buying a level, come back soon!"));
                                            GC.AddSend(Packets.NPCLink("Thanks.", 255));
                                            GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            GC.AddSend(Packets.NPCFinish());
                                        }
                                        else
                                        {
                                            GC.AddSend(Packets.NPCSay("Sorry, you must be level 130-136 and have 50,000 cps to buy a level."));
                                            GC.AddSend(Packets.NPCLink("Damn.", 255));
                                            GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            GC.AddSend(Packets.NPCFinish());
                                        }
                                        break;
                                    }
                                }
                            #endregion
08/23/2010 10:35 BLASTER!!!!#2
dont use & () & () & ().
use && && &&.
im talking about this:
if (GC.MyChar.CPs >= 50000) & (GC.MyChar.Level >= 130) & (GC.MyChar.Level <= 137);
and dont use ; for checks.
make it:
if (GC.MyChar.CPs >= 50000 && GC.MyChar.Level >= 130 && GC.MyChar.Level <= 137)

and this one:
break;
never put break 2 brackets over end.
It have to be inside the case.
like

case 1:
{
break;
}

controls:
case 1:
{
if (control == 1)
{

}
break;
}

Should work :)
08/23/2010 13:16 .Beatz#3
Code:
#region Leveler 137
                            case 88955:
                                    {
                                        if (Control == 0)
                                        {
                                            GC.AddSend(Packets.NPCSay("Hello, I'm the hoe that you want to talk to if you want to buy levels from 130-137. Want to buy a lvl for 50,000 cps each?"));
                                            GC.AddSend(Packets.NPCLink("Buy a level.", 1));
                                            GC.AddSend(Packets.NPCLink("Just passing by.", 255));
                                            GC.AddSend(Packets.NPCSetFace(30));
                                            GC.AddSend(Packets.NPCFinish());
                                        }
                                        if (Control == 1)
                                        {
                                            if (GC.MyChar.CPs >= 50000 && GC.MyChar.Level >= 130 && GC.MyChar.Level <= 137)
                                            {
                                                GC.MyChar.CPs -= 50000;
                                                GC.MyChar.Level += 1;
                                                Broadcast("Congratulations," + GC.MyChar.Name + "has just bought a level! He/she is now level" + GC.MyChar.Level + "!");
                                                GC.AddSend(Packets.NPCSay("You have leveled up! You are now level" + GC.MyChar.Level + ". Thank you for buying a level, come back soon!"));
                                                GC.AddSend(Packets.NPCLink("Thanks.", 255));
                                                GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                                GC.AddSend(Packets.NPCFinish());
                                            }
                                            else
                                            {
                                                GC.AddSend(Packets.NPCSay("Sorry, you must be level 130-136 and have 50,000 cps to buy a level."));
                                                GC.AddSend(Packets.NPCLink("Damn.", 255));
                                                GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                                GC.AddSend(Packets.NPCFinish());
                                            }
                                        }
                                        break;
                                    }
                            #endregion
Done
08/23/2010 18:06 copz1337#4
Thanks now it works. #Request close