Author Topic: FINDCOL  (Read 320 times)

0 Members and 1 Guest are viewing this topic.

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
FINDCOL
« on: July 12, 2017, 08:30:32 PM »
0
I am trying to get this to work but not much luck. Findcol doesn't really have an example that I can use to help. http://wiki.easyuo.com/index.php?title=FindCol

I tried this sub but no luck
Code: easyuo
  1. Sub AddCraftedItems3
  2.    finditem %SB_Engrave_Tool_Color C_ , #backpackid
  3.    set %crafted ( #findcnt + %stackmoved )
  4.    Menu Font Size 10
  5.    Menu Font Color Black
  6.    menu set Crafted %crafted
  7. Return
  8. ;===================================================================

At the beginning of the Script, I set the item color like this

Code: easyuo
  1. set %SB_Engrave_Tool_color 1165

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12881
  • Activity:
    3.6%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Jesse
  • Respect: +21
  • Referrals: 30
    • View Profile
    • ScriptUO
Re: FINDCOL
« Reply #1 on: July 12, 2017, 08:38:53 PM »
0
Here's something I'm putting together on the fly....

Code: easyuo
  1. ; finds the count of a specific colored item.  Returns one as #LOBJECTID, returns 0 if nothing is found - #LOBJECTID not touched
  2. sub FindColoredItem
  3.   namespace push
  4.   namespace local FCI
  5.   set !finditem %1
  6.   set !container %2
  7.   set !color %3
  8.   set !rval 0
  9.   finditem !finditem C_ , !container
  10.   if #FINDCNT > 0
  11.   {
  12.     for #FINDINDEX 1 #FINDCNT
  13.     {
  14.       if #FINDCOL = !color
  15.       {
  16.         set !rval !rval + 1
  17.         set #LOBJECTID #FINDID
  18.       }
  19.     }
  20.   }
  21.   set #RESULT !rval
  22.   namespace pop
  23. return #RESULT
  24.  
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1517
  • Activity:
    1.4%
  • Reputation Power: 19
  • The Ghost is working their way up.The Ghost is working their way up.The Ghost is working their way up.
  • Respect: +12
  • Referrals: 0
    • View Profile
Re: FINDCOL
« Reply #2 on: July 13, 2017, 03:34:15 AM »
0
This is the sub that I use to move colour items.

if the colour is 0, so no need to add it.   
Code: easyuo
  1. ; ========================== SUB RESTOCK ==============================
  2. ;
  3. ;gosub TG_Restock (Container) (ItemStock)  (Amount) (colour)
  4. ; %1 Container to restock from
  5. ; %2 Item to restock
  6. ; %3 Number of items to take
  7. ; %4 Colour Item (optional)
  8. ; Returns #FALSE if item to move is not found
  9. ; gosub TG_Restock %Resource_Secure %Wood %Fletching_Drag_Amount
  10. ; gosub TG_Restock %Resource_Secure %Sand %Sand_Drag_Amount 2413
  11. ;
  12. sub TG_Restock
  13.    menu Edit StatusBox 80 20 121 Restoking %Restock
  14.    Namespace Push
  15.    Namespace Local TG_Restock
  16.    if %0 < 4
  17.    set %4 0
  18.    finditem %2 C_ , %1
  19.    For #findindex 1 #findcnt
  20.  {
  21.        if #findkind = -1
  22.           {
  23.           NameSpace Pop
  24.           Return #FALSE
  25.           }
  26.  
  27.     if #findcol = %4 && #findType = %2
  28.        {
  29.          exevent drag #findid %3
  30.          wait !sWait
  31.          exevent dropc #backpackid
  32.          wait !sWait
  33.         }
  34.   }
  35.    Namespace Pop
  36.      wait !sWait
  37. return
  38. ; ----------------------------------------------------------------
  39.  

Offline BobOzarius

  • Jr. Member
  • **
  • Posts: 97
  • Activity:
    0.2%
  • Reputation Power: 2
  • BobOzarius has no influence.
  • Respect: +6
  • Referrals: 0
    • View Profile
Re: FINDCOL
« Reply #3 on: July 13, 2017, 10:07:24 PM »
0
He's setting the %SB_Engrave_Tool_Color to 1165, then trying to search for the COLOR of the item with a #finditem, on the #backpackid.  He's not understanding you can't search for a color with #findid, you need to set the %SB_Engrave_Tool_Color to the color of the tool you're searching for, like you did. 1165. Then search for the #itemTYPE or #itemID of the kind of tool you are looking for. Or just use one of their options above that works. Hope that explains why your code wasn't working. #findcol is populated AFTER you do a search for any tools that match the type or id of the tool you are searching for. If it does, you loop through the #findindex until you find a tool that #findcol matches 1165, and that's the tool you "use" with set #lobject #findid. And use that object...

set %SB_Engrave_Tool_color 1165
« Last Edit: July 13, 2017, 10:09:53 PM by BobOzarius »

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
Re: FINDCOL
« Reply #4 on: July 13, 2017, 11:30:06 PM »
0
Here's something I'm putting together on the fly....

Code: easyuo
  1. ; finds the count of a specific colored item.  Returns one as #LOBJECTID, returns 0 if nothing is found - #LOBJECTID not touched
  2. sub FindColoredItem
  3.   namespace push
  4.   namespace local FCI
  5.   set !finditem %1
  6.   set !container %2
  7.   set !color %3
  8.   set !rval 0
  9.   finditem !finditem C_ , !container
  10.   if #FINDCNT > 0
  11.   {
  12.     for #FINDINDEX 1 #FINDCNT
  13.     {
  14.       if #FINDCOL = !color
  15.       {
  16.         set !rval !rval + 1
  17.         set #LOBJECTID #FINDID
  18.       }
  19.     }
  20.   }
  21.   set #RESULT
  22.   namespace pop
  23. return #RESULT !rval
  24.  

I want to thank everyone for the replies so far. I have seen a few different ways and I keep getting stuck with it not counting anything or counting both engraving tool and scribe pen.

TM I understand yours fairly well the only thing that is stumping me is the set !rval 0

I added your sub in my script with no changes and I am calling it like this
Code: easyuo
  1. gosub FindColoredItem %Spellbook_Engraving_Tool #backpackid 1165

I need it to end up if it finds the tool in the backpack and it is colored 1165, it markes it %crafted. I tried to edit yours a little to make it %crafted but no luck. I changed return #RESULT !rval to return #RESULT %crafted  :-[

After looking at many examples, I tried this
Code: easyuo
  1. Sub AddCraftedItems3
  2.    ;set %SB_Engrave_Tool_Color 1165
  3.    finditem %1 C_ , #backpackid
  4.    For #findindex 1 #findcnt
  5.    if #findcol = 1165 && #findType = PBG
  6.    {
  7.    set %crafted ( #findcnt + %stackmoved )
  8.    }
  9.    Menu Font Size 10
  10.    Menu Font Color Black
  11.    menu set Crafted %crafted
  12. Return

However it is not judging by color and still finding both :(

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12881
  • Activity:
    3.6%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Jesse
  • Respect: +21
  • Referrals: 30
    • View Profile
    • ScriptUO
Re: FINDCOL
« Reply #5 on: July 14, 2017, 05:34:06 AM »
0
Actually be careful with the one you posted, it looks like there's a typo that made it into your version.  It doesn't look like it's in mine. !rval just holds the count of the number of colored ones found.  I use !rval and assign that to #RESULT before I do the "namespace pop" so that #RESULT will have the value.  If you pop before you assign, then #RESULT will probably get assigned N/A.

Look at the end of the one you posted and this one to see:

Code: easyuo
  1. ; finds the count of a specific colored item.  Returns one as #LOBJECTID, returns 0 if nothing is found - #LOBJECTID not touched
  2. sub FindColoredItem
  3.   namespace push
  4.   namespace local FCI
  5.   set !finditem %1
  6.   set !container %2
  7.   set !color %3
  8.   set !rval 0
  9.   finditem !finditem C_ , !container
  10.   if #FINDCNT > 0
  11.   {
  12.     for #FINDINDEX 1 #FINDCNT
  13.     {
  14.       if #FINDCOL = !color
  15.       {
  16.         set !rval !rval + 1
  17.         set #LOBJECTID #FINDID
  18.       }
  19.     }
  20.   }
  21.   set #RESULT !rval
  22.   namespace pop
  23. return #RESULT
  24.  

But I see what you are trying to do.  You are just counting the items of a specific color that were crafted in your pack.  I was under the impression that you were looking for a specific color tool to craft with.  heh

I guess the goal here was to make sure you could see how #FINDCOL works in practice.  Looks like it's clear to you now.  :)
« Last Edit: July 14, 2017, 05:39:41 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
Re: FINDCOL
« Reply #6 on: July 16, 2017, 06:54:33 PM »
0
I am still completely stumped on this findcol thing. I am crafting spellbook engraving tools which are PBG just like the scribe tools. scribe tool color = 0 and spell book engraving tool color = 1165 My menu counts the items crafted and it counts %crafted

In the crafting part of the script, I call the sub
Code: easyuo
  1. goSub AddCraftedItems3 %Spellbook_Engraving_Tool

and the sub is
Code: easyuo
  1. Sub AddCraftedItems3
  2.    finditem %1 C_ , #backpackid
  3.    For #findindex 1 #findcnt
  4.    {
  5.     if #findType = PBG && #findcol = 1165
  6.     {
  7.     set %crafted ( #findcnt + %stackmoved )
  8.     }
  9.    }
  10.    Menu Font Size 10
  11.    Menu Font Color Black
  12.    menu set Crafted %crafted
  13. Return
It still counts both items.

I have tried yours TM, modded it a little to fit what I was doing

I call yours here
Code: easyuo
  1. gosub FindColoredItem %Spellbook_Engraving_Tool #backpackid 1165

Code: easyuo
  1. sub FindColoredItem  
  2.   namespace push
  3.   namespace local FCI
  4.   set !finditem %1
  5.   set !container %2
  6.   set !color %3
  7.   set %crafted 0
  8.   finditem !finditem C_ , !container
  9.   if #FINDCNT > 0
  10.   {
  11.     for #FINDINDEX 1 #FINDCNT
  12.     {
  13.       if #FINDCOL = !color
  14.       {
  15.         set %crafted ( #findcnt + %stackmoved )
  16.         set #LOBJECTID #FINDID
  17.       }
  18.     }
  19.   }
  20.   set #RESULT %crafted
  21.   Menu Font Size 10
  22.   Menu Font Color Black
  23.   menu set Crafted %crafted
  24.   namespace pop
  25. return #RESULT

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12881
  • Activity:
    3.6%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Jesse
  • Respect: +21
  • Referrals: 30
    • View Profile
    • ScriptUO
Re: FINDCOL
« Reply #7 on: July 16, 2017, 08:11:10 PM »
0
Is the one you moded working that I originally wrote?

Oh, also you might want to just add one instead of #findcount.  I'm assuming the engraving tool isn't stackable.
Code: easyuo
  1. set %crafted %stackmoved + 1
  2.  
« Last Edit: July 16, 2017, 08:18:27 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
Re: FINDCOL
« Reply #8 on: July 17, 2017, 04:43:45 AM »
0
Is the one you moded working that I originally wrote?

Oh, also you might want to just add one instead of #findcount.  I'm assuming the engraving tool isn't stackable.
Code: easyuo
  1. set %crafted %stackmoved + 1
  2.  

When I modded yours so it would set it as crafted, it would work but still counted the tools as well. I would set it to craft 5, I had 1 scribe tool in my backpack, it would end up crafting 4 engraving tools, counting the scribe tool as 5 and move all 5 into the secure. Without modding yours, it would endlessly create because the menu called for %crafted to check vs the amount entered in. I always have problems getting findcol to work. I had a fairly decent crafting script for making cannon supplies started but gave up because charcoal, black powder, potash, and saltpeter all have the same findid and I had a lot of difficulty with findcol to pull the right ingredients.


When I used the %stackmoved +1, it would count every attempt whether successful or not which is why I went away from it. I wasn't sure if it would work or not. The engraving tools I believe are 100% chance so it wouldn't affect them.

« Last Edit: July 17, 2017, 04:46:23 AM by Crisis »

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12881
  • Activity:
    3.6%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Jesse
  • Respect: +21
  • Referrals: 30
    • View Profile
    • ScriptUO
Re: FINDCOL
« Reply #9 on: July 17, 2017, 05:25:00 AM »
+1
What's the purpose of the %stackmoved variable?  I'm having a hard time making the math work in my head about what happens every time you iterate through the FOR statement and you're adding that to #FINDCNT each time.

Suppose you have 3 tools matching the color 1165 with 7 total in the pack and a stackmoved value set to 10(for example)

%crafted = 0
in the for loop:

found 1: %crafted = #findcnt + %stackmoved --> %crafted = 7 + 10 = 17
found 2: %crafted = #findcnt + %stackmoved --> %crafted = 7 + 10 = 17
found 3: %crafted = #findcnt + %stackmoved --> %crafted = 7 + 10 = 17

Don't you want it to work more like this:
%crafted = 0
in the for loop:

found 1: %crafted = %crafted + 1 --> %crafted = 0 + 1 = 1
found 2: %crafted = %crafted + 1 --> %crafted = 1 + 1 = 2
found 3: %crafted = %crafted + 1 --> %crafted = 2 + 1 = 3

%crafted = %crafted + %stackmoved --> 3 + 10 = 13

??

You probably need to put a "pause" at the beginning of your function, and setup watch points of your variables and then single step through your code to make sure it's working the way you think it should be.

Code: easyuo
  1.     sub FindColoredItem  
  2.       namespace push
  3.       namespace local FCI
  4.       set !finditem %1
  5.       set !container %2
  6.       set !color %3
  7.       set %crafted 0
  8.       finditem !finditem C_ , !container
  9.       if #FINDCNT > 0
  10.       {
  11.         for #FINDINDEX 1 #FINDCNT
  12.         {
  13.           if #FINDCOL = !color
  14.           {
  15.             set %crafted %crafted + 1
  16.             set #LOBJECTID #FINDID
  17.           }
  18.         }
  19.       }
  20.       set #RESULT %crafted + %stackmoved
  21.       Menu Font Size 10
  22.       Menu Font Color Black
  23.       menu set Crafted %crafted
  24.       namespace pop
  25.     return #RESULT
  26.  
« Last Edit: July 17, 2017, 05:41:46 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
Re: FINDCOL
« Reply #10 on: July 17, 2017, 12:12:09 PM »
0
I am the definition of newb scripter lol. I have never had any programming instruction and probably know enough to break things. Everything I know has come from dissecting other scripts trying to see what they do and how they do it. I have learned a lot from the s different subs that you wrote. I am using stacked because when I took it off it didn't work. I had used it in the past when dealing with stacked items (scrolls) and it needed it there.

I was leary about using
Code: easyuo
  1. set %crafted %crafted + 1
because when I used it before, it would count every attempt at crafting, including fails. I had my script set to craft gate travels and I would set it to craft 500 scrolls. It would count every attempt so when it was done counting 500, I actually only had like 420 scrolls.

Your change got it to work and it only counted the engraving tools and not the scribe tool so now I will have to adjust the clear pack sub to not take the scribe tool when it takes the engraving tools. I really wish UO would not use the same findid number for different items lol. As always TM, I greatly appreciate your patience and assistance!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12881
  • Activity:
    3.6%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Jesse
  • Respect: +21
  • Referrals: 30
    • View Profile
    • ScriptUO
Re: FINDCOL
« Reply #11 on: July 17, 2017, 01:07:03 PM »
0
Glad I could help.  I do highly recommend pausing in a sub that's giving you issues, and set up some watched variables and single-step through the code.  Most of the time the problem will be very evident when you start seeing the misbehavior happening in your watched variables in real-time.  The debugging function Cheffe included in EasyUO is actually quite useful but sadly not many take advantage of it.
Please read the ScriptUO site RULES
Come play RIFT with me!

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
Re: FINDCOL
« Reply #12 on: July 17, 2017, 02:00:21 PM »
0
I designed my clearpack sub to remove the colored engraving tools after your sub.

Code: easyuo
  1. sub ClearPack2
  2. ;gosub ClearPack2 (Color)  (Item)  (Destination)
  3.   set !color %1
  4.   finditem %2 C_ , #backpackid
  5.   if #findcnt < 1
  6.     return
  7.   for #findindex 1 #findcnt
  8.   {
  9.     if #FINDCOL = !color
  10.           {
  11.            exevent drag #findid #findstack
  12.            exevent dropc %3
  13.            wait 20
  14.           }
  15.   }
  16. return
  17.  

It seems to be working, did I do anything that looks odd? I was just guessing based off of yours. I also thought about combining this and my other clear pack to save size/lines but then I thought I may need to get every scroll color and stuff like that which would be more of a pain than an extra 10ish lines of code in an already titanic sized script lol. Any merit to that or is there a generic color code that could work if I wasn't truly worried about color?

Or can I reverse the numbers so color is %3 and if color is not used it will just use %1 to move items?
« Last Edit: July 17, 2017, 02:02:23 PM by Crisis »

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1517
  • Activity:
    1.4%
  • Reputation Power: 19
  • The Ghost is working their way up.The Ghost is working their way up.The Ghost is working their way up.
  • Respect: +12
  • Referrals: 0
    • View Profile
Re: FINDCOL
« Reply #13 on: July 17, 2017, 03:57:47 PM »
0
From what I read here,look like you want to craft new tools when yo have none left and craft 5 new one.     If that the case,  I have something that work well,   it even take for a recourse container if needed.    It event use ManWinc  craft sub, should be easy to add or mod your version

Online CrisisTopic starter

  • Elite
  • *
  • *
  • Posts: 1725
  • Activity:
    3.2%
  • Reputation Power: 26
  • Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.Crisis is on the verge of being accepted.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +6
  • Referrals: 1
    • View Profile
Re: FINDCOL
« Reply #14 on: July 17, 2017, 04:27:58 PM »
0
From what I read here,look like you want to craft new tools when yo have none left and craft 5 new one.     If that the case,  I have something that work well,   it even take for a recourse container if needed.    It event use ManWinc  craft sub, should be easy to add or mod your version

Nah, this was crafting spellbook engraving tools which have the same itemid as the scribe tools. What was happening was the script was counting scribe tools and engraving tools as the same thing so if I set it to craft 5 and I had 2 scribe tools, it would craft 3 engraving tools and then move the engraving tools and scribe tools to the secure. I was trying to use findcol to differentiate the engraving tools from the scribe tools which TM was able to help me with.  :D

Tags: