|
This is the crafting script I used when I played SWG. I quit playing a few months ago, so some things might have changed in the client which breaks the script, but it will get you a long way.
Make sure you read the header part of the script as it explains what you have to do to get the script to work properly in the game (window positioning, theme, etc.)
One thing to note are the calls to AddResource. You'll need to edit the function and add as many AddResource calls as you need. If the schematic takes 6 resources, you need to call AddResource 6 times. I never got around to making a constant for it and just edited the script each time I wanted to make something new.
Make sure the icons in the windows are the default size and you haven't zoomed out to show a lot more or anything.
The script also assumes your windows are not partially transparent (translucent). You want your UI to be opaque as possible - there was a slider to change the opacity somewhere and just make sure it's as opaque as it'll let you go.
If you have any questions, just post a response and I'll reply as time permits.
<-- Script Starts Here -->
' =============================================================================
' SWG Crafting Macro for XUnleashed
' -----------------------------------------------------------------------------
'
' This crating macro is currently set to work with the Rebel UI style colors
' for the interface. If you don't use Rebel, you'll need to find the correct
' colors for BUTTON_COLOR
'
' In addition, every crafting window needs to be moved to the top left corner
' of the screen in game and then needs to be resized to the smallest size. The
' only exception to this is the window where you add resources. It needs to
' still be placed in the upper left corner, have it's width set to the smallest
' size possible, but drag it's bottom edge down as far as it will go. If the
' windows are not set exactly like this, the current macro will not work.
'
' =============================================================================
Option Explicit
' -----------------------------------------------------------------------------
' Constants
' -----------------------------------------------------------------------------
Const ITEMS_TO_CRAFT = 45 ' The number of items to make
Const DRAFT_SCHEMATIC = 7 ' The schematic number for the item to craft
Const PRACTICE_MODE = True ' Want the crafting to be in Practice mode?
Const NUM_CRAFTING_TOOLS = 7 ' The number of crafting tools to use
Const BUTTON_COLOR = 2728184 ' The color to look for on a continue button
Const LOOP_COUNTER_MAX = 100 ' 10 second max wait
Const CRITICAL_FAILURE_MAX = 5 ' Max of 5 critical failures before stopping
Const ENTER = 13
Const F1 = 112
' -----------------------------------------------------------------------------
' Global Variables
' -----------------------------------------------------------------------------
Dim resourceCount
Dim yellowColor
' =============================================================================
' The function which starts crafting
' -----------------------------------------------------------------------------
' This function needs all of the crafting tools in the top row of toolbar
' slots. You need the first NUM_CRAFTING_TOOLS slots with a crafting tool
' in it.
' =============================================================================
Sub CraftItems()
Dim itemCount
Dim tool
For itemCount = 0 To ITEMS_TO_CRAFT - 1
tool = itemCount Mod NUM_CRAFTING_TOOLS
If StartCraftingTool(CInt(F1) + CInt(tool)) = True Then
If SelectDraftSchematic(DRAFT_SCHEMATIC) = True Then
If CraftItem = False Then
Exit Sub
End If
End If
End If
Next
End Sub
' =============================================================================
' The function starts up a crafting tool and waits for it to load
' -----------------------------------------------------------------------------
' str = the key to press to start the crafting tool
' =============================================================================
Function StartCraftingTool(key)
XUScriptPlugin.staStatus.Text = "Starting crafting tool"
XUScriptPlugin.Window.Invalidate
XUScriptHost.Sleep 1000
PressKey key
XUScriptPlugin.staStatus.Text = "Waiting for color"
XUScriptPlugin.Window.Invalidate
StartCraftingTool = WaitForColorAtLocation(BUTTON_COLOR, 463, 296)
XUScriptHost.Sleep 50
End Function
' =============================================================================
' Select the draft schematic for the crafting tool
' -----------------------------------------------------------------------------
' index = the index number for the schematic to use in the tool
' =============================================================================
Function SelectDraftSchematic(index)
SendString "/selectDraftSchematic " & CStr(index)
XUScriptHost.Sleep 50
PressKey ENTER
SelectDraftSchematic = WaitForColorAtLocation(BUTTON_COLOR, 579, 750)
XUScriptHost.Sleep 50
End Function
' =============================================================================
' The function to actually craft an item
' -----------------------------------------------------------------------------
' =============================================================================
Function CraftItem()
If HandleResourceDialog = False Then
CraftItem = False
Exit Function
End If
If HandleCraftingSummaryDialog = False Then
CraftItem = False
Exit Function
End If
' If HandleCreatePrototypeDialog = False Then
' CraftItem = False
' Exit Function
' End If
If HandleItemCustomizationDialog = False Then
CraftItem = False
Exit Function
End If
XUScriptHost.Sleep 100
CraftItem = True
End Function
' =============================================================================
' Handle the Resource Dialog
' -----------------------------------------------------------------------------
' =============================================================================
Function HandleResourceDialog()
Dim loopCounter
Dim loopCounterContinue
Dim bCritical
For loopCounter = 0 To CRITICAL_FAILURE_MAX
bCritical = False
' ---------------------------------------------------------------------
' Add the required resources
' ---------------------------------------------------------------------
resourceCount = 0
AddResource 1
AddResource 1
AddResource 2
If WaitForResourcesToLoad = False Then
HandleResourceDialog = False
Exit Function
End If
PressKey ENTER
For loopCounterContinue = 0 To LOOP_COUNTER_MAX * 2 ' Wait for either
' the critical failure dialog or
' or crafting summary dialog to
' appear, then continue
XUScriptHost.Sleep 100
If XUScriptHost.GetPixelColor(321, 386) = BUTTON_COLOR Then
Exit For
ElseIf CheckForCriticalFailure(BUTTON_COLOR, 508, 397) = True Then
bCritical = True
Exit For
End If
Next
If bCritical = False Then
Exit For
End If
XUScriptHost.Sleep 100
Next
HandleResourceDialog = True
End Function
' =============================================================================
' Add a resource
' -----------------------------------------------------------------------------
' index = 0 based index of resource to add
' =============================================================================
Sub AddResource(index)
Dim x
Dim y
x = index Mod 2
x = x * 68
x = x + 52
y = index \ 2
y = y * 68
y = y + 140
DoubleClickAtLocation x, y
resourceCount = resourceCount + 1
End Sub
' =============================================================================
' WaitForResourcesToLoad
' -----------------------------------------------------------------------------
' =============================================================================
Function WaitForResourcesToLoad()
Dim loopCounter
Dim resourceIndex
Dim resourcesLoaded
For loopCounter = 0 To LOOP_COUNTER_MAX * 2
XUScriptHost.Sleep 100
resourcesLoaded = True
For resourceIndex = 0 To resourceCount - 1
resourcesLoaded = resourcesLoaded And IsResourceLoaded(resourceIndex)
Next
If resourcesLoaded = True Then
Exit For
End If
Next
If resourcesLoaded = True Then
WaitForResourcesToLoad = True
Else
WaitForResourcesToLoad = False
End If
End Function
' =============================================================================
' Check to see if a resource is loaded
' -----------------------------------------------------------------------------
' index = 0 based index of resource to check
' =============================================================================
Function IsResourceLoaded(index)
Dim x
Dim y
x = index Mod 2
x = x * 125
x = x + 228
y = index \ 2
y = y * 114
y = y + 100
Dim pixelColor
pixelColor = XUScriptHost.GetPixelColor(CInt(x), CInt(y))
' Check to see if it's an orange color, but to orange
If GetBlueValue(pixelColor) >= 4 And GetBlueValue(pixelColor) <= 12 Then
If GetGreenValue(pixelColor) > 73 And GetGreenValue(pixelColor) < 93 Then
If GetRedValue(pixelColor) > 125 And GetRedValue(pixelColor) < 150 Then
IsResourceLoaded = True
Exit Function
End If
End If
End If
IsResourceLoaded = False
End Function
' =============================================================================
' Handle the Crafting Summary Dialog
' -----------------------------------------------------------------------------
' =============================================================================
Function HandleCraftingSummaryDialog()
' Press enter on the crafting summary dialog
If WaitForColorAtLocation(BUTTON_COLOR, 309, 386) = False Then
HandleCraftingSummaryDialog = False
Exit Function
End If
XUScriptHost.Sleep 100
PressKey ENTER
HandleCraftingSummaryDialog = True
End Function
' =============================================================================
' Handle the Create Prototype Dialog
' -----------------------------------------------------------------------------
' =============================================================================
Function HandleCreatePrototypeDialog()
' Select to create a prototype on the Finish Crafting Dialog
If WaitForColorAtLocation(BUTTON_COLOR, 151, 115) = False Then
HandleCreatePrototypeDialog = False
Exit Function
End If
ClickAtLocation 151, 115
XUScriptHost.Sleep 100
HandleCreatePrototypeDialog = True
End Function
' =============================================================================
' Handle the Item Customization Dialog
' -----------------------------------------------------------------------------
' =============================================================================
Function HandleItemCustomizationDialog()
Dim loopCounterContinue
If WaitForColorAtLocation(BUTTON_COLOR, 676, 440) = False Then ' Was 398, 440
HandleItemCustomizationDialog = False
Exit Function
End If
XUScriptHost.Sleep 100
' Make sure the dialog is in Practice mode if the script calls for it
If PRACTICE_MODE = True Then
If XUScriptHost.GetPixelColor(646, 440) = BUTTON_COLOR Then
ClickAtLocation 40, 436 ' Click in the checkbox
XUScriptHost.Sleep 100
End If
Else
If XUScriptHost.GetPixelColor(646, 440) <> BUTTON_COLOR Then
ClickAtLocation 40, 436 ' Click in the checkbox
XUScriptHost.Sleep 100
End If
End If
' Press enter on the item customization dialog
PressKey ENTER
' Now we try and determine when the crafting tools stops by
' looking for a yellow color on the last dialog it displays
If WaitForYellowColorAtLocation(647, 373) = True Then
' Loop until it goes away
If WaitForYellowColorToGoAwayAtLocation(647, 373) = False Then
HandleItemCustomizationDialog = False
Exit Function
End If
Else
HandleItemCustomizationDialog = False
Exit Function
End If
XUScriptHost.Sleep 250
HandleItemCustomizationDialog = True
End Function
' =============================================================================
' Check for a critical failure
' -----------------------------------------------------------------------------
' color = color of the pixel on the screen
' x = x coordinate of the pixel on the screen
' y = y coordinate of the pixel on the screen
' =============================================================================
Function CheckForCriticalFailure(color, x, y)
If XUScriptHost.GetPixelColor(CInt(x), CInt(y)) = color Then
ClickAtLocation CInt(x), CInt(y) ' Clear the dialog
CheckForCriticalFailure = True
Exit Function
End If
CheckForCriticalFailure = False
End Function
' =============================================================================
' Wait for a color to appear at a particular position on the screen
' -----------------------------------------------------------------------------
' color = color of the pixel on the screen
' x = x coordinate of the pixel on the screen
' y = y coordinate of the pixel on the screen
' =============================================================================
Function WaitForColorAtLocation(color, x, y)
Dim loopCounter
For loopCounter = 0 To LOOP_COUNTER_MAX
If XUScriptHost.GetPixelColor(CInt(x), CInt(y)) = color Then
WaitForColorAtLocation = True
Exit Function
End If
XUScriptHost.Sleep 100
Next
WaitForColorAtLocation = False
End Function
' =============================================================================
' Wait for a yellow color to appear at a particular position on the screen
' -----------------------------------------------------------------------------
' x = x coordinate of the pixel on the screen
' y = y coordinate of the pixel on the screen
' =============================================================================
Function WaitForYellowColorAtLocation(x, y)
Dim color
Dim loopCounter
For loopCounter = 0 To LOOP_COUNTER_MAX * 4
color = XUScriptHost.GetPixelColor(CInt(x), CInt(y))
XUScriptPlugin.Window.Title = "Waiting for yellow"
XUScriptPlugin.staStatus.Text = "R: " & XUScriptHost.ExtractRGB_Red(color) & " G: " & XUScriptHost.ExtractRGB_Green(color) & " B: " & XUScriptHost.ExtractRGB_Blue(color)
XUScriptPlugin.Window.Invalidate
If GetRedValue(color) > 227 And GetGreenValue(color) > 167 And GetGreenValue(color) < 200 Then
yellowColor = color
WaitForYellowColorAtLocation = True
Exit Function
End If
XUScriptHost.Sleep 75
Next
WaitForYellowColorAtLocation = False
End Function
' =============================================================================
' Wait for a yellow color to go away at a particular position on the screen
' -----------------------------------------------------------------------------
' x = x coordinate of the pixel on the screen
' y = y coordinate of the pixel on the screen
' =============================================================================
Function WaitForYellowColorToGoAwayAtLocation(x, y)
Dim color
Dim loopCounter
For loopCounter = 0 To LOOP_COUNTER_MAX * 4
color = XUScriptHost.GetPixelColor(CInt(x), CInt(y))
If color <> yellowColor Then
XUScriptPlugin.staStatus.Text = "Yellow went away"
XUScriptPlugin.Window.Invalidate
WaitForYellowColorToGoAwayAtLocation = True
Exit Function
End If
XUScriptHost.Sleep 50
Next
WaitForYellowColorToGoAwayAtLocation = False
End Function
' =============================================================================
' Click the left mouse button on a location on the screen
' -----------------------------------------------------------------------------
' x = x coordinate of the point to double click
' y = y coordinate of the point to double click
' =============================================================================
Sub ClickAtLocation(x, y)
XUScriptHost.MouseMove CInt(x), CInt(y)
XUScriptHost.Sleep 100
XUScriptHost.LMouseDown CInt(x), CInt(y)
XUScriptHost.LMouseUp CInt(x), CInt(y)
XUScriptHost.Sleep 100
End Sub
' =============================================================================
' Double click the left mouse button on a location on the screen
' -----------------------------------------------------------------------------
' x = x coordinate of the point to double click
' y = y coordinate of the point to double click
' =============================================================================
Sub DoubleClickAtLocation(x, y)
XUScriptHost.MouseMove CInt(x), CInt(y)
XUScriptHost.Sleep 100
XUScriptHost.LMouseDown CInt(x), CInt(y)
XUScriptHost.LMouseUp CInt(x), CInt(y)
XUScriptHost.LMouseDown CInt(x), CInt(y)
XUScriptHost.LMouseUp CInt(x), CInt(y)
XUScriptHost.Sleep 100
End Sub
' =============================================================================
' Press the specified key
' -----------------------------------------------------------------------------
' key = the key code of the key to press
' =============================================================================
Sub PressKey(key)
XUScriptHost.KeyDown CInt(key)
XUScriptHost.KeyUp CInt(key)
End Sub
' =============================================================================
' Get the Red Color from a Pixel
' -----------------------------------------------------------------------------
' color = pixel color
' =============================================================================
Function GetRedValue(color)
GetRedValue = (color Mod 256)
End Function
' =============================================================================
' Get the Green Color from a Pixel
' -----------------------------------------------------------------------------
' color = pixel color
' =============================================================================
Function GetGreenValue(color)
GetGreenValue = (color \ 256) And 255
End Function
' =============================================================================
' Get the Blue Color from a Pixel
' -----------------------------------------------------------------------------
' color = pixel color
' =============================================================================
Function GetBlueValue(color)
GetBlueValue = (color \ 65536) And 255
End Function
' =============================================================================
' Send a string to the program
' -----------------------------------------------------------------------------
' str = the string to send
' =============================================================================
Sub SendString(str)
Dim length
Dim index
length = Len(str)
For index = 1 To length
SendCharacter Asc(Mid(str, index, 1))
Next
End Sub
' =============================================================================
' Send a string to the program
' -----------------------------------------------------------------------------
' str = the string to send
' =============================================================================
Sub SendCharacter(value)
If value = 47 Then ' / key
PressKey(111)
ElseIf value >= 97 And value <= 122 Then ' a - z
PressKey value - 97 + 65
ElseIf value >= 65 And value <= 90 Then ' A - Z
XUScriptHost.KeyDown 160
PressKey value
XUScriptHost.KeyUp 160
ElseIf value >= 48 And value <= 57 Then ' 0 - 9
PressKey value
ElseIf value = 32 Then ' space
PressKey value
End If
End Sub
CraftItems
<-- Script Ends Here -->
Good luck! It worked amazingly well when I used to use it.
|