Author Topic: Moving Resources: Moving one item instead of stack  (Read 3790 times)

0 Members and 1 Guest are viewing this topic.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.4%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Moving Resources: Moving one item instead of stack
« on: February 26, 2013, 07:43:15 AM »
0
I am using Polonius's Move Resource Sub. I have looked this over a ton of times but best as I can tell the checkpotash sub is showing to check for a stack >=500 and then to move that 500. It is moving 1 piece of potash to the resource container but leaving the stack >=500. What am I missing?

Code: [Select]
;=========================================
Start:
Gosub Setup

;===================Sub Setup============================
Sub Setup
set %TinkerTools JTL_GTL_KTL
Set %Tongs OBG
Set %Boards TLK
Set %MortarPestle RQF
Set %EmptyPitcher WYF
Set %FullPitcher VBM
Set %Potash AFZ
Set %SaveList NWH_RCG_FCG_FKF
Set %DumpList
set %Ingots ENK
set %cwin 530_497            ; Crafting window size
set %gumpwait 1 ; Increase number to slow down clicks on menus.  20 = 1 second.
set %targetcursorwait 1 ; Increase number as above

Display Ok Select the container with your resources in it.
  set #targcurs 1
      while #targcurs = 1
         wait 1
      set %ResourceSecure #ltargetID
      set #lobjectID #ltargetID
      set #nextcposx 400
      set #nextcposy 0
      event macro 17
      wait 20
      {
      gosub mainmenu
      }
return

;===================Sub Main Menu======================
sub MainMenu
menu Clear
menu Window Title Crisis High Seas Munitions Factory
menu Window Color $FFFFFFFF
menu Window Size 190 130
menu Font Transparent #true
menu Font Align Right
menu Font Name Comic Sans MS
menu Font Size 8
menu Font Style b
menu Font Color Lime
menu Font Transparent #false
menu Font Align Left
menu Font BGColor $FFFFFFFF
menu Text EUOLabel1 63 0 Select One:
menu Font Name MS Sans Serif
menu Font Style
menu Font Color WindowText
menu Font BGColor Window
menu Font BGColor Lime
menu Button begin  64 62 55 25 Start
menu Font Name Comic Sans MS
menu Font Style b
menu Font Color Lime
menu Font BGColor $FFFFFFFF
menu Font Name MS Sans Serif
menu Font Style
menu Font Color WindowText
menu Font BGColor Window
menu Combo Create list 20 16 150
  menu Combo Add list Potash
menu Combo Add list Black Powder
menu Combo Add list Light Powder Charge
menu Combo Add list Heavy Powder Charge
menu Combo Add list Light Grapeshot
menu Combo Add list Light Cannonball
menu Combo Add list Heavy Grapeshot
menu Combo Add list Heavy Cannonball
menu Combo Add list Fuse Cord
menu Combo Add list Match Cord
menu Combo Add list Match
menu Combo Add list Swab
menu Combo Add list Ramrod
menu Show 421 270
  set #menubutton N/A
  repeat
  until #menubutton <> N/A
  menu delete begin
  menu hide
  menu get list
if #menures = 1
   set %craftable Potash
if #menures = 2
   set %craftable BlkPwdr
if #menures = 3
   set %craftable LtPwdrChg
if #menures = 4
   set %craftable HvyPwdrChg
if #menures = 5
   set %craftable LtGrpSht
if #menures = 6
   set %craftable LtCanBall
if #menures = 7
   set %craftable HvyGrpSht
if #menures = 8
   set %craftable HvyCanBall
;choosesitem %craftable

if %craftable = Potash
      {
      Display You must be next to a water trough and have a water pitcher in your backpack.
      gosub MakePotash
      }
if %craftable = BlkPwdr
      {
      gosub MakeBlackPowder
      }
if %craftable = LtPwdrChg
      {
      gosub LightPowderCharge
      }
