mIRC Home    About    Download    Register    News    Help

Print Thread
#81829 04/05/04 08:54 AM
Joined: May 2004
Posts: 6
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: May 2004
Posts: 6
This script is suppose to detect people's score jump from a game. It scans through "playerinfo.txt" (were all the current info is stored) and then checks to see what their score was 30 seconds ago in a scorejump.ini. If their score has jumped X amount of points set in the %jumprequire, it goes off. Can someone tell me if I have done something wrong with this While-Loop?

alias scorejump {
if (!$read(playerinfo.txt, 1)) {
/msg %channel No Players In-Game
}
else {
/set %sj 1
while ($read(playerinfo.txt, %sj)) && (%sj <= $calc($lines(playerinfo.txt) - 1)) {
if (!$readini(scorejump.ini, names, $gettok($read(playerinfo.txt, %sj),2,32))) {
/writeini scorejump.ini names $gettok($read(playerinfo.txt, %sj),2,32) $gettok($read(playerinfo.txt, %sj),3,32)
/inc %sj
}
if ($calc($gettok($read(playerinfo.txt, %sj),3,32) - $readini(scorejump.ini, names, $gettok($read(playerinfo.txt, %sj),2,32))) < %jumprequire) {
/writeini scorejump.ini names $gettok($read(playerinfo.txt, %sj),2,32) $gettok($read(playerinfo.txt, %sj),3,32)
/inc %sj
}
elseif ($calc($gettok($read(playerinfo.txt, %sj),3,32) - $readini(scorejump.ini, names, $gettok($read(playerinfo.txt, %sj),2,32))) >= %jumprequire) {
/set %scorejump $gettok($read(playerinfo.txt, %sj),3,32)
/set %prevjump $readini(scorejump.ini, names, $gettok($read(playerinfo.txt, %sj),2,32))
/set %nickjump $gettok($read(playerinfo.txt, %sj),2,32)
/msg %channel >> Score Jump: %nickjump $+ : $calc( $+ %scorejump - %prevjump $+ )
/writeini scorejump.ini names %nickjump %scorejump
/inc %sj
}
else {
/inc %sj
}
}
}
}

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

I've optimized your code for you. Note how I'm only using one time dec %sj
I'm using a while loop that starts at the end of the txt file. SHould you for any reason absolutely want to start from the beginning of the file, and loop till the end, then indeed, you need to do:

var %lines = $lines(%file.txt)
var %sj = 1
while (%sj <= %lines) {
...
...
...
}
inc %sj
}
}
}

Here's the code:
Code:
alias scorejump {
  [color:red]  [/color] 
  var %file.txt = $+(",$mircdir,playerinfo.txt,")
  var %file.ini = $+(",$mircdir,scorejump.ini,")
  var %sj = $lines(%file.txt), %score.ini, %scorejump
  [color:red]  [/color] 
  if (!%sj) { msg %channel No players In-Game }
  else {
    while (%sj) {
      tokenize 32 $read(%file.txt, %sj)
      %score.ini = $readini(%file.ini, names, $2)
      %scorejump = $calc($3 - %score.ini)
      if (!%score.ini) || (%scorejump &lt; %jumprequire) { goto next }
      else { msg %channel &gt;&gt; Score Jump: $2 $+ : %scorejump }
      :next
      writeini %file.ini names $2 $3
      dec %sj
    }
  }
} 

Note1: you are never using the first parameter in a line of that txt file. You always use $2 and $3. Just out of curiousity, what is the first parameter?
I mean like: <1st parameter> <name> <score>

Note2: I'm assuming that your playerinfo.txt and scorejump.ini are located in your main mirc folder.


Greetz

Last edited by FiberOPtics; 04/05/04 10:07 AM.

Gone.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hehe,

and if you're mircfolder has a path with no spaces in it, and playerinfo.txt & scorejump.ini are in the main mirc folder, then the code becomes even shorter:

Code:
 
alias scorejump {
  var %sj = $lines(playerinfo.txt), %score.ini, %scorejump
  if (!%sj) { msg %channel No players In-Game | return }
  while (%sj) {
    tokenize 32 $read(playerinfo.txt, %sj)
    %score.ini = $readini(scorejump.ini, names, $2)
    %scorejump = $calc($3 - %score.ini)
    if (!%score.ini) || (%scorejump &lt; %jumprequire) { goto next }
    msg %channel &gt;&gt; Score Jump: $2 $+ : %scorejump 
    :next
    writeini scorejump.ini names $2 $3
    dec %sj
  }
}


Some tips for the future:

* /help /tokenize
* /help local variables
* if you are going to use some data multiple times, it is better to store it in e.g. a variable or identifier (with tokenize), so that you can easily access the value of the variable, rather than having to look up the value from the source each time. I'm referring to $gettok($read(playerinfo.txt, %sj),2,32) which is replaced in my script with $2


Greetz

Last edited by FiberOPtics; 04/05/04 01:56 PM.

Gone.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Here's a way to shorten it some more. Replace this:
Code:
  if (!%score.ini) || (%scorejump &lt; %jumprequire) { goto next }
  else { msg %channel &gt;&gt; Score Jump: $2 $+ : %scorejump }
  :next
with this:
Code:
  if %score.ini &amp;&amp; %scorejump &gt;= %jumprequire { msg %channel &gt;&gt; Score Jump: $2 $+ : %scorejump }



/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hey,

duh I know that :P, reply to him lol.

qwerty, did you ever get my pm, btw?

Greetz

Last edited by FiberOPtics; 04/05/04 06:04 PM.

Gone.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
It was you who introduced the /goto in the code, not Speedy059 :tongue: Regardless, even though I replied to your post, the reply wasn't meant just for you to read. In fact, it was directed mostly towards Speedy059, since he is the one who needs this code, not you.

Yeah, I got the PM, I just didn't have anything more to add to that topic smile Btw, there's a nice feature in Ubbthreads, where you can check a box prior to PMing somebody and be notified when the recipient reads the message.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hehe,

I know about that feature, but that time i forgot to enable it.

Oh well, all I needed to know.

Catch ya later!


Gone.

Link Copied to Clipboard