mIRC Home    About    Download    Register    News    Help

Print Thread
#262356 24/01/18 08:54 AM
Joined: Dec 2017
Posts: 9
C
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Dec 2017
Posts: 9
so im a little confused, what i would to accomplish is being able to use the same script in channel and query(pm) with bot. this is the code i have:
on *:TEXT:!item *:#,?:{
if ($target = $me) {
if ($read(C:\Users\...\AppData\Roaming\mIRC\txtfiles\items.txt,ns,$2-) != $null) {
var %pokemon $read(C:\Users\...\AppData\Roaming\mIRC\txtfiles\items.txt,ns,$2-)
notice $nick Name: $+ $chr(32) $gettok(%pokemon,1,59) $chr(32) $chr(124) $chr(32) $+ Description: $+ $chr(32) $gettok(%pokemon,2,59) $chr(32) $chr(124) $chr(32) $+ Sell-able from Player Shop: $+ $chr(32) $gettok(%pokemon,3,59) $chr(32) $chr(124) $chr(32) $+ Buyable: $+ $chr(32) $gettok(%pokemon,4,59) $chr(32) $chr(124) $chr(32) $+ Other: $+ $chr(32) $gettok(%pokemon,5,59) $chr(32)
}
}
else {
if ($read(C:\Users\camck\AppData\Roaming\mIRC\txtfiles\items.txt,ns,$2-) != $null) {
var %pokemon $read(C:\Users\camck\AppData\Roaming\mIRC\txtfiles\items.txt,ns,$2-)
notice $nick Name: $+ $chr(32) $gettok(%pokemon,1,59) $chr(32) $chr(124) $chr(32) $+ Description: $+ $chr(32) $gettok(%pokemon,2,59) $chr(32) $chr(124) $chr(32) $+ Sell-able from Player Shop: $+ $chr(32) $gettok(%pokemon,3,59) $chr(32) $chr(124) $chr(32) $+ Buyable: $+ $chr(32) $gettok(%pokemon,4,59) $chr(32) $chr(124) $chr(32) $+ Other: $+ $chr(32) $gettok(%pokemon,5,59) $chr(32)
}
else {
notice $nick I couldn't find a Item with that name. Check your spelling, and try again smile
}
}
}

it does what i want but, if im in channel it automatically sends pm to bot and displays again the script message again. so message is displayed in both channel and pm with bot not just one or the other like i would to happen. where did i mess up?

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
"sends pm to bot" means you're sending a query to them. This ON TEXT event does not send a message to channel nor does it send a query, it sends only a notice, so you may have another ON TEXT in another script or above this in this same script doing something, or you edited your script to take out the part that's doing the /query or /msg.

This event could be cleaned up a little better. Instead of using the literal path to a subfolder beneath the folder where mirc.ini is located, you can use $MIRCDIRsubfolder\filename.txt. The $mircdir part is assumed when path doesn't begin with backslash or like c:\ so you can refer to this as $read(txtfiles\item.txt,ns,$2-)

Also, the way you're doing this is reading disk twice to fetch the same thing. First you read disk to see if the item is null, then you read the same thing from disk to put it into %pokemon. You should read it from disk into the variable, then check if %pokemon != $null. Also, by having shorter code, it avoids the chance that a change doesn't get edited the same way everywhere. i.e. your script contains the identical $read command in 4 different places. Also, the /notice command strips duplicated spaces, so "text text" already has a space, so there's no need to have "text $+ $chr(32) text".

Also, your post will be easier to read, if you select the code section with your mouse, then choose the "#" icon and pick "code" from within, which formats in a different font without stripping the indents.

If you want it to reply to channel when someone types in channel, and reply in query when someone types in a query window, you can "query $nick message" if $target == $me, and "msg # reply to $nick message" otherwise. I also see from your code that you don't reply the "can't find" message when target=me, so I'm continuing that.

Instead of using :#,?: as your last ON TEXT parameter, you could have used :*: but this lets you specify an individual channel while also handling query windows.

Code:
on *:TEXT:!item *:#,?:{
  var %item $read($MIRCDIRtxtfiles\items.txt,ns,$2-)
  var %message
  if (%item != $null) var %message Name: $gettok(%pokemon,1,59) $(|) Description: $gettok(%pokemon,2,59) $(|) Sell-able from Player Shop: $gettok(%pokemon,3,59) $(|) Buyable: $gettok(%pokemon,4,59) $(|) Other: $gettok(%pokemon,5,59)

  if ($target == $me) {
    if (%item != $null) { query $nick %message }
  }
  else {
    if (%item != $null) { msg # %message }
    else msg # I couldn't find a Item with that name. Check your spelling, and try again smile
  }
}

Joined: Dec 2017
Posts: 9
C
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Dec 2017
Posts: 9
thank you so much maroon, now to slow edit all the scripts works great. and thanks for the pointers


Link Copied to Clipboard