if %craftable = HvyPwdrChg
      {
      gosub HeavyPowderCharge
      }
if %craftable = LtGrpSht
      {
      gosub LightGrapeShot
      }
if %craftable = LtCanBall
      {
      gosub LightCannonBall
      }
if %craftable = HvyGrpSht
      {
      gosub HeavyGrapeShot
      }
if %craftable = HvyCanBall
      {
      gosub HeavyCannonBall
      }
until #charghost = yes
return

;===================Sub Make Potash===========================
Sub MakePotash
    MakePotashLoop:
    finditem %Boards C_ , #backpackid
         if #findstack < 10
         {
         set %quantityinpack 100 - #findstack
         Gosub Move_Resource_To_Container %Boards 0 %ResourceSecure #BackpackID %quantityinpack
         If ! #Result
            {
            display You need to place more boards in your Resource Secure and hit play.
            pause
            GoTo MakePotashLoop
            }
         }
         {
         finditem %EmptyPitcher C_ , #backpackid
         gosub ENs_FillPitchersFromWaterTrough
         }
         {
         finditem %MortarPestle C_ , #backpackid
         set #lobjectid #findid
         If #findcnt < 2
         gosub MakeMortarPestle
         }
         event macro 17
              gosub waitforgump %cwin
              if ! #result
              {
              Display Dbl Click a mortar and pestle in your backpack and hit play
              Pause
              }
              gosub OffsetClick 25 190
              gosub waitforgump %cwin
              if ! #result
              {
              GoTo MakePotashLoop
              }
              Gosub OffSetClick 230 210 f
              gosub waitforgump %cwin
              if ! #result
              {
              GoTo MakePotashLoop
              }
              Gosub OffSetClick 281 452 f
              gosub waitforgump %cwin
              if ! #result
              {
              GoTo MakePotashLoop
              }
              gosub CheckPotash
              return
;================Sub Move Resource==========================
Sub CheckPotash
finditem %Potash C_ , #backpackid
              if #findstack >= 500
              {
              set %quantityinpack 500 - #findstack
              gosub Move_Resource_To_Container %Potash 1102 #BackpackID %ResourceSecure %quantityinpack
              }
              goto MakePotashLoop
              return
;================Sub Move Resource==========================
Sub Move_Resource_To_Container
; Sub moves a stackable resource from one container to another
; Checks Item Color to insure proper identification (Required)
; Will return #False if there are not enough of the resource
; #True with a successful move
;----------------------------------------------------------
; SAMPLE CALL Line
; Gosub Move_Resource_To_Container ItemType ItemColor ContainerIDSource ContainerIDDestination AmountToMve
;----------------------------------------------------------
namespace push
namespace local NCS
Set !ResourceItemType %1
Set !ResourceColor %2
Set !ResourceSource %3
Set !ResourceDestination %4
Set !ResourceCountToMove %5
Set !ResourceCountToMoveCheck %5
Finditem !ResourceItemType C_ , !ResourceSource
Set #findindex 0
Set #FindCol N/A
Set !ResourceLocated No
while #findindex < #findcnt && No in !ResourceLocated
      {
      set #findindex #findindex + 1
      If #FindCol = !ResourceColor && #FindStack < !ResourceCountToMove && #FindCnt > #findindex
         {
         exevent drag #FindID #FindStack
         Wait 15
         exevent dropc !ResourceDestination
         Wait 15
         Set !ResourceCountToMove !ResourceCountToMove - #FindStack
         Set #findindex 0
         Finditem !ResourceItemType C_ , !ResourceSource
         }
      If #FindCol = !ResourceColor && #FindStack >= !ResourceCountToMove
         {
         exevent drag #FindID !ResourceCountToMove
         Wait 15
         exevent dropc !ResourceDestination
         Wait 15
         Set !ResourceLocated Yes
         }
      }
If #FindIndex = 0 || No in !ResourceLocated
   {
   IgnoreItem Reset
   Namespace pop
   Return #False
   }
