[Release]Materials NPC's Related to Buying & Upgrading House for 5165

02/01/2010 03:12 HardNotTo#16
Quote:
Originally Posted by pro4never View Post
Yuppp, that's a function that lets you do the same thing over and over without having to write the entire code required. Think about the additem void. Instead of having to go through all the steps of creating a new item, you have a function that does it for you using simple input such as item Id, +, -, sockets, etc.

What this does is gets an input of the id to find and returns the count of it in the players inventory. The 'genius' of the way he wrote it is you have the base item Id for ores and then each loop (the while loop) it adds the loop count to the end of it thus searching for a different kind of ore each time and then returns how many their are. If there are enough it does a similar loop to delete them from the players inventory.

Hope that helps a bit. @ original npc, good job! Nice to see people contributing.
Awsome, thanks for the explanation, thats exactly what I was wanting to get it to do. Thanks to both of you for your help.
02/01/2010 03:57 HardNotTo#17
Ok, just put in his code and it works, but I have two things wrong with it.
1. It does not count the Rate1 CopperOres
2. Now it requires 12 Ores(correct), but it only removes 5 of them from the inventory and replaces them with the correct number of Vouchers.

Not sure if this helps but there are only 10 different CopperOres listed in order from 1072020 to 1072029
02/01/2010 04:01 pro4never#18
byte count = 1;

Change that to 0, that should help (assuming the first copper ore is 1072020 instead of 1072021.

totalcount += GC.MyChar.InventoryItemIDCount((uint)(1072020 + count));

That's saying it's using 1072020 + whatever loop number it is on to check for items in inventory. with count being initially 1 it will only go up from 1072021 (thus not counting the rate 1 ores)


Do the same fix to the removal and that may fix some of your problems.
02/01/2010 05:27 HardNotTo#19
ok i got it to count the Rate1 Copper, thanks

now for the removal i changed:

count = 1; this bit has me stuck I know that at count = 1; it removes 5 of the 12 Ores. changed to: count = 0; and now it removes 10 of the 12 Ores, then just to test something I changed it to: count = 12; and it didn't remove any Ores, but did give the Vouchers.
while (count != 13 && othercount != 12)
{
GC.MyChar.RemoveItem(GC.MyChar.NextItem((uint)(107 2020 + count)));
count++;
othercount++;

Well, after trying different things, nothing working, I will give up for the night and try again tomorrow. I could take the easy way out and have it require only 10 CopperOres, but then I wouldn't be learning anything. So maybe something will come to me while I sleep.
02/01/2010 05:58 pro4never#20
I think you may need to get a new remove item void. My suspicion (without having used lotf) is that it's just going ahead and removing the ores even if they aren't properly in your inventory.

You might need something similar to the count item id fucntion he posted basically doing a loop through inventory counting up ores of 1 type, removing them and then subtracting how many more ores need to be removed from the inventory and moving on to the next one.
02/01/2010 09:04 -impulse-#21
I guess it's my fault that it wasn't counting all ores... I'm not sure how many rate of ores are there 10 or 12?
02/01/2010 14:49 HardNotTo#22
Quote:
Originally Posted by -impulse- View Post
I guess it's my fault that it wasn't counting all ores... I'm not sure how many rate of ores are there 10 or 12?
there are 10
02/01/2010 17:46 -impulse-#23
alright then let me rewrite the code :X

PHP Code:
else if (Control == 3)
                                    {
                                        
byte[] contains = new byte[10];
                                        
byte totalcount 0;
                                        
byte othercount 0;
                                        
byte count 0;
                                        while (
count != 10)
                                        {
                                            
contains[count] += GC.MyChar.InventoryItemIDCount((uint)(1072020 count));
                                            
totalcount += GC.MyChar.InventoryItemIDCount((uint)(1072020 count));
                                            
count++;
                                        }
                                        if (
totalcount >= 12)
                                        {
                                            
count 0;
                                            while (
count != 10 && othercount != 12)
                                            {
                                                while (
contains[count] != && othercount != 12)
                                                {
                                                    
GC.MyChar.RemoveItem(GC.MyChar.NextItem((uint)(1072020 count)));
                                                    
othercount++;
                                                    
contains[count]--;
                                                }
                                                
count++;
                                            }
                                            for (
int i 010i++)
                                                
GC.MyChar.AddItem(721175);
                                            
GC.AddSend(Packets.NPCSay("Congragulation you have 10 Copper Ore Voucher for 12 Any Rate Copper Ores."));
                                            
GC.AddSend(Packets.NPCLink("OK Thx"255));
                                            
GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            
GC.AddSend(Packets.NPCFinish());
                                        }
                                        else
                                        {
                                            
GC.AddSend(Packets.NPCSay("Sorry you dont have 12 Any Rate Copper Ores."));
                                            
GC.AddSend(Packets.NPCLink("OK i see."255));
                                            
GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            
GC.AddSend(Packets.NPCFinish());
                                        }
                                    } 
This should work...It was like removing one of 1 type... never 2 of 1 type
02/01/2010 18:43 HardNotTo#24
Quote:
Originally Posted by -impulse- View Post
alright then let me rewrite the code :X

PHP Code:
else if (Control == 3)
                                    {
                                        
byte[] contains = new byte[10];
                                        
byte totalcount 0;
                                        
byte othercount 0;
                                        
byte count 0;
                                        while (
count != 10)
                                        {
                                            
contains[count] += GC.MyChar.InventoryItemIDCount((uint)(1072020 count));
                                            
totalcount += GC.MyChar.InventoryItemIDCount((uint)(1072020 count));
                                            
count++;
                                        }
                                        if (
totalcount >= 12)
                                        {
                                            
count 0;
                                            while (
count != 10 && othercount != 12)
                                            {
                                                while (
contains[count] != && othercount != 12)
                                                {
                                                    
GC.MyChar.RemoveItem(GC.MyChar.NextItem((uint)(1072020 count)));
                                                    
othercount++;
                                                    
contains[count]--;
                                                }
                                                
count++;
                                            }
                                            for (
int i 010i++)
                                                
GC.MyChar.AddItem(721175);
                                            
GC.AddSend(Packets.NPCSay("Congragulation you have 10 Copper Ore Voucher for 12 Any Rate Copper Ores."));
                                            
GC.AddSend(Packets.NPCLink("OK Thx"255));
                                            
GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            
GC.AddSend(Packets.NPCFinish());
                                        }
                                        else
                                        {
                                            
GC.AddSend(Packets.NPCSay("Sorry you dont have 12 Any Rate Copper Ores."));
                                            
GC.AddSend(Packets.NPCLink("OK i see."255));
                                            
GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                            
GC.AddSend(Packets.NPCFinish());
                                        }
                                    } 
This should work...It was like removing one of 1 type... never 2 of 1 type
that fixed it...works perfectly...thank you both for helping me with this.

Updated first post with this fix and gave credit to you.