mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
Hi All,

Here is what I have been using for a while for a quote bot with audio playback. I am trying to see if there is a better way to do this. I am fairly knowledgeable in powershell. Though I don't believe there is a switch function that I can use. Well here is the code portion.

Code:
on *:TEXT:!q *:#: { 
  ;if ((%floodquote) || ($($+(%,floodquote.,$nick),2))) { return }
  ;set -u30 %floodquote On
  ;set -u60 %floodquote. $+ $nick On
  if ($2 isalnum) && ($2 <= $lines(%quotefile)) { 
    msg $chan Quote $chr(91) $+ $chr(35) $+ $2 $+ $chr(92) $+ $lines(%quotefile) $+ $chr(93) $+ $chr(34) $+ $read(%quotefile, $2) $+ $chr(34)
    if ($2 == 1) {
      var %qr1 $rand(1,2)
      if (%qr1 == 1) {
        splay %soundquotes $+ q1-1.mp3
      }
      else {
        splay %soundquotes $+ q1-2.mp3
      }
    }
    elseif ($2 == 2) {
      var %qr2 $rand(1,4)
      if (%qr2 == 1) {
        splay %soundquotes $+ q2-1.mp3
      }
      elseif (%qr2 == 2) {
        splay %soundquotes $+ q2-2.mp3
      }
      elseif (%qr2 == 3) {
        splay %soundquotes $+ q2-3.mp3
      }
      else {
        splay %soundquotes $+ q2-4.mp3
      }
    }
    elseif ($2 == 3) {
      var %qr3 $rand(1,3)
      if (%qr3 == 1) {
        splay %soundquotes $+ q3-1.mp3
      }
      elseif (%qr3 == 2) {
        splay %soundquotes $+ q3-2.mp3
      }
      else {
        splay %soundquotes $+ q3-3.mp3
      }
    }
    elseif ($2 == 4) {
      var %qr4 $rand(1,2)
      if (%qr4 == 1) {
        splay %soundquotes $+ q4-1.mp3
      }
      else {
        splay %soundquotes $+ q4-2.mp3
      }
    }
  } 
} 


This is a sample portion. Current system is 68 quotes with up to 4 different quote audio files. I have what I need working. Just wondering if there was a better way to do this.

Thank you all for your time!

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Hello, what you need is called genericity, you can't just write all condition for $2 going from 1 to N litterally or your code would be very long very quickly!
In your code, you have some part which are repeating a lot.
A simple example is:

Code:
alias test {
if ($1 == 1) dosomething 1
elseif ($1 == 2) dosomething 2
..
elseif ($1 == 8) dosomething 8
}

Well why not just calling /dosomething $1 as long as $1 is between 1 and 8?
that would give:

Code:
alias test {
if ($1 isnum 1-8) dosomething $1
}
And you get one line of code handling a various numbers of situations.




Code:
if ($2 == 1) {
  var %qr1 $rand(1,2)
  if (%qr1 == 1) {
     splay %soundquotes $+ q1-1.mp3
  }
  else {
    splay %soundquotes $+ q1-2.mp3
  }
}
elseif ($2 == 2) {
  var %qr2 $rand(1,4)
  if (%qr2 == 1) {
    splay %soundquotes $+ q2-1.mp3
  }
  elseif (%qr2 == 2) {
    splay %soundquotes $+ q2-2.mp3
  }
  elseif (%qr2 == 3) {
    splay %soundquotes $+ q2-3.mp3
  }
  else {
    splay %soundquotes $+ q2-4.mp3
  }
}
...
Here, no matter what is the value of $2 (you are checking that $2 is 'alnum', but you probably want it to be 'isnum', since you are only expecting numbers), you're always going to call $rand with 1 as the first parameter, and no matter what's the value of that $rand, you will always call /splay, were the parameters of /splay are passed according to that number $2 (predictable)
So we need to predict the second parameter of $rand based on $2, this is pretty simple: $2 goes from 1 to N, so we can make a list of number for $rand and access the $2th element in that list, when $2 is 1, your second parameter for $rand is 2, so first element is 2, for $2 == 2, you have $rand = 4, so second element is 4, and so on.
The parameter for /splay is %soundquotes $+ q1-1.mp3 for $2 == 1 and $rand == 1, so clearly we can create the parameter based on $2 and $rand: %soundquotes $+ q $+ $2 $+ - $+ $rand() $+ .mp3

Code:
if ($2 isnum 1-LIMIT) {
var %listforrand 1 2 3 2
var %qr1 $rand(1,$gettok(%listforrand,$2,32))
splay %soundquotes $+ q $+ $2 $+ - $+ %qr1 $+ .mp3
much shorter right? and now the only thing you need to do to add more cases for $2, is to define the number in %listforrand


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
Very awesome design!

Code:
if ($2 isnum 1-LIMIT) {
var %listforrand 1 2 3 2
var %qr1 $rand(1,$gettok(%listforrand,$2,32))
splay %soundquotes $+ q $+ $2 $+ - $+ %qr1 $+ .mp3


Actually figured it out now. VERY awesome design!! Thank you so much. I just got confused because the first quote would only play one sound file instead, the 1 of 2. Though I resolved that with the following.

Code:
    var %listforrand 2 3 3 2


Working code for if anyone else finds this helpful.

Code:
on *:TEXT:!qu *:#:{
  ;if ((%floodquote) || ($($+(%,floodquote.,$nick),2))) { return }
  ;set -u30 %floodquote On
  ;set -u60 %floodquote. $+ $nick On
  if ($2 isalnum) && ($2 <= $lines(%quotefile)) { 
    msg $chan Quote $chr(91) $+ $chr(35) $+ $2 $+ $chr(92) $+ $lines(%quotefile) $+ $chr(93) $+ $chr(34) $+ $read(%quotefile, $2) $+ $chr(34)
    var %listforrand 2 3 3 2
    ;this works like this.  gettok (1 2 3 4,number to pick,number of the delimiter character 32=space, 44=comma
    var %qr1 $rand(1,$gettok(%listforrand,$2,32))
    splay %soundquotes $+ q $+ $2 $+ - $+ %qr1 $+ .mp3
  }
}

Last edited by Despized; 12/08/15 03:53 AM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Hum.. Well the point was to get you to complete the code, especially the list in %listforrand, however it seems that I started it wrong, it also seems to me that your final code is incorrect: the code originally had $rand(1,4) for $2 == 2 so '4' should be the second element in the list:
Code:
var %listforrand 1 4 3 2

Last edited by Wims; 12/08/15 02:41 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
The logic of the script is that when a user says !q 1 or !q 2 or !q 23. Is that it would pull the quote from the ini file and display it in the chat.

After that it would then randomly select a number 1-2 or 1-3 or 1-4. Depending on how may audio files are tied to that quote.

For instance. Quote 1. Has two quote audio files tied. Quote 2 has 4. So the randomly selected audio quote file would play along with the quote being stated in chat.

Now that is covered. Your solution worked perfectly once I figured out the understanding of the array variable and $gettok.
My %listforrand is now 68 characters long for all 68 quotes that have audio files with them. After work I will post the working solution.

I do understand the listforrand portion now. This would work with the existing code from my first post. Meaning that if $2=1 then the listforrand would be 2. Also if $2=2 then the listforrand would be 4. Based on the usage of the $gettok.
Code:
;if $2=1 then it would be quote listforrand 2
;if $2=2 then it would be quote listforrand 4
;if $2=3 then it would be quote listforrand 3
;if $2=4 then it would be quote listforrand 2

var %listforrand 2 4 3 2
var %qr1 $rand(1,$gettok(%listforrand,$2,32))

;if $2=1 then the result would be 1 or 2 for %qr1

splay %soundquotes $+ q $+ $2 $+ - $+ %qr1 $+ .mp3

;this would play q1-1.mp3 or q1-2.mp3 if $2=1


I do have some more script portions that I would love help on optimizing if possible. Though I am unsure if I should continue with this thread or create another thread. Since they are the same thing.

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
I was just saying/pointing out that, in your new script, you had "var %listforrand 2 3 3 2", which is incorrect since the original code had $rand(1,4) for $2 == 2, meaning that %listforrand should have been "2 4 3 2", which you fixed then smile

I'd say you can keep using that thread since its title is about script optimization.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
Oh ok cool! sorry that I didn't get that. I was reading on my phone at work. Again many thanks!

Alright next example portion. I was using the gettok method though I ran into a stump with ulevel check. Basically want the command to check the user rank to show what commands they have available. The full script goes to ulevel 50. Just showing a portion of it since the rest is rinse and repeat.

Code:
on *:text:!sounds:#:{
  if ((%floodsounds) || ($($+(%,floodsounds.,$nick),2))) { return }
  set -u10 %floodsounds On
  set -u30 %floodsounds. $+ $nick On 
  ;Update as more sound commands are added.
  ;Need to work on shortening this one.
  var %sounds !chicken,!elementalcohesion,!nonono,!igottheboons,!bane,!moo,!pewpew,!elephant,!monkey,!toot,!doom,!babyfart,!matingcall
  if ($ulevel < 9 ) {
    msg $chan you are $ulevel and have no sound commands.
  }
  elseif ($ulevel == 10 ) {
    ;msg $chan $nick $+ $chr(58) !chicken
    msg $chan $nick $+ $chr(58) $gettok(%sounds,1,44)
  }
  elseif ($ulevel == 11 ) {
    msg $chan $nick $+ $chr(58) $gettok(%sounds,1-2,44)
  }
  elseif ($ulevel == 12 ) {
    msg $chan $nick $+ $chr(58) $gettok(%sounds,1-3,44)
  }
  elseif ($ulevel == 13 ) {
    msg $chan $nick $+ $chr(58) $gettok(%sounds,1-4,44)
  }
}

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
The idea is the same, but you can't just use $gettok the same, because you have more than one information per level.
In this case you can associate the triggers (I hate that people call it a command) with the level, using multiple variable and counting on the fact that level N has access to all triggers between 10 and N:

Since I don't know exactly how to associate (I guess it's one trigger per level), I'll show you an example with several triggers per level, also, it's always a better idea to use a space as the seperator in your list, in any case, using comma is a bad idea because comma delimit the parameters of $identifier: $identifier(param1,param2), even if you have to put the comma back for display purpose

