View unanswered posts | View active topics It is currently Thu Apr 18, 2024 10:12 pm



Reply to topic  [ 14 posts ] 
 My first TWX script. 
Author Message
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post My first TWX script.
Even reading TWX script gives me a headache, so I swore I would never write anything in TWX script, but I have fallen to the DARK SIDE :(

This script sends M()MBOT "Status" commands over SubSpace, parses the status reports, and displays a combined status report for the whole team. The report is sent over subspace, and displayed locally in color.

Your comments and suggestions are welcome :)

Image

Code:
:GetStatus
  loadVar $Team~BotList
 
  If ($Team~BotList = 0)
    getInput $Team~BotList "Please enter bot names seperated by spaces."
    saveVar $Team~BotList
  end

  echo ANSI_14 "Collecting Data...**"
 
setVar $i  1
:Loop1
  getWord $Team~BotList $TeamStatus~BotName[$i] $i
  #saveVar TeamStatus$BotName[$i]

  if ($TeamStatus~BotName[$i] <> 0)
    send "'" $TeamStatus~BotName[$i]  " Status*"
    Gosub :LoadStatus
    add $i 1
    goto :Loop1
  end

# Send Status over SubSpace
  send "'* *Player       Sector  Prompt   Turns   PH Mode     IG  Ship LP Time*"
  send "------------ ------- -------- ------- -- -------- --- ---- -- -------*"

setVar $i  1
:Loop2
# Only use left 4 characters of the bot name.
cutText "{" & $TeamStatus~BotName[$i] $BotName 1 5
cutText $BotName & "}  " $BotName 1 6

  if ($TeamStatus~BotName[$i]  <> 0)
    send $TeamStatus~Player[$i]
    send $BotName " "
    if $TeamStatus~OnPlanet[$i]
      cutText $TeamStatus~Sector[$i] & "P      " $Sector 1 7   
    else
      cutText $TeamStatus~Sector[$i] & "      " $Sector 1 7   
    end
    send $Sector " "
    send $TeamStatus~Prompt[$i] " "
    send $TeamStatus~Turns[$i] " "
    send $TeamStatus~Photons[$i] " "
    send $TeamStatus~Mode[$i] " "
    send $TeamStatus~IG[$i] " "
    send $TeamStatus~Ship[$i] " "
    send $TeamStatus~LastPlanet[$i] " "
    send $TeamStatus~TimeLeft[$i] "*"
    add $i 1
    goto :Loop2
  end
  send "*"

# Display Status Locally
  subtract $i 1
  WaitFor $TeamStatus~Player[$i] & "{"
  WaitFor "Command [TL"
  echo ANSI_5 "**Player       Sector  Prompt   Turns   PH Mode     IG  Ship LP Time*"
  echo ANSI_15 "------------ ------- -------- ------- -- -------- --- ---- -- -------*"

setVar $i  1
:Loop3
# Only use left 4 characters of the bot name.
cutText "{" & $TeamStatus~BotName[$i] $BotName 1 5
cutText $BotName & "}  " $BotName 1 6

  if ($TeamStatus~BotName[$i]  <> 0)
    echo ANSI_11 $TeamStatus~Player[$i]
    echo $BotName " "
    if $TeamStatus~OnPlanet[$i]
      cutText $TeamStatus~Sector[$i] & ANSI_12 & #27 & "[5mP" & #27 & "[0m      " $Sector 1 22   
    else
      cutText $TeamStatus~Sector[$i] & "      " $Sector 1 7   
    end
    echo ANSI_14 $Sector " "
    echo ANSI_10 $TeamStatus~Prompt[$i] " "
    echo ANSI_14 $TeamStatus~Turns[$i] " "
    echo ANSI_13 $TeamStatus~Photons[$i] " "
    echo ANSI_10 $TeamStatus~Mode[$i] " "
    echo ANSI_13 $TeamStatus~IG[$i] " "
    echo ANSI_10 $TeamStatus~Ship[$i] " "
    echo ANSI_13 $TeamStatus~LastPlanet[$i] " "
    echo ANSI_14 $TeamStatus~TimeLeft[$i] "*"
    add $i 1
    goto :Loop3
  end
  halt

