# calculate exactly how many trips we're making # and how much we're carrying on our last trip setVar $trips $quantity divide $trips $holds setVar $x $trips multiply $x $holds setVar $lastTrip $quantity subtract $lastTrip $x if ($lastTrip = 0) setVar $lastTrip $holds else add $trips 1 end
addMenu "" "BuyDown" "BuyDown Settings" "." "" "Main" FALSE addMenu "BuyDown" "GO" "GO!" "G" :Menu_Go "" TRUE addMenu "BuyDown" "Product" "Product" "P" :Menu_Product "" FALSE addMenu "BuyDown" "TurnLimit" "Turn limit" "T" :Menu_TurnLimit "" FALSE addMenu "BuyDown" "Quantity" "Quantity" "U" :Menu_Quantity "" FALSE addMenu "BuyDown" "Haggle" "Haggling" "H" :Menu_HaggleFactor "" FALSE gosub :sub_SetMenu openMenu "BuyDown"
setAvoid $enemySector getCourse $course CURRENTSECTOR STARDOCK gosub :mowCourse clearAllAvoids
# don't run script without free cargo holds if ($holds = 0) clientMessage "No free cargo holds!" halt end
# get the name of a planet being landed on getWord CURRENTLINE $ID 2 stripText $ID "#" getWord CURRENTLINE $Sector 5 stripText $Sector ":" getWordPos CURRENTLINE $Pos ": " cutText CURRENTLINE $Name ($Pos + 2) 999
# write dead-end list to a file clientMessage "Querying..." delete deadends.txt setVar $i 1 :next if (SECTOR.WARPS[$i][2] = 0) write "deadends.txt" $i end if ($i > SECTORS) halt end add $i 1 goto :next
# calculate exactly how many trips we're making # and how much we're carrying on our last trip setVar $trips $quantity divide $trips $holds setVar $x $trips multiply $x $holds setVar $lastTrip $quantity subtract $lastTrip $x if ($lastTrip = 0) setVar $lastTrip $holds else add $trips 1 end
# Get a product type using a menu :GetProduct echo "*" ANSI_15 "Select Product:" "**" echo ANSI_11 "1 " ANSI_3 " - Fuel Ore*" echo ANSI_11 "2 " ANSI_3 " - Organics*" echo ANSI_11 "3 " ANSI_3 " - Equipment*" getConsoleInput $Product SINGLEKEY if ($Product <> 1) and ($Product <> 2) and ($Product <> 3) goto :GetProduct end
# load bust list if ($BustFile <> "") fileExists $exists $BustFile if ($exists) setArray $BustList SECTORS setVar $i 1 read $BustFile $bust $i while ($bust <> EOF) setVar $BustList[$bust] 1 add $i 1 read $BustFile $bust $i end end end
# determine the time elapsed between two string values format "4/27/2013 14:20:00" $dateTime1 STRTODATETIME setVar $now DATE & " " & TIME \\ date and time are TWX constants format $now $dateTime2 STRTODATETIME setPrecision 10 setVar $elapsed ($dateTime2 - $dateTime1) echo "*Elapsed: " $elapsed
# Locate all unfigged sectors 8 hops from Terra and show the course setVar $hops 8 getAllCourses $courses 1 setVar $a 1 while ($a <= SECTORS) if ($courses[$a] = $hops) and ($figGrid[$a] = 0) echo "*" $a ", Course:" setVar $b 1 while ($b <= ($courses[$a] + 1)) echo " " $courses[$a][$b] add $b 1 end end add $a 1 end
# Get a product type using a menu :GetProduct echo "*" ANSI_15 "Select Product:" "**" echo ANSI_11 "1 " ANSI_3 " - Fuel Ore*" echo ANSI_11 "2 " ANSI_3 " - Organics*" echo ANSI_11 "3 " ANSI_3 " - Equipment*" getConsoleInput $Product SINGLEKEY if ($Product <> 1) and ($Product <> 2) and ($Product <> 3) goto :GetProduct end
# plot and display a warp course getInput $fromSector "Enter a sector to plot from" getInput $toSector "Enter a sector to plot to" getCourse $course $fromSector $toSector setVar $i 0 while ($i <= course) echo $course[$i] " " add $i 1 end
# Search the logs to find any Starports that have been initiated. getFileList $logs "logs\*" & GAMENAME & ".log" # if 20 files where found, the variable '$logs' now equals 20. # $logs[1] is the 1st file name, $logs[2] the 2nd, and so on. echo "*A total of " $logs " Logs found." setVar $a 1 while ($a <= $logs) echo "**Now Searching file " $logs[$a] "..." readToArray "logs\" & $logs[$a] $linesArray setVar $b 1 while ($b <= $linesArray) getWordPos $linesArray[$b] $pos "began construction!" if ($pos > 0) echo "*" $linesArray[$b] add $newPortCount 1 end add $b 1 end add $a 1 end echo "**Complete, " $newPortCount " ports have been logged.*"
# input parameters getInput $sectorNumber2 "Enter other sector to SSM from" getInput $holds "Enter max holds to steal"
# Find the closest figged sector getNearestWarps $nearArray CURRENTSECTOR setVar $i 1 while ($i <= $nearArray) setVar $focus $nearArray[$i] if ($figGrid[$focus] > 0) echo "*NearFig: " $i "*" return end add $i 1 end
# Check compiled script's version before opening getScriptVersion "scripts/buydown.cts" $ver if ($ver <> 4) echo "*You need to update the buydown.cts file*" else load "scripts/buydown.cts" end
# write dead-end list to a file clientMessage "Querying..." delete deadends.txt setVar $i 1 :next getSector $i $i if ($i.warp[2] = 0) write "deadends.txt" $i end if ($i > SECTORS) halt end add $i 1 goto :next
# show all sectors that have been marked as enemy territory setVar $i 1 while ($i <= SECTORS) getSectorParameter $i "Owner" $owner if ($owner = "Enemy") echo $i "*" end end
setVar $line "This is a test line to copy text from" getText $line $value "line to " " text from" # displays: "copy" echo $value
getTime $test "'The time is :' h:m:s, ' the date is :' d:m:yyyy'" # displays: The time is : 12:22:28, the date is : 11:4:2003 echo $test
getTimer $startTicks # Perform some routine here getTimer $stopTicks setVar $durationTicks ($stopTicks - $startTicks) # Now divide by CPU Hz if you need to convert Ticks to seconds. (2.2 GHz here) # You will need to set the precision according to your desired accuracy, before dividing. setPrecision 18 setVar $seconds ($durationTicks / 2200000000) setPrecision 0 echo "*Time lapse in Seconds: " $seconds "*"
setVar $line "This is a line of text" getWord $line $word 4 # displays: line echo $word
setVar $line "This is a line of text" getWordPos $line $pos "line" # displays: 11 echo $pos
# gosub/return demo: echo "This is a gosub/return demo. I'm going to branch to a subroutine." gosub :subroutine echo "I've just returned from my subroutine" halt :subroutine echo "I'm in my subroutine" return
# Goto example: echo "About to jump to another part of my script" goto :otherPart echo "I should never execute this command" :otherPart echo "I've just jumped to a different part of my script" halt
:PlanetsPerSector getInput $value "Enter number of planets per sector" isNumber $test $value if ($test = 0) echo ANSI_15 "**Value must be a number*" goto :PlanetsPerSector end setVar $build_planetsPerSector $value saveVar $build_planetsPerSector
# see if we have a planet scanner setVar $scanner 0 send "i" setTextLineTrigger 1 :HasScanner "Planet Scanner" setTextTrigger 2 :DoneTest "Command [TL=" pause :HasScanner setVar $scanner 1 killTrigger 2 :DoneTest killTrigger 1
# Stop FastFoton.ts if it is running listActiveScripts $scripts setVar $a 1 while ($a <= $scripts) if ($scripts[$a] = "FastFoton.ts") stop $scripts[$a] return end add $a 1 end
# Clear any avoid with our fig present listAvoids $voids setVar $a 1 while ($a <= $voids) setVar $focus $voids[$a] if ($figGrid[$focus] > 0) clearAvoid $focus end add $a 1 end
# Delete all Sector Parameters from the Database setVar $a 1 while ($a <= SECTORS) listSectorParameters $a $parms setVar $b 1 while ($b <= $parms) setSectorParameter $parms[$b] "" add $b 1 end add $a 1 end
# get defaults loadVar $EvilSaved if ($EvilSaved) loadVar $evil_stealFactor loadVar $evil_robFactor loadVar $evil_continue loadVar $evil_broadcast loadVar $evil_shipsetup loadVar $evil_haggle else setVar $evil_stealFactor 30 setVar $evil_robFactor 3 setVar $evil_continue 1 setVar $evil_broadcast 1 setVar $evil_shipSetup "" setVar $evil_haggle 1 saveVar $evil_stealFactor saveVar $evil_robFactor saveVar $evil_continue saveVar $evil_broadcast saveVar $evil_shipSetup saveVar $evil_haggle setVar $EvilSaved 1 saveVar $EvilSaved end
# calculate exactly how many trips we're making # and how much we're carrying on our last trip setVar $trips $quantity divide $trips $holds setVar $x $trips multiply $x $holds setVar $lastTrip $quantity subtract $lastTrip $x if ($lastTrip = 0) setVar $lastTrip $holds else add $trips 1 end
openMenu TWX_LISTACTIVE FALSE addMenu "" "BuyDown" "BuyDown Settings" "." "" "Main" FALSE addMenu "BuyDown" "GO" "GO!" "G" :Menu_Go "" TRUE addMenu "BuyDown" "Product" "Product" "P" :Menu_Product "" FALSE addMenu "BuyDown" "TurnLimit" "Turn limit" "T" :Menu_TurnLimit "" FALSE addMenu "BuyDown" "Quantity" "Quantity" "U" :Menu_Quantity "" FALSE addMenu "BuyDown" "Haggle" "Haggling" "H" :Menu_HaggleFactor "" FALSE gosub :sub_SetMenu openMenu "BuyDown"
# see if we have a planet scanner setVar $scanner 0 send "i" setTextLineTrigger 1 :HasScanner "Planet Scanner" setTextTrigger 2 :DoneTest "Command [TL=" pause :HasScanner setVar $scanner 1 killTrigger 2 :DoneTest killTrigger 1
# load bust list if ($BustFile <> "") fileExists $exists $BustFile if ($exists) setArray $BustList SECTORS setVar $i 1 read $BustFile $bust $i while ($bust <> EOF) setVar $BustList[$bust] 1 add $i 1 read $BustFile $bust $i end end end
# Read a text file into an array readToArray figlist.txt $figArray # A variable $figArray also exists, and is equal to the element count echo "*Figged Sectors read:" $figArray setVar $i 1 while ($i <= $figArray) echo "*" $figArray[$i] add $i 1 end
# gosub/return demo: echo "This is a gosub/return demo. I'm going to branch to a subroutine." gosub :subroutine echo "I've just returned from my subroutine" halt :subroutine echo "I'm in my subroutine" return
setPrecision 2 setVar $x "500.52" round $x 1 # this line will display: 500.5 echo $x
# get defaults loadVar $EvilSaved if ($EvilSaved) loadVar $evil_stealFactor loadVar $evil_robFactor loadVar $evil_continue loadVar $evil_broadcast loadVar $evil_shipsetup loadVar $evil_haggle else setVar $evil_stealFactor 30 setVar $evil_robFactor 3 setVar $evil_continue 1 setVar $evil_broadcast 1 setVar $evil_shipSetup "" setVar $evil_haggle 1 saveVar $evil_stealFactor saveVar $evil_robFactor saveVar $evil_continue saveVar $evil_broadcast saveVar $evil_shipSetup saveVar $evil_haggle setVar $EvilSaved 1 saveVar $EvilSaved end
# load bust list if ($BustFile <> "") fileExists $exists $BustFile if ($exists) setArray $BustList SECTORS setVar $i 1 read $BustFile $bust $i while ($bust <> EOF) setVar $BustList[$bust] 1 add $i 1 read $BustFile $bust $i end end end
# One way of showing the backdoor to Stardock setVar $a 1 while ($a <= SECTOR.WARPCOUNT[STARDOCK]) # Avoids warps out of StarDock setAvoid SECTOR.WARPS[STARDOCK][$a] add $a 1 end getCourse $course 1 STARDOCK if ($course = 0) echo "*No Backdoor found.*" else # $course is the number of hops. Since the $course array # is $hops + 1, it is also the next-to-last warp echo "*Backdoor: " $course[$course] end
:wait send "#" setDelayTrigger delay :wait 60000 pause
:sub_SetMenu if ($evil_haggle) setMenuValue "Haggling" "ON" else setMenuValue "Haggling" "OFF" end if ($evil_continue > 0) setMenuValue "Continue" "YES" else setMenuValue "Continue" "NO" end if ($evil_broadcast > 0) setMenuValue "Broadcast" "YES" else setMenuValue "Broadcast" "NO" end setMenuValue "StealFactor" $evil_stealFactor setMenuValue "RobFactor" $evil_robFactor setMenuValue "ShipSetup" $evil_shipSetup setMenuValue "QuickSetup" $evil_shipSetup return
# This will set precision to a max of 10 decimal places setPrecision 10
# set the current sector as being enemy territory setTextLineTrigger getSector :getSector "Sector : " pause :getSector getWord CURRENTLINE $sector 3 setSectorParameter $sector "Owner" "Enemy"
# see if we have a planet scanner setVar $scanner 0 send "i" setTextLineTrigger 1 :HasScanner "Planet Scanner" setTextTrigger 2 :DoneTest "Command [TL=" pause :HasScanner setVar $scanner 1 killTrigger 2 :DoneTest killTrigger 1
# see if we have a planet scanner setVar $scanner 0 send "i" setTextLineTrigger 1 :HasScanner "Planet Scanner" setTextTrigger 2 :DoneTest "Command [TL=" pause :HasScanner setVar $scanner 1 killTrigger 2 :DoneTest killTrigger 1
# calculate exactly how many trips we're making # and how much we're carrying on our last trip setVar $trips $quantity divide $trips $holds setVar $x $trips multiply $x $holds setVar $lastTrip $quantity subtract $lastTrip $x if ($lastTrip = 0) setVar $lastTrip $holds else add $trips 1 end
# Create ZTM progress window - as managed in 1_ZTM.ts window ztm 170 94 "ZTM" ONTOP setWindowContents ztm "Perc Done:*Est Time:*Speed:*Up to:"
# play a sound sound click.wav
# load then terminate keepalive script (completely useless) load 1_keepalive stop 1_keepalive
# break a line of text into the individual words splitText "This is a line of text." $words stop 1_keepalive
# stripText example: setVar $value "This is my value" stripText $value "my " # displays: This is value echo $value
# calculate exactly how many trips we're making # and how much we're carrying on our last trip setVar $trips $quantity divide $trips $holds setVar $x $trips multiply $x $holds setVar $lastTrip $quantity subtract $lastTrip $x if ($lastTrip = 0) setVar $lastTrip $holds else add $trips 1 end
waitfor "(ENTER for none):" send LoginName "*" waitfor "Trade Wars 2002 Game Server" send Game waitfor "module now loading." send "*t***" Password "*"
# Create ZTM progress window - as managed in 1_ZTM.ts window ztm 170 94 "ZTM" ONTOP setWindowContents ztm "Perc Done:*Est Time:*Speed:*Up to:"
Usage: IF (expression) ... ELSEIF ... ELSE ... END Description: This macro will write micro-commands to perform a standard 'if' comparison. All the commands under the 'IF' section of this structure will only be executed if the expression evaluates to true. The commands under the 'ELSEIF' will only be executed if the primary expression results to false, and 'ELSEIF' expression results to true. The commands under the 'ELSE' structure will only be executed if no other part of the structure has been. Example: IF ($x = "Hello") echo "Hello there!" ELSEIF ($x = "Bye") echo "Bye!" ELSE echo "I didn't hear you!" END
Usage: INCLUDE scriptname Description: This macro will include the code from another script or pack2 include file during compilation. Example: include "includemove"
Usage: WAITON text Description: This macro will write the commands to create a temporary TextTrigger. This can be used as a substitute for a waitFor command that will not be 'broken' if another trigger activates while the script is waiting for text. Example: waitOn "Command [TL="
Usage: WHILE (expression) ... END Description: This macro will create a standard 'while' loop. All the commands within this loop will continue to be repeated until the expression evaluates to false. Example: setVar $x 1 WHILE ($x < 10) echo "Counting: " & $x & "*" add $x 1 END