Code:
on *:text:!sounds:#:{
  if ((%floodsounds) || ($($+(%,floodsounds.,$nick),2))) { return }
  set -u10 %floodsounds On
  set -u30 %floodsounds. $+ $nick On 
  ;Update as more sound commands are added.
  ;Need to work on shortening this one.
  var %sounds10 !chicken !elementalcohesion
  var %sounds11 !nonono !igottheboons !bane !moo
  var %sound12 !pewpew !elephant
  var %sound13 !monkey !toot !doom !babyfart !matingcall
  ;you have to keep this if statement because 9 and others level don't share the same code, also i think you want to use <=, otherwise level 9 wouldn't get an answer.
  if ($ulevel <= 9 ) {
    msg $chan you are $ulevel and have no sound commands.
  }
  else {
  ;so if it's greater than 9, we are going to 'keep' (this is the while loop) looking for a variable that is %sound<level>, starting at level $ulevel:
  var %level $ulevel
    while ($eval($+(%,sounds,%level),2) != $null) {
      ; no need to escape : with $chr(58) here
      msg $chan $nick $+ : $v1
      inc %level
    }
  }
}

So let's say %level start at 10, $+(%,sounds,%level) is the litteral text %sounds10, $eval(,2) will evaluate one more time to produce the value of the variable.
$v1 refers to the last 'first operand' used in a conditional statement, here, it refers to the value of that while ().

Of course, this is actually sending one message 'per' level that the user can access, if you want one message for all, you just keep adding the triggers to a variable and you send that at the end:

Code:
else {
  var %level $ulevel,%result
    while ($eval($+(%,sounds,%level),2) != $null) {
      ; no need to escape : with $chr(58) here
      %result = %result $v1
      inc %level
    }
   msg $chan $nick $+ : %result
  }


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
Alright very nicely designed. The mass use of the %sound variable isn't ideal though I am have not figured out a way to do it differently. I was originally trying to make %sounds an array to call from.. but I would need a correspondance table of sorts.

Code:
if $level=10 {%sounds[0]}
else if $ulevel=11 {%sounds[0..1]}


Not exactly like that but that is how I logically see it or if possible to do a switch.
Code:
switch $ulevel {
 "10" = {%sound[0]}
 "11" = {%sound[0..1]}
etc...
etc..
 "15" = {%sound[0..5]}
etc...
}


Here is the current working script portion that I am using and tinkering around with now.

Code:
on *:text:!sounds:#:{
  ;if ((%floodsounds) || ($($+(%,floodsounds.,$nick),2))) { return }
  ;set -u10 %floodsounds On
  ;set -u30 %floodsounds. $+ $nick On 
  ;Update as more sound commands are added.
  ;Need to work on shortening this one.
  var %sound10 !chicken
  var %sound11 !chicken !elementalcohesion
  var %sound12 !chicken !elementalcohesion !nonono
  var %sound13 !chicken !elementalcohesion !nonono !igottheboons
  var %sound14 !chicken !elementalcohesion !nonono !igottheboons !bane
  var %sound15 !chicken !elementalcohesion !nonono !igottheboons !bane !moo
  var %sound16 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew
  var %sound17 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant
  var %sound18 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey
  var %sound19 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot 
  var %sound20 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom
  var %sound21 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart
  var %sound22 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound23 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound24 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound25 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound26 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound27 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound28 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound29 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound30 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound31 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound32 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound33 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound34 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound35 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound36 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound37 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound38 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound39 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound40 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound41 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound42 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound43 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound44 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound45 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound46 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound47 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound48 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound49 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound50 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound999 !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  ;Go all the way to rank 50 for the maximum just incase.  (correspond this with the ranks that you actually gain the audio commands.)
  if ($ulevel < 9 ) {
    msg $chan you are $ulevel and have no sound commands.
  }
  else {
    ;msg $chan $nick $+ $chr(58) $gettok(%sounds,1-13,44)
    var %level $ulevel,%result
    while ($eval($+(%,sound,%level),2) != $null) {
      ; no need to escape : with $chr(58) here
      %result = %result $v1
      inc %level
    }
    msg $chan $nick $+ : %result
  }
}


I have old sections commented out for reference points as I tinker with this more. Thanks again Wims thus far!

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Hum maybe I wasn't clear but the method I used was meant to allow you not to repeat the triggers: a level N (that is > 9) already access all the triggers of the levels 10 to N

mIRC doesn't have array, but this is actually our way of creating arrays, it's exactly the same and for the level N, we access all the next element in the array, N, N + 1 etc, until there is no more element in the array.
mIRC doesn't have switch either, it was requested but we don't need that, if / elseif already does the job fine.