Finditem !ResourceItemType C_ , !ResourceDestination
Set #findindex 0
Set #FindCol N/A
Set !ResourceLocated No
while #findindex < #findcnt && No in !ResourceLocated
      {
      set #findindex #findindex + 1
      If #FindCol = !ResourceColor && #FindStack >= !ResourceCountToMoveCheck
         {
         Namespace pop
         IgnoreItem Reset
         Return #True
         }
      }
Namespace pop
Return #False

;=================sub ENs_FillPitchers======================
sub ENs_FillPitchersFromWaterTrough  ; %1= troughrange , defaults to 12 if nothing passed
 If %waterTroughTypes = N/A
  set %waterTroughTypes TEE_WEE_QEE_VEE
 IF  %emptypitcherTypes = N/A
    set %emptypitcher  WYF
 If %0 <> 1
   set %waterTroughRange 12
 finditem %waterTroughTypes G_ , %waterTroughRange
 If #Findcnt = 0
     event exmsg #charid 3 0 ERROR No Water Trough Found
 IF #findcnt > 0
   {
   set %WaterTroughId #findid
   finditem %emptypitcher C_ , #backpackid
   if #findcnt > 0
     {
     For #findindex 1 #findcnt
       {
       set #lobjectid #findid
       event exmsg #charid 3 0 Empty pitchers found, filling! #findindex of #findcnt
       event macro 17
       target 5s
       set #Ltargetkind 1
       set #ltargetid %WaterTroughID
       event macro 22
       wait 20
       }
     }
   }
return

;==================Sub Wait for Gump=========================
sub waitforgump
set %timeout #scnt + 10
while #contsize <> %1
      {
      wait 1
      if #scnt > %timeout
         {
          return #false
         }
      }
wait %gumpwait
return #true
;==================Sub Wait for Target Cursor================
sub WaitForTargetCursor
set %timeout #scnt + 4
Repeat
      wait %targetcursorwait
      if #scnt > %timeout
         return #false
Until #TARGCURS = 1
return #true



;=================Sub Offset Click===========================
sub OffsetClick
  set %tempx %1 + #CONTPOSX
  set %tempy %2 + #CONTPOSY
  click %tempx %tempy f
return

« Last Edit: February 26, 2013, 08:17:02 AM by Crisis »

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #1 on: February 26, 2013, 08:22:05 AM »
0
this is your error (math)... you call the move_resource...  sub with the quantity to move = %quantityinpack

you set %quantityinpack as