:LoadStatus
  WaitFor "--- Status Report ---"
  getWord CURRENTLINE $Channel 1
  if ($Channel = "S:")
    setVar $WordOffset 5
    setVar $TeamStatus~Player[$i] $TraderName
  else
    setVar $WordOffset 6
    getWord CURRENTLINE $TeamStatus~Player[$i] 2
  end
  cutText $TeamStatus~Player[$i] & "      " $TeamStatus~Player[$i] 1 6
 
  killAllTriggers
  setTextTrigger S0 :Trader "Trader Name"
  setTextTrigger S1 :Sector " - Sector"
  setTextTrigger S2 :Prompt " - Prompt"
  setTextTrigger S3 :Turns " - Turns"
  setTextTrigger S4 :Photons " - Photons"
  setTextTrigger S5 :Mode " - Mode"
  setTextTrigger S6 :IG " - IG"
  setTextTrigger S7 :Ship " - Ship"
  setTextTrigger S8 :Planet " - Planet"
  setTextTrigger S9 :LastPlanet " - Last Planet"
  setTextTrigger S10 :Team " - Team"
  setTextTrigger S11 :TimeLeft " - Time Left"
  pause
 
:Trader
  getWord CURRENTLINE $TraderName 5
#  if $TraderName
#   getWord CURRENTLINE $TraderName 5
  #end
  cutText $TraderName & "      " $TraderName 1 6
  goto :LoadStatus

:Sector
  getWord CURRENTLINE $TeamStatus~Sector[$i] $WordOffset
  pause

:Prompt
  getWord CURRENTLINE $TeamStatus~Prompt[$i] $WordOffset
  cutText $TeamStatus~Prompt[$i] & "          " $TeamStatus~Prompt[$i] 1 8
  pause

:Turns
  getWord CURRENTLINE $TeamStatus~Turns[$i] $WordOffset
  cutText $TeamStatus~Turns[$i] & "      " $TeamStatus~Turns[$i] 1 7
  pause

:Photons
  getWord CURRENTLINE $TeamStatus~Photons[$i] $WordOffset
  cutText $TeamStatus~Photons[$i] & "        " $TeamStatus~Photons[$i] 1 2
  pause

:Mode
  getWord CURRENTLINE $TeamStatus~Mode[$i] $WordOffset
  cutText $TeamStatus~Mode[$i] & "          " $TeamStatus~Mode[$i] 1 8
  pause

:IG
  getWord CURRENTLINE $TeamStatus~IG[$i] $WordOffset
  cutText $TeamStatus~IG[$i] & "        " $TeamStatus~IG[$i] 1 3
  pause

:Ship
  getWord CURRENTLINE $TeamStatus~Ship[$i] $WordOffset
  cutText $TeamStatus~Ship[$i] & "        " $TeamStatus~Ship[$i] 1 4
  pause

:Planet
  getWord CURRENTLINE $TeamStatus~LastPlanet[$i] $WordOffset
  cutText $TeamStatus~LastPlanet[$i] & "        " $TeamStatus~LastPlanet[$i] 1 2
  setVar $TeamStatus~OnPlanet[$i] 1
  pause

:LastPlanet
  getWord CURRENTLINE $TeamStatus~LastPlanet[$i] $WordOffset + 1
  cutText $TeamStatus~LastPlanet[$i] & "        " $TeamStatus~LastPlanet[$i] 1 2
  setVar $TeamStatus~OnPlanet[$i] 0
  pause

:Team
  getWord CURRENTLINE $TeamStatus~Team[$i] $WordOffset
  cutText $TeamStatus~Team[$i] & "        " $TeamStatus~Team[$i] 1 4
  pause

:TimeLeft
  getWord CURRENTLINE $TeamStatus~TimeLeft[$i] $WordOffset  + 1
  cutText $TeamStatus~TimeLeft[$i] & "        " $TeamStatus~TimeLeft[$i] 1 7
  return

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Last edited by Micro on Sun Apr 14, 2013 9:22 pm, edited 1 time in total.



Sun Apr 14, 2013 1:04 pm
Profile ICQ YIM WWW
Commander
User avatar

Joined: Mon Oct 29, 2001 3:00 am
Posts: 1096
Location: Tucson, AZ
Unread post Re: My first TWX script.
Congrats, I guess. :lol:

_________________
Suddenly you're Busted!


Sun Apr 14, 2013 2:04 pm
Profile WWW
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: My first TWX script.
Mongoose wrote:
Congrats, I guess. :lol:

Not really; I almost threw up several times. Using TWX script just encourages me to work more on FirstMate. I still hate TWX script, and I always will.

I couldn't help but notice that portions of that script are actually event driven. It seems to be very common in the examples I have been reading.

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Sun Apr 14, 2013 2:20 pm
Profile ICQ YIM WWW
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 4016
Location: USA
Unread post Re: My first TWX script.
Personally I really dislike corpmates spamming SS when they want to gather info. If you can make it echo only to you, I think your corpmates would appreciate it.

Or, give them the option at the very least.

_________________

BOTE 1998 Champs: Team Fament
HHT 2015 Champs: Cloud09
Big Game 2016 Champs: Draft team
HHT 2018 Champs: Rock Stars
Big Game 2019 Champs: Draft Team


Classic Style Games Here:
telnet://crunchers-twgs.com:2002

Web page from 1990's: https://web.archive.org/web/20170103155645/http://tradewars.fament.com/Cruncher/tradewar.htm
Blog with current server info: http://cruncherstw.blogspot.com
Discord: https://discord.gg/4dja5Z8
E-mail: Cruncherstw@gmail.com
FaceBook: http://www.facebook.com/CrunchersTW


Sun Apr 14, 2013 5:20 pm
Profile ICQ WWW
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: My first TWX script.
Cruncher wrote:
Personally I really dislike corpmates spamming SS when they want to gather info. If you can make it echo only to you, I think your corpmates would appreciate it.

Or, give them the option at the very least.

That will be an option for the final report, but unfortunately there is no silent way to collect the information using M()MBOT as it has to send a status request to each bot. If I want to know how many turns each player has (for instance), I would have to ask each player or send the status request anyway. This just makes it faster. I actually wrote it to see if everyone was in the correct ships, at valid prompts, etc... to make sure everyone was ready before starting TSDT.

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Sun Apr 14, 2013 5:48 pm
Profile ICQ YIM WWW
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 4016
Location: USA
Unread post Re: My first TWX script.
Micro wrote:
Cruncher wrote:
Personally I really dislike corpmates spamming SS when they want to gather info. If you can make it echo only to you, I think your corpmates would appreciate it.

Or, give them the option at the very least.

That will be an option for the final report, but unfortunately there is no silent way to collect the information using M()MBOT as it has to send a status request to each bot. If I want to know how many turns each player has (for instance), I would have to ask each player or send the status request anyway. This just makes it faster. I actually wrote it to see if everyone was in the correct ships, at valid prompts, etc... to make sure everyone was ready before starting TSDT.


The team SDT that I use does do a status report on everyone before starting.

_________________

BOTE 1998 Champs: Team Fament
HHT 2015 Champs: Cloud09
Big Game 2016 Champs: Draft team
HHT 2018 Champs: Rock Stars
Big Game 2019 Champs: Draft Team


Classic Style Games Here:
telnet://crunchers-twgs.com:2002

Web page from 1990's: https://web.archive.org/web/20170103155645/http://tradewars.fament.com/Cruncher/tradewar.htm
Blog with current server info: http://cruncherstw.blogspot.com
Discord: https://discord.gg/4dja5Z8
E-mail: Cruncherstw@gmail.com
FaceBook: http://www.facebook.com/CrunchersTW


Sun Apr 14, 2013 8:21 pm
Profile ICQ WWW
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: My first TWX script.
Cruncher wrote:
The team SDT that I use does do a status report on everyone before starting.

Which one are you using?

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Sun Apr 14, 2013 9:15 pm
Profile ICQ YIM WWW
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 4016
Location: USA
Unread post Re: My first TWX script.
Micro wrote:
Cruncher wrote:
The team SDT that I use does do a status report on everyone before starting.

Which one are you using?


Boo SDT, Xanos wrote it, upgraded it a bit for Killbillies. He's asked me to not distributed it.

Before he made his final tweeks he gave all of Boo the file just before we had the Boo vs Boo game.