Code:
on *:text:!sounds:#:{
  ;if ((%floodsounds) || ($($+(%,floodsounds.,$nick),2))) { return }
  ;set -u10 %floodsounds On
  ;set -u30 %floodsounds. $+ $nick On 
  ;Update as more sound commands are added.
  ;Need to work on shortening this one.
  var %sound10 !chicken
  var %sound11 !elementalcohesion
  var %sound12 !nonono
  var %sound13 !igottheboons
  var %sound14 !bane
  var %sound15 !moo

  ;etc... 

  ;Go all the way to rank 50 for the maximum just incase.  (correspond this with the ranks that you actually gain the audio commands.)
  ;don't you want <= 9 here instead of < 9)? see my previous post!
  if ($ulevel < 9 ) {
    msg $chan you are $ulevel and have no sound commands.
  }
  else {
    ;msg $chan $nick $+ $chr(58) $gettok(%sounds,1-13,44)
    var %level $ulevel,%result
    while ($eval($+(%,sound,%level),2) != $null) {
      ; no need to escape : with $chr(58) here
      %result = %result $v1
      inc %level
    }
    msg $chan $nick $+ : %result
  }
}
That being said, if each new level means strictly one more trigger, then you can use the $gettok method, which is also basically reproducing an array access.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
Very nice work! Though I am trying to get it so it adds all the commands together per level. Instead of just having it show only the sound command of the level you are at. Show all that are available to the user for their current level.

Trying out a couple ideas. - Alright I got it working the way I wanted using gettok

Here is the code for anyone's reference.
Code:
on *:text:!sounds:#:{
  ;if ((%floodsounds) || ($($+(%,floodsounds.,$nick),2))) { return }
  ;set -u10 %floodsounds On
  ;set -u30 %floodsounds. $+ $nick On 
  ;Update as more sound commands are added.
  ;Need to work on shortening this one.
  var %sounds !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  var %sound10 $gettok(%sounds,1,32)
  var %sound11 $gettok(%sounds,1-2,32)
  var %sound12 $gettok(%sounds,1-3,32)
  var %sound13 $gettok(%sounds,1-4,32)
  var %sound14 $gettok(%sounds,1-5,32)
  var %sound15 $gettok(%sounds,1-6,32)
  var %sound16 $gettok(%sounds,1-7,32)
  var %sound17 $gettok(%sounds,1-8,32)
  var %sound18 $gettok(%sounds,1-9,32)
  var %sound19 $gettok(%sounds,1-10,32)
  var %sound20 $gettok(%sounds,1-11,32)
  var %sound21 $gettok(%sounds,1-12,32)
  var %sound22 $gettok(%sounds,1-13,32)
  var %sound999 $gettok(%sounds,1-13,32)
  ;Go all the way to rank 50 for the maximum just incase.  (correspond this with the ranks that you actually gain the audio commands.)
  if ($ulevel <= 9 ) {
    msg $chan you are $ulevel and have no sound commands.
  }
  else {
    ;msg $chan $nick $+ $chr(58) $gettok(%sounds,1-13,44)
    var %level $ulevel,%result
    while ($eval($+(%,sound,%level),2) != $null) {
      ; no need to escape : with $chr(58) here
      %result = %result $v1
      inc %level
    }
    msg $chan $nick $+ : %result
  }
}


This is one that I am really unsure of.. another optimizer question. This is the point evaluation system that identifies users view points and then calculates that to give a user a rank/color/etc.

Code:
on *:TEXT:!potato:#:{
  if ((%floodpotato) || ($($+(%,floodpotato.,$nick),2))) { return }
  set -u10 %floodpotato On
  set -u15 %floodpotato. $+ $nick On 
  var %ID = $findID(%rosterFile, %rosterID, $nick)
  if (%ID == 0) {
    msg $chan /me $nick is not in the Points System.
  }
  else {
    var %points = $readini(%rosterFile, $findID(%rosterFile, %rosterID, $nick), points)
    var %views = $round($calc($readini(%rosterFile, $findID(%rosterFile, %rosterID, $nick), views) / 60), 2)
    if (%views <= 2.99) {
      msg $chan $nick you are a †Niblet† with %views hours. Earn $calc(3 - %views) More hours to become a Spud.
      set %level. $+ $nick Niblet
    }
    elseif (%views > 2.99) && (%views <= 4.99) {
      msg $chan $nick you are a †Spud† with %views hours. Earn $calc(5 - %views) More hours to become a Newblet.
      var %level = %level. [ $+ [ $nick ] ]
      if (%level != Spud) {
        set %level. $+ $nick Spud
        splay %soundlevels $+ SpudLevel.mp3
      }
      if ($nick != dreadfullydespized) {
        guser -a 10 $nick
      }
    }
    elseif (%views > 4.99) && (%views <= 7.99) {
      msg $chan $nick you are a †Newblet† with %views hours. Earn $calc(8 - %views) More hours to become a †Newbie†.
      if ($nick != dreadfullydespized) {
        guser -a 10 $nick
      }
    }
    elseif (%views > 7.99) && (%views <= 10.99) {
      msg $chan $nick you are a †Newbie† with %views hours. Earn $calc(11 - %views) More hours to become a †Newb†.
      if ($nick != dreadfullydespized) {
        guser -a 10 $nick
      }
    }
    elseif (%views > 10.99) && (%views <= 15.99) {
      msg $chan $nick you are a †Newb† with %views hours. Earn $calc(16 - %views) More hours to become a †Mini Potato†.
      if ($nick != dreadfullydespized) {
        ;cnick -m0 $nick 2
        guser -a 11 $nick
      }
    }
    elseif (%views > 15.99) && (%views <= 19.99) {
      msg $chan $nick you are a †Mini Potato† with %views hours. Earn $calc(20 - %views) More hours to become a †Squishy Potato†.
      var %level = %level. [ $+ [ $nick ] ]
      if (%level != MiniPotato) {
        set %level. $+ $nick MiniPotato
        splay %soundlevels $+ MiniPotatoLevel.mp3
      }
      if ($nick != dreadfullydespized) {
        ;cnick -m0 $nick 2
        guser -a 11 $nick
      }
    }
    elseif (%views > 19.99) && (%views <= 24.99) {
      msg $chan $nick you are a †Squishy Potato† with %views hours. Earn $calc(25 - %views) More hours to become a †Tastey Potato†.
      var %level = %level. [ $+ [ $nick ] ]
      if (%level != SquishyPotato) {
        set %level. $+ $nick SquishyPotato
        splay %soundlevels $+ SquishyPotatoLevel.mp3
      }
      if ($nick != dreadfullydespized) {
        ;cnick -m0 $nick 5
        guser -a 12 $nick
      }
    }
    else {
      msg $chan $nick you are a †Grand Puuba Elite Potato of the Dek† with %views hours.
      var %level = %level. [ $+ [ $nick ] ]
      if (%level != GrandPuubaElitePotatooftheDek) {
        set %level. $+ $nick GrandPuubaElitePotatooftheDek
        splay %soundlevels $+ GrandPuubaElitePotatooftheDekLevel.mp3
      }
      if ($nick != dreadfullydespized) {
        ;cnick -m0 $nick
        guser -a 50 $nick
      }
    }
  }
}

Last edited by Despized; 13/08/15 11:54 PM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Quote:
Very nice work! Though I am trying to get it so it adds all the commands together per level. Instead of just having it show only the sound command of the level you are at. Show all that are available to the user for their current level.
That's not how it works, however the way I did it is wrong, it should be the other way around!
With what I made, level 11 would access to all triggers from level 11 onward but it should be backward, from level 11 to 10.

But anyway, yeah, you do have only one more trigger per level, so yeah $gettok is fine, you don't even need to set %soundN, just use %sound:

Code:
 var %sounds !chicken !elementalcohesion !nonono !igottheboons !bane !moo !pewpew !elephant !monkey !toot !doom !babyfart !matingcall
  if ($ulevel <= 9 ) {
    msg $chan you are $ulevel and have no sound commands.
  }
  else {
    msg $chan $nick $+ $chr(58) $gettok(%sounds,1- $calc($ulevel - 9),44)
  }
}


For the other script, you could do:
Code:
on *:TEXT:!potato:#:{
  if ((%floodpotato) || ($($+(%,floodpotato.,$nick),2))) { return }
  set -u10 %floodpotato On
  set -u15 %floodpotato. $+ $nick On 
  var %ID = $findID(%rosterFile, %rosterID, $nick)
  if (%ID == 0) {
    msg $chan /me $nick is not in the Points System.
  }
  else {
    var %points = $readini(%rosterFile, $findID(%rosterFile, %rosterID, $nick), points)
    var %level = %level. [ $+ [ $nick ] ]
    var %views = $round($calc($readini(%rosterFile, $findID(%rosterFile, %rosterID, $nick), views) / 60), 2)
    var %range 3-4.99 5-7.99 8-10.99 11-15.99 16-19.99 20-24.99
    var %title †Spud†@†Newblet†@†Newbie†@†Newb†@†Mini Potato†@†Squishy Potato†@
    var %hour 5 8 11 16 20 25
    var %guser 10 10 10 11 11 12
    if (%views <= 2.99) {
      msg $chan $nick you are a †Niblet† with %views hours. Earn $calc(3 - %views) More hours to become a Spud.
      set %level. $+ $nick Niblet  
    }
    elseif (%views >= 25) {
      msg $chan $nick you are a †Grand Puuba Elite Potato of the Dek† with %views hours.
      if (%level != GrandPuubaElitePotatooftheDek) {
        set %level. $+ $nick GrandPuubaElitePotatooftheDek
        splay %soundlevels $+ GrandPuubaElitePotatooftheDekLevel.mp3
      }
      if ($nick != dreadfullydespized) {
        ;cnick -m0 $nick
        guser -a 50 $nick
      }
    }
    else {
      var %a 1
      while ($gettok(%range,%a,32) != $null) {
        if (%views isnum $v1) {
          msg $chan $nick you are a $gettok(%title,%a,64) with %views hours. Earn $calc($gettok(%hour,%a,32) - %views) More hours to become a $gettok(%title,$calc(%a + 1),64) $+ .
          if ($istok(1 5 6,%a,32)) {
            if (%level != $remove($gettok(%title,%a,64),†)) {
              set %level. $+ $nick $v2
              splay %soundlevels $+ $v2 $+ Level.mp3
            }
          }
          ;when you have only one command associated to an statement, you can ommit the { }
          if ($nick != dreadfullydespized) guser -a $gettok(%guser,%a,32) $nick
          break
        }
        inc %a
      }
    }
  }
}
I won't explain how it works so you can figure it out yourself, the idea is always the same anyway, but ask if you don't understand something.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
I must say you are amazing with this scripting language. Big thanks!!!

I got some interesting/stumped situations with two portions.

Code:
          }
          ;when you have only one command associated to an statement, you can ommit the { }
          if ($nick != dreadfullydespized) guser -a $gettok(%guser,%a,32) $nick
          ;break
        }
        inc %a
      }


I had to comment out the break in the line. It was calling my !break remote action. Which was weird.

Code of the remote !break command
Code:
on @10:TEXT:!break:#:{
  if ((%floodbreak) || ($($+(%,floodbreak.,$nick),2))) { return }
  set -u120 %floodbreak On
  set -u300 %floodbreak. $+ $nick On
  msg $chan Dread Says, Please take some time to take care of yourself! Go get something to eat or drink! Go to the bathroom. Possibly even stand up and stretch! Thank you. This has been a public service announcement from the DreadCast system.
}


Second interesting portion that I am not fully understanding. My guess is that the 1 5 6 was in relation to the scope of how many iterations of the script I showed here. The actual script goes up to 22,000 hours. Vs I pasted a shortened version thinking that would be helpful lol.

The line for if istoken. From my gathering. has 1 5 6. Then the %a is the iteration number of how many times it goes through the while statement. Then 32 being space for the character delimiter. Though I am unsure if I need to put the full range of all ranks/levels in the istok statement. Or if I can sum it up in some fashion like I see below.

The second thing that makes me curious. Is the next if statement line. Which from what I gather. Removes the † from the rank name information. To be better parsed for the file of the mp3. Though. The only issue I found with that is I would also need to remove character32/space. Since the mp3 files don't have one.

Final thing on this one is line 3. The $v2 is the second operator of the if statement from my understanding. Though that would also need to have the space removed. I am mainly replying to this to help me understand what actions are being taken in this portion of the script.
Code:
          if ($istok(1 5 6,%a,32)) {
            if (%level != $remove($gettok(%title,%a,64),†)) {
              set %level. $+ $nick $v2
              splay %soundlevels $+ $v2 $+ Level.mp3
            }
          }


