Author Topic: Move Resource Sub  (Read 5808 times)

0 Members and 1 Guest are viewing this topic.

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +304
  • Referrals: 1
    • View Profile
Move Resource Sub
« on: October 11, 2010, 01:27:51 PM »
0
This is a sub intended to be used to move stackable resources from one container to another.  You must have the item color and type to use the sub.  

Code: [Select]
;==========================================================
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
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

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: +786
  • Referrals: 1
    • View Profile
Re: Move Resource Sub
« Reply #1 on: October 11, 2010, 01:59:56 PM »
0
I dont think you  need these 2 lines (inside the if {} )... 
Code: [Select]
     Set #findindex 0
      Finditem !ResourceItemType C_ , !ResourceSource
Your line where you set #findindex #findindex + 1  .. changes the value of #findid. Thierfor you dont need to do another finditem..
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 PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +304
  • Referrals: 1
    • View Profile
Re: Move Resource Sub
« Reply #2 on: October 11, 2010, 02:14:35 PM »
0
I didn't think so either, but when I split the stack up to test grabbing the intended amount to move into two packets, it left the second packet.  I will keep looking at it and see if I can tighten it up...
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

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: +786
  • Referrals: 1
    • View Profile
Re: Move Resource Sub
« Reply #3 on: October 11, 2010, 03:47:10 PM »
0
this is an untested edit... but it seems like your not beliveing your own code functioned and so are double checking why ?.. and if you do double check you need to record how many you started with to begin with

Code: [Select]
;==========================================================
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

goSub Countnumberinpack ; Count how many you started with
set !StartedAmount #result 

Finditem !ResourceItemType C_ , !ResourceSource
Set #findindex 0
Set #FindCol N/A
Set !ResourceLocated No
while #findindex < #findcnt && !ResourceCountToMove > 0
      {
      set #findindex #findindex + 1
      If #FindCol = !ResourceColor
         {
         set !MoveAmount #findstack
         if !MoveAmount > !ResourceCountToMove
            set !MoveAmount !ResourceCountToMove
         exevent drag #FindID !moveAmount
         Wait 15
         exevent dropc !ResourceDestination
         Wait 15
         Set !ResourceCountToMove !ResourceCountToMove - !MoveAmount
         }
      }
goSub Countnumberinpack
Namespace pop
Return ( !StartedAmount + !ResourceCountToMoveCheck = #result)

Sub Countnumberinpack
  Finditem !ResourceItemType C_ , !ResourceDestination
  Set #findindex 0
  set !AmountGot 0
  while #findindex < #findcnt
      {
      set #findindex #findindex + 1
      If #FindCol = !ResourceColor
         set !AmountGot !AmountGot + #findstack
      }
return !AmountGot


As i say i personally wouldnt do it that way .. i would belive my code worked in actual moving.. and instead of returning true/false it would return the amount it moved.

eg
Code: [Select]
;==========================================================
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
Finditem !ResourceItemType C_ , !ResourceSource
Set #findindex 0
Set #FindCol N/A
Set !ResourceLocated No
while #findindex < #findcnt && !ResourceCountToMove > 0
      {
      set #findindex #findindex + 1
      If #FindCol = !ResourceColor
         {
         set !MoveAmount #findstack
         if !MoveAmount > !ResourceCountToMove
            set !MoveAmount !ResourceCountToMove
         exevent drag #FindID !moveAmount
         Wait 15
         exevent dropc !ResourceDestination
         Wait 15
         Set !ResourceCountToMove !ResourceCountToMove - !MoveAmount
         }
      }
Namespace pop
Return ( %5 - !moveAmount)



100% untest .. arugments sake code.
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 PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +304
  • Referrals: 1
    • View Profile
Re: Move Resource Sub
« Reply #4 on: October 12, 2010, 05:29:01 AM »
0
I guess I am trying to account for lag, or some other issue that would cause the script to malfunction, but I see your point.

I like returning the number of ingots moved instead of T/F. 

Appreciate your help learning how to use the index functions EN. 
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

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: +786
  • Referrals: 1
    • View Profile
Re: Move Resource Sub
« Reply #5 on: October 12, 2010, 08:07:14 AM »
0
I guess I am trying to account for lag, or some other issue that would cause the script to malfunction, but I see your point.

I like returning the number of ingots moved instead of T/F. 

Appreciate your help learning how to use the index functions EN. 

Your welcome.. once you get the findindex mastered you will find alot of things easier and faster to accomplish.  Your extra redundancy is a good thing.. ive been getting a bit lazy on that front I think.

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."

Tags: