[Help] Could Somone Fix This code?..

12/08/2009 03:13 rocka7x#1
hmm Don't Flame im kinda learning.. yes i know its a simple npc.. just as i just stated im learning..


Quote:
if (Control == 0)
{
GC.AddSend(Packets.NPCSay("If you pay me one dragonball, I can have your size changed. . "));
GC.AddSend(Packets.NPCLink("Here is a dragonball.", 2));
GC.AddSend(Packets.NPCLink("I have no dragonball.", 255));
GC.AddSend(Packets.NPCSetFace(30));
GC.AddSend(Packets.NPCFinish());
}
if (Control == 1)
{
if (GC.MyChar.InventoryContains(1088000, 1))
{
for (byte i = 0; i < 1; i++)
GC.MyChar.RemoveItem(GC.MyChar.NextItem(1088000));
}
{

if (GC.MyChar.Body == 1004)
GC.MyChar.Body -= 1;
else if (GC.MyChar.Body == 1003)
GC.MyChar.Body += 1;
if (GC.MyChar.Body == 2002)
GC.MyChar.Body -= 1;
else if (GC.MyChar.Body == 2001)
GC.MyChar.Body += 1;



Missing somthing here?..=/


}
}


GC.AddSend(Packets.NPCSay("Sorry, you do not have a DragonBall."));
GC.AddSend(Packets.NPCLink("OK, I Know.", 255));
GC.AddSend(Packets.NPCSetFace(30));
GC.AddSend(Packets.NPCFinish());
{
break;

}


}
#endregion
12/08/2009 05:20 hunterman01#2
Quote:
GC.AddSend(Packets.NPCLink("Here is a dragonball.", 2));
Change the 2 to a 1
12/08/2009 20:29 ~*NewDuuDe*~#3
Code:
if (Control == 0)
{
GC.AddSend(Packets.NPCSay("If you pay me one dragonball, I can have your size changed."));
GC.AddSend(Packets.NPCLink("Here is a dragonball.", 1));
GC.AddSend(Packets.NPCLink("I do not have a dragonball.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
if (Control == 1)
{
if (GC.MyChar.InventoryContains(1088000, 1))
{
for (byte i = 0; i < 1; i++)
GC.MyChar.RemoveItem(GC.MyChar.NextItem(1088000));
{
if (GC.MyChar.Body == 1004)
GC.MyChar.Body -= 1;
else if (GC.MyChar.Body == 1003)
GC.MyChar.Body += 1;
if (GC.MyChar.Body == 2002)
GC.MyChar.Body -= 1;
else if (GC.MyChar.Body == 2001)
GC.MyChar.Body += 1;
}
else
{
GC.AddSend(Packets.NPCSay("Sorry, you do not have a DragonBall."));
GC.AddSend(Packets.NPCLink("OK, I Know.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
break;
}
}
#endregion
This should work.
12/08/2009 20:57 rocka7x#4
Quote:
Originally Posted by BERGHUIS1 View Post
Code:
if (Control == 0)
{
GC.AddSend(Packets.NPCSay("If you pay me one dragonball, I can have your size changed."));
GC.AddSend(Packets.NPCLink("Here is a dragonball.", 1));
GC.AddSend(Packets.NPCLink("I do not have a dragonball.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
if (Control == 1)
{
if (GC.MyChar.InventoryContains(1088000, 1))
{
for (byte i = 0; i < 1; i++)
GC.MyChar.RemoveItem(GC.MyChar.NextItem(1088000));
{
if (GC.MyChar.Body == 1004)
GC.MyChar.Body -= 1;
else if (GC.MyChar.Body == 1003)
GC.MyChar.Body += 1;
if (GC.MyChar.Body == 2002)
GC.MyChar.Body -= 1;
else if (GC.MyChar.Body == 2001)
GC.MyChar.Body += 1;
}
else
{
GC.AddSend(Packets.NPCSay("Sorry, you do not have a DragonBall."));
GC.AddSend(Packets.NPCLink("OK, I Know.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
break;
}
}
#endregion
This should work.

still 1 error.. giveing invalic expression term 'else'

if i remove that it gives control cannot be followed through from one case label to another..
12/08/2009 21:14 -Shunsui-#5
Quote:
Originally Posted by rocka7x View Post
still 1 error.. giveing invalic expression term 'else'

if i remove that it gives control cannot be followed through from one case label to another..
Check your barckets the eding ones seem messed up,
12/09/2009 10:50 pro4never#6
As said it looks like your indentation is wrong (brackets)


So you know where you went wrong in the first one...


GC.AddSend(Packets.NPCLink("Here is a dragonball.", 2));

This line is saying that you are going to Control==2

In your code the actual code is 1...

You will want something structured like this

Code==0
{
initial npc text/options
}
Code==1
{
if inventory contains dragonball
{
remove db and do the actual code for changing sizes
{
else
{
no db option
}
}


That should be the indentation structure for it.


<edit>

At a second look you want to move the }'s up before the break.

Break indicated the END OF THE NPC You are not closing them in the order that they are opened. Think of each section of {} as a complete thought. Data is executed in the order they are opened so you need to close them in the same order. It will help if you look at them as saying "well this is starting this section of code... and here is where this section of code ends"" That will help you see them as unique symbols and see where you should be closing them.
12/09/2009 14:55 rocka7x#7
Quote:
Originally Posted by pro4never View Post
As said it looks like your indentation is wrong (brackets)


So you know where you went wrong in the first one...


GC.AddSend(Packets.NPCLink("Here is a dragonball.", 2));

This line is saying that you are going to Control==2

In your code the actual code is 1...

You will want something structured like this

Code==0
{
initial npc text/options
}
Code==1
{
if inventory contains dragonball
{
remove db and do the actual code for changing sizes
{
else
{
no db option
}
}


That should be the indentation structure for it.


<edit>

At a second look you want to move the }'s up before the break.

Break indicated the END OF THE NPC You are not closing them in the order that they are opened. Think of each section of {} as a complete thought. Data is executed in the order they are opened so you need to close them in the same order. It will help if you look at them as saying "well this is starting this section of code... and here is where this section of code ends"" That will help you see them as unique symbols and see where you should be closing them.
Thx ill try and sort it out :p
12/09/2009 15:47 _Emme_#8
Quote:
if (Option == 0)
{
Text("Want to change size for a DB?");
Option("Sure",1);
Option("No thank you",255);
}
if (Option == 1)
{
if (InvContains(1088000))
{
if ((Body % 10) == 1 || (Body % 10) == 3)
Body++;
else
Body--;
Client.RemoveItem(1088000);
}
else
{
Text("You don't have a DB!");
Option("Okay",255);
}
}
Don't copy paste. Also remove your loop, what is it there for? Lol