I made the following edit, it provides what I wanted in terms of no † and no space. Though now it seems to not create the %level.$nick $v2 or play the sound file.
Code:
            if (%level != $remove($gettok(%title,%a,64),$chr(32),†)) {


I really really really! Appreciate your help on this. I wouldn't even know where to look for these optimization techniques.

Last edited by Despized; 14/08/15 10:57 PM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Quote:
I had to comment out the break in the line. It was calling my !break remote action. Which was weird.
That can't possibly happen, a command cannot trigger an event whose trigger is that command, I suppose you had a bracket mismatch, which may result in what is below your code to be executed as command:

Code:
alias test {
/echo -a some stuff
/if (1 == 1 {
/more stuff..
/if (2 == 2) {

}

}

/this is actually executed


/on *:text:!break:#:{
/stuff
/if (1 == 1 {
/more stuff..
/if (2 == 2) {

}
}
}
}
In this case, the { } bracket are incorrect, the alias is missing its closing }, which is actually at the end of the event, causing everything to be executed as a command.

You can use control + h in the editor to check for bracket mismatch, although if you have the correct number of { and } but misplaced, it would still be wrong and not detected.
/break allows to break the loop, we're using all these variables as array, %a is the Nth element in the array, %range is an array of range, from the smallest to biggest and we check each time if we are in the current range, if so, we don't need to check any more range so we must exit the loop. Note that by the nature and the logic of the code, it couldn't possibly match two ranges, so not using break would be the exact same thing, but using break make the script faster, especially if we consider you have thousand of range to check for and the first one already matched.

The 1 5 6 stuff is related to the previous code, for these range (for the range of the 1st 5th and 6th element in the array) you were playing a sound file. Not all range were playing a sound file, which is why we must do that $istok check (it's equal to 'if (%a == 1) || (%a == 5) || (%a == 6) {')

Code:
The only issue I found with that is I would also need to remove character32/space. Since the mp3 files don't have one.
Yes, good catch, I missed this!

Also, you should use mslDev, an IDE for the language, which helps with any kind of error: there is a website, msldev.com, but long story short is that it's currently not updated anymore and this is the last stable release made, which is not available on the website: http://rly.cc/8YM59

You're welcome, check my signature and feel free to come by the channel if you have a lot of quick questions like that smile


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
The break issue is on me. I created a alias /break. That is what was causing that issue laugh Thanks!

Updated and here is the finished working code. laugh

Code:
on *:TEXT:!potato:#:{
  ;if ((%floodpotato) || ($($+(%,floodpotato.,$nick),2))) { return }
  ;set -u10 %floodpotato On
  ;set -u15 %floodpotato. $+ $nick On 
  var %ID = $findID(%rosterFile, %rosterID, $nick)
  if (%ID == 0) {
    msg $chan /me $nick is not in the Points System.
  }
  else {
    var %points = $readini(%rosterFile, $findID(%rosterFile, %rosterID, $nick), points)
    var %level = %level. [ $+ [ $nick ] ]
    var %views = $round($calc($readini(%rosterFile, $findID(%rosterFile, %rosterID, $nick), views) / 60), 2)
    var %range 3-4.99 5-7.99 8-10.99 11-15.99 16-19.99 20-24.99 25-31.99 32-40.99 41-49.99 50-59.99 60-77.99 78-87.99 88-92.99 93-124.99 125-157.99 158-182.99 183-216.99 217-266.99 267-382.99 383-466.99 467-582.99 583-699.99 700-832.99 833-1166.99 1167-1499.99 1500-1665.99 1666-1916.99 1917-2332.99 2333-2749.99 2750-3249.99 3250-4166.99 4167-5832.99 5833-7432.99 7433-8162.99 8163-8892.99 8893-10492.99 10493-11222.99 11223-11999.99 11200-12729.99 12730-13529.99 13530-14259.99 14260-14999.99 15000-15729.99 15730-16579.99 16580-17309.99 17310-18054.99 18055-18789.99 18790-19527.99 19528-19999.99 20000-21099.99 21100-21849.99
    var %title †Spud†@†Newblet†@†Newbie†@†Newb†@†Mini Potato†@†Squishy Potato†@†Tastey Potato†@†Salty Potato†@†Soft Potato†@†Potato†@†Sticky Potato†@†Gnarly Potato†@†Luscious Potato†@†Dedicated Potato†@†Saucey Potato†@†Elite Potato†@†Uber Potato†@†Honored Potato†@†Revered Potato†@†Dignified Potato†@†Molested Potato†@†Tainted Potato†@†Eternal Potato†@†Mashed Potato†@†Boiled Potato†@†Hasselback Potato†@†Soupy Potato†@†Beefy Potato†@†Golden Potato†@†Hairy Potato†@†Stuffed Potato†@†Cheesy Potato†@†Diaper Wrapper Potato†@†Goliath Potato†@†Zombie Potato†@†Infected Potato†@†Peeled Potato†@†Cream Filled Potato†@†Sparkling Potato†@†Tickled Potato†@†Steel Belted Potato†@†Dishonored Potato†@†Tactical Potato†@†Ancient Potato†@†PotatoKnight†@†Baron of the Potato†@†Duke of the Potato†@†Royal Potato Guard†@†Potato General†@†Potato of the Sauce†@†Dek Filled Potato†
    var %hour 5 8 11 16 20 25 32 41 50 60 78 88 93 125 158 183 217 267 383 467 583 700 883 1167 1500 1666 1917 2333 2750 3250 4167 5833 7433 8163 8893 10493 11223 12000 12730 13530 14260 15000 15730 16580 17310 18055 18790 19528 20000 21100 21850
    var %guser 10 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 18 19 19 20 20 21 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    if (%views <= 2.99) {
      msg $chan $nick you are a †Niblet† with %views hours. Earn $calc(3 - %views) More hours to become a †Spud†.
      set %level. $+ $nick Niblet  
    }
    elseif (%views >= 21850) {
      msg $chan $nick you are a †Grand Puuba Elite Potato of the Dek† with %views hours.
      if (%level != GrandPuubaElitePotatooftheDek) {
        set %level. $+ $nick GrandPuubaElitePotatooftheDek
        splay %soundlevels $+ GrandPuubaElitePotatooftheDekLevel.mp3
      }
      if ($nick != dreadfullydespized) {
        ;cnick -m0 $nick
        guser -a 50 $nick
      }
    }
    else {
      var %a 1
      while ($gettok(%range,%a,32) != $null) {
        if (%views isnum $v1) {
          msg $chan $nick you are a $gettok(%title,%a,64) with %views hours. Earn $calc($gettok(%hour,%a,32) - %views) More hours to become a $gettok(%title,$calc(%a + 1),64) $+ .
          ;This line below is used to iterate the ranks with sound files attached to with
          if ($istok(1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46,%a,32)) {
            if (%level != $remove($gettok(%title,%a,64),$chr(32), †)) {
              set %level. $+ $nick $v2
              ;set %level. $+ $nick $remove($gettok(%title,%a,64),$chr(32), †)
              splay %soundlevels $+ $v2 $+ Level.mp3
              ;splay %soundlevels $+ $remove($gettok(%title,%a,64),$chr(32), †) $+ Level.mp3
            }
          }
          ;when you have only one command associated to an statement, you can ommit the { }
          if ($nick != dreadfullydespized) guser -a $gettok(%guser,%a,32) $nick
          break
        }
        inc %a
      }
    }
  }
}

Last edited by Despized; 16/08/15 12:36 AM.
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
New Optimization question.

Working on a portion that pulls information from two text files and then compares the first line in both of them to see if they are different or not. Unfortunately.. It includes spaces and that comes out really odd.

Here is the block of code to work with the files. I copied the information directly from the text files as it is, the results once the script finishes. Which doesn't make any sense to me. Since it skips a space to the output/update file. Variables %one and %two actually echo exactly the same. resulting in the same as File2.txt at the bottom. The If message portion is used to not throw a fit if a user doesn't have a donation message in their donation.

Code:
alias donations {
  var %one $read(%donateFile,n,1)
  echo -a %one
  var %two $read(%checkFile,n,1)
  echo -a %two
  var %name $gettok(%two,1,38)
  echo -a %name
  var %message $gettok(%two,2,38)
  if (%message == $chr(32)) || (%message == $null) || (%message == $chr(38)) {
    var %message default
  }
  echo -a %message
  var %donate $gettok(%two,3,38)
  echo -a %donate
  ;This line removes the $ from the dollar amount donated.  To work with the system easier.
  var %donateamount $mid(%donate,3)
  echo -a %donateamount
  ;This is the problem line.
  if (%one isin %two) { return } 
  ;Calls the donation alias to then convert donate amount to whole number and times it by 6 for points to be added to user who donated.
  ;donation %name %donateamount
  ;Currently sitting at 15 total
  var %soundcodes [BABY] [BANE] [CHCK] [DOOM] [ELCO] [ELTO] [IGBO] [MATI] [MONK] [MOOO] [MORS] [NONO] [PEWP] [TOOT] [BOON] [DINO] [SQUI] [DUKE] [BAYM] [DWDU] [MILI]
  var %soundrand 1 3 1 1 1 1 1 4 1 1 1 1 1 1 2 1 1 16 1 1 1
  ;Sets an incremental variable
  var %a 1
  while ($gettok(%soundcodes,%a,32) != $null) {
    var %v $v1
    ;echo -a v: %v
    if ($istok(%message,%v,32)) {
      var %tof $v1
    }
    if (%v isin %message) {
      var %vs $v1
      var %vss $mid(%vs,2,4)
      ;echo -a vss: %vss
      ;echo -a a: %a
      var %vsss %vss $+ $rand(1,$gettok(%soundrand,%a,32))
      ;echo -a vssstotal: %donateSounds $+ %vsss $+ .mp3
      splay %donateSounds $+ %vsss $+ .mp3
      ;echo -a vsss: %vsss
    }
    inc %a
  }
  if (%tof == $null) {
    splay %sounds $+ Alerts-Donation-Online.mp3
  }
  echo -a New Donation: %two
  write -c %checkFile %one
}


File1.txt
Code:
Targ &  & $2.50


File2.txt
Code:
Targ & & $2.50


Thank you for your time and input!

Last edited by Despized; 01/10/15 04:17 AM. Reason: Corrected Typos
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Yeah, consecutives spaces are lost with command, you can get around this by writting a binary variable to the file with /bwrite.
Keep using write -c at the end, but just to clear the file, then use this:
Code:
bset &a 1 $regsubex(%one,/(.)/g,$asc(\1) $+ $chr(32))
bwrite file.txt 0 -1 &a


For the if condition, if you want to check if both lines are different or not, you should use the '==' operator ('===' for case sensitive check), not 'isin'


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2015
Posts: 13
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Aug 2015
Posts: 13
Works awesome thank you! Also fixed some other bugs. Wims you are a magician with this!!!

Code:
alias donations {
  var %one $read(%donateFile,n,1)
  ;echo -a DonateFile: %one
  var %two $read(%checkFile,n,1)
  ;echo -a CheckFile: %two
  var %name $gettok(%one,1,38)
  ;echo -a Username: %name
  var %message $gettok(%one,2,38)
  if (%message == $chr(32)) || (%message == $null) || (%message == $chr(38)) {
    var %message default
  }
  ;echo -a Message: %message
  var %donate $gettok(%one,3,38)
  ;echo -a Donate: %donate
  ;This line removes the $ from the dollar amount donated.  To work with the system easier.
  var %donateamount $mid(%donate,3)
  ;echo -a DonateAmount: %donateamount
  if (%one === %two) { return } 
  ;Calls the donation alias to then convert donate amount to whole number and times it by 6 for points to be added to user who donated.
  ;donation %name %donateamount
  ;Currently sitting at 15 total
  var %soundcodes [BABY] [BANE] [CHCK] [DOOM] [ELCO] [ELTO] [IGBO] [MATI] [MONK] [MOOO] [MORS] [NONO] [PEWP] [TOOT] [BOON] [DINO] [SQUI] [DUKE] [BAYM] [DWDU] [MILI]
  var %soundrand 1 3 1 1 1 1 1 4 1 1 1 1 1 1 2 1 1 16 1 1 1
  ;Sets an incremental variable
  var %a 1
  while ($gettok(%soundcodes,%a,32) != $null) {
    var %v $v1
    ;echo -a v: %v
    if ($istok(%message,%v,32)) {
      var %tof $v1
    }
    if (%v isin %message) {
      var %vs $v1
      var %vss $mid(%vs,2,4)
      ;echo -a vss: %vss
      ;echo -a a: %a
      var %vsss %vss $+ $rand(1,$gettok(%soundrand,%a,32))
      splay %donateSounds $+ %vsss $+ .mp3
    }
    inc %a
  }
  if (%tof == $null) {
    splay %sounds $+ Alerts-Donation-Online.mp3
  }
  ;clears out the %checkFile to prevent extra 0's at the end of the line.
  write -c %checkFile
  bset &a 1 $regsubex(%one,/(.)/g,$asc(\1) $+ $chr(32))
  bwrite %checkFile 0 -1 &a
  echo -a New Donation: $read(%checkFile,n,1)
}


Resolved/working script for anyone who may see this post. Thank you again Wims!

Last edited by Despized; 03/10/15 08:31 PM.

Link Copied to Clipboard