finditem %Potash C_ , #backpackid
 if #findstack > 500
              {
              set %quantityinpack 500 - #findstack


So reading this if quantity in pack < 500 do nothing
if quantity in pack > 500   then  move    500 - #stacksize  = a negative number  as we already detemined  findstack > 500 .. so move a negative stack.. !!!!

Should be   set %quantityinpack 500    as thats what you want to move right.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Neo

  • Prime Program
  • Elite
  • *
  • *
  • Posts: 821
  • Activity:
    0%
  • Reputation Power: 13
  • Neo barely matters.Neo barely matters.
  • Respect: +155
  • Referrals: 3
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #2 on: February 26, 2013, 09:10:47 AM »
0
You have those "500 - #findstack" or "10 - #findstack", etc all over the script.

I don't suppose these are evaluating the way you intend them to.

Might want to review those as well...
Never refuse an invitation.
Never resist the unfamiliar.
Never fail to be polite.
And never outstay your welcome.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.4%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #3 on: February 26, 2013, 09:50:29 AM »
0
Wow was I reading that wrong. I was looking at line 234
Code: [Select]
Set !ResourceCountToMove !ResourceCountToMove - #FindStack so thought I needed the dash in there,didn't realize it was a minus. Thank you both!!  :)

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.4%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #4 on: February 26, 2013, 10:16:56 AM »
0
Okay I adjusted the CheckPotash sub to also quit after making the 500 so it is now:
Code: [Select]
;================Sub Check Potash==========================
Sub CheckPotash
finditem %Potash C_ , #backpackid
              if #findstack < 500
              goto MakePotashLoop
              if #findstack >= 500
              {
              set %quantityinpack 500 #findstack
              gosub Move_Resource_To_Container %Potash 1102 #BackpackID %ResourceSecure %quantityinpack
              }
              Halt

Lets say that the user wants to set it to 200 instead of 500. How can I set it so that the user can set the amount of potash to make 200 instead of the 500. I would like for them to be able to adjust that when they first choose to make potash instead of having to edit the checkpotash sub.

Offline Neo

  • Prime Program
  • Elite
  • *
  • *
  • Posts: 821
  • Activity:
    0%
  • Reputation Power: 13
  • Neo barely matters.Neo barely matters.
  • Respect: +155
  • Referrals: 3
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #5 on: February 26, 2013, 12:02:50 PM »
0
Okay I adjusted the CheckPotash sub to also quit after making the 500 so it is now:
Code: [Select]
;================Sub Check Potash==========================
Sub CheckPotash
finditem %Potash C_ , #backpackid
              if #findstack < 500
              goto MakePotashLoop
              if #findstack >= 500
              {
              set %quantityinpack 500 #findstack
              gosub Move_Resource_To_Container %Potash 1102 #BackpackID %ResourceSecure %quantityinpack
              }
              Halt

Lets say that the user wants to set it to 200 instead of 500. How can I set it so that the user can set the amount of potash to make 200 instead of the 500. I would like for them to be able to adjust that when they first choose to make potash instead of having to edit the checkpotash sub.
Well, there's a few ways to do this.

The easiest one (for you) would be to write a section on top of the script where users could change certain variables. Make sure to make it easy for people to see where to edit.

Something like this:

Code: [Select]
;======= user preferences =======
set %potashamount 500 ; change this value to suit your needs
;======= end user preferences =======

The user could just change it to whatever value he'd want, and the script would then use this variable instead of a fixed amount:

Code: [Select]
;================Sub Check Potash==========================
Sub CheckPotash
finditem %Potash C_ , #backpackid
              if #findstack < %potashamount
              goto MakePotashLoop
              if #findstack >= %potashamount
              {
              set %quantityinpack %potashamount #findstack
              gosub Move_Resource_To_Container %Potash 1102 #BackpackID %ResourceSecure %quantityinpack
              }
              Halt
Never refuse an invitation.
Never resist the unfamiliar.
Never fail to be polite.
And never outstay your welcome.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.4%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #6 on: February 26, 2013, 12:54:21 PM »
0
Thanks that is a good way to work it if I can't get the menu to work. Thanks again for your help, I have a lot to learn and you are showing me some good stuff. BTW I love your termur lumberjack script. I use it a lot and it runs great! :)

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #7 on: February 26, 2013, 02:53:02 PM »
0
set %quantityinpack 500 #findstack

The function of #findstack in the above statment is ?????

set Var Value

you have set Var Value Value ??

if you just want a comment then do

set %quantityinpack 500 ; #findstack  ; = comment start
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Neo

  • Prime Program
  • Elite
  • *
  • *
  • Posts: 821
  • Activity:
    0%
  • Reputation Power: 13
  • Neo barely matters.Neo barely matters.
  • Respect: +155
  • Referrals: 3
    • View Profile
Re: Moving Resources: Moving one item instead of stack
« Reply #8 on: February 26, 2013, 03:14:23 PM »
0
set %quantityinpack 500 #findstack

The function of #findstack in the above statment is ?????

set Var Value

you have set Var Value Value ??

if you just want a comment then do

set %quantityinpack 500 ; #findstack  ; = comment start
lol, didn't even notice that one :S
Never refuse an invitation.
Never resist the unfamiliar.
Never fail to be polite.
And never outstay your welcome.

Tags: