www.ClassicTW.com
https://mail.black-squirrel.com/

Script- Write Game Players to Text file
https://mail.black-squirrel.com/viewtopic.php?f=15&t=24243
Page 1 of 1

Author:  Thrawn [ Mon Nov 09, 2009 12:11 am ]
Post subject:  Script- Write Game Players to Text file

I am working on a mod for another script and am beating my head on a wall. I'm trying to get a text file produced where the players that are in the game are recorded to a text file. I have the script sending the "clv" and I did manage to get the text file created, but it put a zero in the file. I then changed a few things and it wrote only the last player in the "clv" to the text file. I changed it back and now am back to getting the zero. I am obviously forgetting some important step, or some syntax is wrong/backwards, and therefore I am here to ask the script gurus.

Here is what I have so far (code taken at the point where the script is in the game and at the Command Prompt):

Code:
echo "*Arrived In Game*"
setArray $player 0
setVar $ii 1
send "c l v"
setTextLineTrigger time :time "Trade Wars 2002 Trader Rankings"
pause
:time
getWord CURRENTLINE $date 7
getWord CURRENTLINE $time 8
getWord CURRENTLINE $am 9
waiton "--- --------------------- -- ------------------------------"
setTextLineTrigger player :player
pause
:player
# Trader Number
setVar $TEMP CURRENTLINE
if ($TEMP <> "")
   
   # Trader Name
   cutText $TEMP $player[$ii][PLAYERNAME] 30 30
   replaceText $player[$ii][PLAYERNAME] "<" "&lt;"
   replaceText $player[$ii][PLAYERNAME] ">" "&gt;"
   add $ii 1
   setTextLineTrigger player :player
   pause

elseif ($TEMP = "Computer command")
   goto :player_done
end

:player_done
killAllTriggers
waitfor "Computer command"
send "q"
setvar $i 1
setvar $playerCnt 1
delete $playerfile
while ($i <= $playerCnt)
   write $playerfile $player[$ii][PLAYERNAME]
   add $i 1
end


Author:  Promethius [ Mon Nov 09, 2009 2:02 am ]
Post subject:  Re: Script- Write Game Players to Text file

Looks like part of the problem is at the bottom if I am reading it right:

Code:
setvar $i 1                  <---- setting loop counter to 1 - ok
setvar $playerCnt 1      <---- set to same value as $i on the above line
delete $playerfile
while ($i <= $playerCnt)   <-------------------already equal from above so will make one loop
   write $playerfile $player[$ii][PLAYERNAME]   <--- $ii var counter used and not incremented in loop
   add $i 1                                                   --- will contain last value of $ii
end



It is late and I am tired so I may be way off base on it. Also looks like $ii might be incremented 1 time more than the player count so the $ii in the var above would not have any information and would return 0.

so maybe something like:

Code:
setvar $i 1                 
subtract $ii 1   
delete $playerfile
while ($i <= $ii)   
   write $playerfile $player[$i][PLAYERNAME]   
   add $i 1                                                   
end

Author:  Big D [ Mon Nov 09, 2009 2:30 am ]
Post subject:  Re: Script- Write Game Players to Text file

I'm not sure exactly what you want as far a format, but this should work if you just want a player name list of the clv saved to file: Now this doesn't take into consideration that screen pauses are on.


setVar $playerfile GAMENAME & "_clv.txt"
delete $playerfile
echo "*Arrived In Game*"
send "c l v"
setvar $playernum 0

waiton "Trade Wars 2002 Trader Rankings"
getWord CURRENTLINE $date 7
getWord CURRENTLINE $time 8
getWord CURRENTLINE $am 9
write $playerfile $date
write $playerfile $time
write $playerfile $am
waiton "--- --------------------- -- ------------------------------"
:getclv
killAllTriggers
add $playernum 1
setTextTrigger done :done "Computer command ["
waiton $playernum
cutText CURRENTLINE $playername 30 30
write $playerfile $playername
goto :getclv

:done
send "q"
echo "*CLV File Updated*"
halt

Author:  Vid Kid [ Mon Nov 09, 2009 4:11 am ]
Post subject:  Re: Script- Write Game Players to Text file

Here you go Thrawn

Code:

SetVar $playerfile GAMENAME &"-"& GAME &"-clv.txt"
Delete $playerfile
Echo "*Arrived In Game*"
SetArray $player "0"
SetVar $ii "0"
Send "|"
WaitOn "all messages."
CutText CURRENTLINE $messages 1 10
StripText $messages " "
If ($messages <> "Displaying")
Else
Send "|"
End
WaitFor "ommand"
SetTextLineTrigger timedate :timedate "Trade Wars 2002 Trader Rankings"
Send "c l v"
Pause

:timedate
CutText CURRENTLINE $daydate 35 99
Write $playerfile $daydate
WaitFor "--- --------------------- -- ------------------------------"
:Top
KillAllTriggers
SetTextLineTrigger player :player
Pause
:player
SetVar $TEMP CURRENTLINE
IF ($TEMP <> "")
   Add $ii "1"
   GetWord $Temp $Numb[$ii] "1"
   CutText $TEMP $player[$ii] 30 30
          GetLength $Numb[$ii] $len
            IF ($len = "1")
              SetVar $Numb[$ii] "   "&$Numb[$ii]
            ElseIF ($len = "2")
              SetVar $Numb[$ii] "  "&$Numb[$ii]
            ElseIF ($len = "3")
              SetVar $Numb[$ii] " "&$Numb[$ii]
            ElseIF ($len = "4")
              SetVar $Numb[$ii] ""&$Numb[$ii]
            End
   Write $playerfile $Numb[$ii]&"  "&$player[$ii]
   Goto :Top
ElseIf ($TEMP = "Computer command")
   Goto :player_done
End
:player_done
KillAllTriggers
WaitFor "Computer command"
Send "q"
ReadToArray $playerfile $Count
SetVar $i "2"
ECHO "**"
While ($i <= $Count)
Echo ANSI_10 $Count[$i]&"*"
Add $i "1"
End
Echo "*" ANSI_0
Send "|"
WaitOn "all messages."
CutText CURRENTLINE $messages 1 10
StripText $messages " "
If ($messages = "Displaying")
Else
Send "|"
End
Sound ding
WaitFor "ommand"

Author:  Thrawn [ Mon Nov 09, 2009 11:16 am ]
Post subject:  Re: Script- Write Game Players to Text file

Thank you guys for the assist. It goes to show when you step out of scripting for a bit and return how you forget the simple things. I see from all three of your examples exactly where I went wrong and got it fixed. Of course I should not be working on a project so late at night either.

Now I can get the next phase underway. Really appreciate you taking time to give me help.

Cheers

Author:  Promethius [ Mon Nov 09, 2009 12:14 pm ]
Post subject:  Re: Script- Write Game Players to Text file

If all you are trying to write is something like:

Code:
Trade Wars 2002 Trader Rankings : 11/09/21 12:06:07 PM
  1   Tracer                       
  2   fluffyg420                   
  3   fluffg420                     
  4   Farley                     

and not reuse the array vars then something like this would be fairly easy to do with:

Code:
   

send "clvq"
setTextLineTrigger timeDate :timeDate "Trade Wars 2002 Trader Rankings"
pause
:timeDate
write "someFile.txt" currentline
waitfor "--- ---------------------"
:getInfo
setTextLineTrigger line :line ""
pause
:line
  getlength currentline $len
  if ($len < 1)
      goto :done
  else
      # below line saves formatting the number
      cutText currentline $num 1 5
      cutText currentline $player 30 30
      write "someFile.txt" $num & " " & $player
  end
  goto :getInfo

:done
  halt


Author:  Thrawn [ Mon Nov 09, 2009 1:12 pm ]
Post subject:  Re: Script- Write Game Players to Text file

I was looking to do something like that, but then decided to get fancy ;) The idea was that the script could then read from the text file of player names to send mail, etc. All part of a mod I'm working on for both the ScoreKeeper and our Computer player script.

Vid, I'm curious on your script. Yours works good, but I notice that when it puts the player names in the text file, it is 30 characters. When I go to read that file to an array for a mail function, it inputs the player name AND spaces, resulting in an "Unknown Trader" message. How can I just have the line end where the player name is and not fill in the remainder with spaces to equal 30?

For example:

Code:

Daala                         .
Thrawn                        .
Mon Mothma                    .



The "." represent the end of that line. So when I run the mail function, it sends "Daala " which results in the "Unknown Trader" showing. I am trying to remember how to eliminate the spaces after the name.

Cheers

Author:  Vid Kid [ Mon Nov 09, 2009 6:00 pm ]
Post subject:  Re: Script- Write Game Players to Text file

I think you could just do


SetVar $ii "2"
While ($ii <= $count)
Read $playerfile $player[$ii] $ii
CutText CURRENTLINE $player[$ii] 8 99
Add $ii "1"
END


(not tested , but should strip off anything after name in the file.)

Author:  Thrawn [ Mon Nov 09, 2009 6:23 pm ]
Post subject:  Re: Script- Write Game Players to Text file

Sorry, that did not fix the issue.

I've attached a copy of the text file with 3 usernames. You can see that it has spaces in each line so that each line equals 30 characters. When the mail function runs, it reads the username including the spaces. Here is the code I wrote to do the mail function:

Code:
:sendMail
fileexists $fileAvail $playerfile
if ($fileAvail = FALSE)
   halt
end
readtoarray $playerfile $mailer
setvar $m 1
while ($m <= $mailer)
   send "c"
   waitfor "Computer activated"
   :startmail
   killalltriggers
   send "s"
   waitfor "Sysop: Is this a message FROM"
   send "y"
   waitfor "Which Trader ? (Full or Partial Name)"
   send $mailer[$m] & "*"
   settextlinetrigger unknown :startmail "Unknown Trader!"
   settextlinetrigger ready :ready "Type M.A.I.L. message [<ENTER> to send line. Blank line to end transmission]"
   pause
   :ready
   killalltriggers
   send "Test**"
   waitfor "Computer command"
   send "q"
   waitfor "Command [TL"
   add $m 1
end


I'll keep plugging away on it. I'm still grateful you guys took the time to get me in the right direction.

Cheers

Attachments:
File comment: GameA CLV list of players
playerlist_Game_A-CLV.zip [181 Bytes]
Downloaded 412 times

Author:  Vid Kid [ Mon Nov 09, 2009 10:05 pm ]
Post subject:  Re: Script- Write Game Players to Text file

Thank you Thrawn , that last bit was a little challenging .. removing the spaces.
Also thank you Promethius for your way to padding the count.

New code is as follows :

Code:

SetVar $playerfile GAMENAME &"-"& GAME &"-clv.txt"
Delete $playerfile
Echo "*Arrived In Game*"
SetArray $player "0"
SetVar $ii "0"
Send "|"
WaitOn "all messages."
CutText CURRENTLINE $messages 1 10
StripText $messages " "
If ($messages <> "Displaying")
Else
Send "|"
End
WaitFor "ommand"
SetTextLineTrigger timedate :timedate "Trade Wars 2002 Trader Rankings"
Send "c l v"
Pause

:timedate
CutText CURRENTLINE $daydate 35 99
Write $playerfile $daydate
WaitFor "--- --------------------- -- ------------------------------"
:Top
KillAllTriggers
SetTextLineTrigger player :player
Pause
:player
SetVar $TEMP CURRENTLINE
IF ($TEMP <> "")
   Add $ii "1"
   CutText $Temp $Numb[$ii] 1 5
   CutText $TEMP $Name 30 30
    SetVar $T "1"
    SetVar $Z "30"
   :TLoop
    While ($T <= $Z)
    SetVar $E ($Z - $T)
    CutText $Name $New $E 1
        IF ($New = " ")
        Add $T 1
        Goto :TLoop
        ElseIF ($New <> " ")
        CutText $Name $Player 1 $E
        Goto :TOut
        End
    Add $T 1
    END
   :TOut
   SetVar $Player[$ii] $player
   Write $playerfile $Numb[$ii]&$player
   Goto :Top
ElseIf ($TEMP = "Computer command")
   Goto :player_done
End
:player_done
KillAllTriggers
WaitFor "Computer command"
Send "q"
ReadToArray $playerfile $Count
SetVar $i "2"
ECHO "**"
While ($i <= $Count)
Echo ANSI_10 $Count[$i]&"*"
Add $i "1"
End
Echo "*" ANSI_0
Send "|"
WaitOn "all messages."
CutText CURRENTLINE $messages 1 10
StripText $messages " "
If ($messages = "Displaying")
Else
Send "|"
End
Sound ding
WaitFor "ommand"

Author:  Thrawn [ Mon Nov 09, 2009 10:35 pm ]
Post subject:  Re: Script- Write Game Players to Text file

I see where the change is. Learn something new, and I've recorded this in my notebook for future reference. Thanks to you, D, and Promethius for the help. Works perfectly, and the mail portion of the script now works. If all goes well, we hope to release this to the public soon (SysOp server-side script). I'll be on this after 11-Nov, as our unit is gathering for Remembrance Day and we have other obligations for the next few days.

BTW Vid, if I read the "congradulations" on the forum right, Happy Birthday. Prom and Big D, thank you too for the script help. I'm using both of yours for some other functions (if you are okay with that) on this project.

Cheers

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/