_________________

BOTE 1998 Champs: Team Fament
HHT 2015 Champs: Cloud09
Big Game 2016 Champs: Draft team
HHT 2018 Champs: Rock Stars
Big Game 2019 Champs: Draft Team


Classic Style Games Here:
telnet://crunchers-twgs.com:2002

Web page from 1990's: https://web.archive.org/web/20170103155645/http://tradewars.fament.com/Cruncher/tradewar.htm
Blog with current server info: http://cruncherstw.blogspot.com
Discord: https://discord.gg/4dja5Z8
E-mail: Cruncherstw@gmail.com
FaceBook: http://www.facebook.com/CrunchersTW


Sun Apr 14, 2013 9:47 pm
Profile ICQ WWW
Boo! inc.
User avatar

Joined: Sat Oct 09, 2004 2:00 am
Posts: 865
Location: USA
Unread post Re: My first TWX script.
Nice script...

It's interesting to see the differences between scripts who's authors are programmers vs non-programmers.

Micro, are you a programmer?

_________________
“The object of war is not to die for your corp but to make the other bastard die for his.”

Boo! inc.


Mon Apr 15, 2013 12:39 pm
Profile
Boo! inc.
User avatar

Joined: Sat Oct 09, 2004 2:00 am
Posts: 865
Location: USA
Unread post Re: My first TWX script.
I wrote this during one of our death matches, it worked on two people then crosby got me..;)


This is one of my first scripts I wrote to work with m()m bot. I would love to get back into writing. I loved playing with a few good friends and being asked to come up with something on the fly.


Code:
#      After plock turn on citkill
#
#
systemscript
loadvar $bot_name
send "'*"
send "Starting Active Plock/Auto Citkilla**"

:starttriggers
settexttrigger 1 :activeplock "{" & $bot_name & "} - PLOCK Ready to fire Sector:"
settexttrigger 2 :cleared "{" & $bot_name & "} - PLOCK Sector Cleared"
echo "***...Waiting for plock to fire...***"
echo "***...Be sure that you do not have (kill) option on...***"
pause

:activeplock
killtrigger 1
killtrigger 2
settexttrigger 3 :plockdone " -PLOCK Launched"
pause

:plockdone
killtrigger 3
send "'*"
send $bot_name " citkill on dt smart**"

:cleared
killalltriggers
send "'Resetting triggers!*"
goto :starttriggers

#disrupted 12 of your mines in 19146

_________________
“The object of war is not to die for your corp but to make the other bastard die for his.”

Boo! inc.


Mon Apr 15, 2013 12:51 pm
Profile
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: My first TWX script.
mob wrote:
Micro, are you a programmer?

Yes, for as long as I can remember. Started with gwbasic, assembler, and c (before ++) back in the 80's. Now I prefer C#/WPF.

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Mon Apr 15, 2013 11:41 pm
Profile ICQ YIM WWW
Boo! inc.
User avatar

Joined: Sat Oct 09, 2004 2:00 am
Posts: 865
Location: USA
Unread post Re: My first TWX script.
Micro wrote:
mob wrote:
Micro, are you a programmer?

Yes, for as long as I can remember. Started with gwbasic, assembler, and c (before ++) back in the 80's. Now I prefer C#/WPF.


Yeah, and I'm not. You can see the difference in the script. Nice job though man.

_________________
“The object of war is not to die for your corp but to make the other bastard die for his.”

Boo! inc.


Tue Apr 16, 2013 4:14 am
Profile
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: My first TWX script.
Lots of way's to skin a cat, personally I would have used a while instead of the that loop and used a "&" during your send spam. But for a first time with TWX it's good, very readable which I'm a fan of. However, not sure what you were expecting from a scripting language; event driven and all ;-)

It's not like it's Objective C or something :P

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Fri Apr 19, 2013 6:47 am
Profile ICQ
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: My first TWX script.
Actually, I didn't even know TWX had "WHILE". Normally I would use a "for" or "foreach" in this scenario, but TWX doesn't have those. I prefer C#/WPF, so I actually don't like using "GOTO" at ALL!

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Sun Apr 21, 2013 5:26 pm
Profile ICQ YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.