ScriptUO
Official ScriptUO EasyUO Scripts => Script Snippets => Topic started by: Paulonius on October 11, 2010, 01:27:51 PM
-
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.
;==========================================================
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
-
I dont think you need these 2 lines (inside the if {} )...
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..
-
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 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
;==========================================================
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;==========================================================
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.
-
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.
-
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.