ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Crisis on February 21, 2013, 06:46:36 PM
-
I have just about finished with my first crafting script but have a couple of questions.
1. I found a sub to take items from a secure to a backpack but not sure about reversing that. I want it to move it to the secure once it hits a stack of 100. I tried this command finditem %Potash C_ , #backpackid
If #findcnt > 100
{
set %quantityinresourcesecure 100 - #findstack
Gosub Move_Resource_To_Secure %Potash 0 #BackpackID %ResourceSecure %quantityinpack
}
I am using Polinius' Move Resources Sub
2. I am also wanting to set the script to stop making them at a desired number that the user enters. Right now, the script will run until the user runs out of resources.
Any help would be greatly appreciated and keep in mind I am a complete noob but I am trying!
-
I think this might be backwards
set %quantityinresourcesecure 100 - #findstack
it should be something like this.
if #Findstack > 100
set %quantityinresourcesecure #findstack - 100
-
You could do something like this:
set %StopHere 500 ; let's say you wish to stop crafting after 500 items are crafted
set %PotashCrafted 0 ; this is going to be the counter for the amount of items you have crafted
repeat
gosub CraftPotash ; suppose you have a sub that will craft the item
finditem #Potash C_ , #backpackid
if #findcnt >= 100
{
gosub moveresource #findstack #backpackid %resource ; for this case the sub would have to be: %1 quantity to move, %2 bag to move from, %3 bag to move to, you'll have to adapt this for the sub you're using
}
set %PotashCrafted %PotashCrafted + 1
until %PotashCrafted >= %StopHere ; this will make the crafting stop once the amount crafted equals or exceeds the amount setup at the top of the script
Hope this is clear. Of course this is a simple view of what to do, you could add more functionality to it depending on your needs. Let me know if this helps you get started.
PS: I stole TM's colors!! :P
-
Haha! With SMF 2.0, we get that context coloring
-
You could do something like this:
set %StopHere 500 ; let's say you wish to stop crafting after 500 items are crafted
set %PotashCrafted 0 ; this is going to be the counter for the amount of items you have crafted
repeat
gosub CraftPotash ; suppose you have a sub that will craft the item
finditem #Potash C_ , #backpackid
if #findcnt >= 100
{
gosub moveresource #findstack #backpackid %resource ; for this case the sub would have to be: %1 quantity to move, %2 bag to move from, %3 bag to move to, you'll have to adapt this for the sub you're using
}
set %PotashCrafted %PotashCrafted + 1
until %PotashCrafted >= %StopHere ; this will make the crafting stop once the amount crafted equals or exceeds the amount setup at the top of the script
Hope this is clear. Of course this is a simple view of what to do, you could add more functionality to it depending on your needs. Let me know if this helps you get started.
PS: I stole TM's colors!! :P
I am not sure how to best fit that in to be honest. I am heading to work and won't be able to really look at it till I get home. Here is what I have, maybe you can tell me if it will mesh with my code which I am sure is messy as I am taking different subs and trying to make them work for me. The good thing is that I am learning a lot of the commands and how to set things up. I am a dive into the deep and see what happens end type of person lol. So far the script runs smooth, still trying to iron out the kinks. I am learning about menus so I can add the other high seas ship crafting stuff but not until I get this down. Suggestions are welcomed.
;=========================================
Start:
Gosub Setup
;=========================================
Mainloop:
Repeat
{
gosub MakePotash
}
Until #CharGhost = Yes
Halt
;========================Sub Make TinkerKit==============================================
Sub MakeTinkerKit
MakeKitLoop:
finditem %Ingots C_ , #backpackid
if #findstack < 10
{
set %quantityinpack 10 - #findstack
Gosub Move_Resource_To_Container %Ingots 0 %ResourceSecure #BackpackID %quantityinpack
If ! #Result
{
display You need to place more ingots in your Resource Secure and hit play.
pause
GoTo MakeKitLoop
}
}
finditem %TinkerTools C_ , #backpackid
set #lobjectid #findid
event macro 17
gosub waitforgump %cwin
if ! #result
{
Display Dbl Click a tinker kit in your backpack and hit play
Pause
}
Gosub OffSetClick 30 130
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
Gosub OffSetClick 230 130 f
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
Gosub OffSetClick 230 130 f
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
Gosub Skillcheck
Return
;======================Sub Make MortarPestle================================================
Sub MakeMortarPestle
MakeMortarPestleLoop:
finditem %Ingots C_ , #backpackid
if #findstack < 10
{
set %quantityinpack 10 - #findstack
Gosub Move_Resource_To_Container %Ingots 0 %ResourceSecure #BackpackID %quantityinpack
If ! #Result
{
display You need to place more ingots in your Resource Secure and hit play.
pause
GoTo MakeMortarPestleLoop
}
}
finditem %TinkerTools C_ , #backpackid
set #lobjectid #findid
If #findcnt < 2
gosub MakeTinkerKit
event macro 17
gosub waitforgump %cwin
if ! #result
{
Display Dbl Click a tinker tool in your backpack and hit play
Pause
}
gosub OffsetClick 27 129
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
Gosub OffSetClick 232 89 f
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
Gosub OffSetClick 281 451 f
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
Gosub OffSetClick 281 451 f
gosub waitforgump %cwin
if ! #result
{
GoTo MakeKitLoop
}
GoSub MakePotash
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
}
finditem %Potash C_ , #backpackid
If #findcnt > 100
{
set %quantityinpack 100 - #findstack
Gosub Move_Resource_To_Container %Potash 1 %ResourceSecure #BackpackID %quantityinpack
}
Return
;================== Wait for gump ======================
sub waitforgump
set %timeout #scnt + 10
while #contsize <> %1
{
wait 1
if #scnt > %timeout
{
return #false
}
}
wait %gumpwait
return #true
;================== Wait for Target Cursor ================
sub WaitForTargetCursor
set %timeout #scnt + 4
Repeat
wait %targetcursorwait
if #scnt > %timeout
return #false
Until #TARGCURS = 1
return #true
;==========================================================
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 OffsetClick
set %tempx %1 + #CONTPOSX
set %tempy %2 + #CONTPOSY
click %tempx %tempy f
return
;============================================
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 Setup
set %TinkerTools JTL_GTL_KTL
Set %Tongs OBG
Set %Boards TLK
Set %MortarPestle RQF
Set %EmptyPitcher WYF
Set %FullPitcher VBM
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
;GoSub Dump
; INITIAL SETUP
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 InitTinkerGump
Return
-
Okay I think I have adjusted the move resource properly to match my move resource 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
Here is my adjust attempt to move bases on moveresource sub
;================================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 #Potash C_ , #backpackid
if #findcnt >= 100
{
set %quantityinpack 100 - #findstack
gosub Move_Resource_To_Container %Potash 1102 #backpackid %ResourceSecure %quantityinpack
}
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
}
Return
It doesn't seem to be working though so I have done something wrong there. I am wondering about the 1102 between the %Potash and the %backpackid. The sub calls for a color to be there and I am guessing for ingots and ore "0" stands for regular ore which runs fine. When I used TM's FindInfoTool there was a section marked 'FINDCOL" and had 1102 so I am guessing that is the color.
As far as the code to enter in an amount to make, I have no clue at that time where to place it. It does not look like a sub, looks like it might go in the MakePotash sub but then again looks like it could be part of the setup as well. I am pulling out what hair I have left, which isn't much lol.
-
Thx Neo for the example. I will try to clean up a old script with this type of writing. still trying to figure how to ue those %1 %2 and %3 . I get lose often with those. :(